|
| 1 | +# Developing multiple functions on the same host using Minikube and Skaffold |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This example shows you how to develop multiple Cloud Functions to a single host |
| 6 | +using Minikube and Skaffold. |
| 7 | + |
| 8 | +The example will focus on: |
| 9 | +* taking two separate Cloud Functions (defined in the same file) |
| 10 | +* building them each individually with Cloud Buildpacks and the Functions Framework |
| 11 | +* deploying them to a local Kubernetes cluster with `minikube` and `skaffold` |
| 12 | +* including live reloading! |
| 13 | + |
| 14 | +## Install `minikube` |
| 15 | +*Note: If on Cloud Shell, `minikube` is pre-installed.* |
| 16 | + |
| 17 | +Install `minikube` via the instructions for your platform at <https://minikube.sigs.k8s.io/docs/start/> |
| 18 | + |
| 19 | +Confirm that `minikube` is installed: |
| 20 | + |
| 21 | +```bash |
| 22 | +minikube version |
| 23 | +``` |
| 24 | + |
| 25 | +You should see output similar to: |
| 26 | + |
| 27 | +```terminal |
| 28 | +minikube version: v1.15.1 |
| 29 | +commit: 23f40a012abb52eff365ff99a709501a61ac5876 |
| 30 | +``` |
| 31 | + |
| 32 | +## Start `minikube` |
| 33 | + |
| 34 | +This starts `minikube` using the default profile: |
| 35 | + |
| 36 | +```bash |
| 37 | +minikube start |
| 38 | +``` |
| 39 | + |
| 40 | +This may take a few minutes. |
| 41 | + |
| 42 | +*Note: If on Cloud Shell, you may be asked to enable Cloud Shell to make API calls* |
| 43 | + |
| 44 | +You should see output similar to: |
| 45 | + |
| 46 | +```terminal |
| 47 | +😄 minikube v1.15.1 on Debian 10.6 |
| 48 | + ▪ MINIKUBE_FORCE_SYSTEMD=true |
| 49 | + ▪ MINIKUBE_HOME=/google/minikube |
| 50 | + ▪ MINIKUBE_WANTUPDATENOTIFICATION=false |
| 51 | +✨ Automatically selected the docker driver |
| 52 | +👍 Starting control plane node minikube in cluster minikube |
| 53 | +🚜 Pulling base image ... |
| 54 | +💾 Downloading Kubernetes v1.19.4 preload ... |
| 55 | +🔥 Creating docker container (CPUs=2, Memory=4000MB) ... |
| 56 | +🐳 Preparing Kubernetes v1.19.4 on Docker 19.03.13 ... |
| 57 | +🔎 Verifying Kubernetes components... |
| 58 | +🌟 Enabled addons: storage-provisioner, default-storageclass |
| 59 | +🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default |
| 60 | +``` |
| 61 | + |
| 62 | +## Install the `ingress` addon for `minikube` |
| 63 | + |
| 64 | +This allows `minikube` to handle external traffic: |
| 65 | + |
| 66 | +```bash |
| 67 | +minikube addons enable ingress |
| 68 | +``` |
| 69 | + |
| 70 | +You should see output similar to: |
| 71 | + |
| 72 | +```terminal |
| 73 | +🔎 Verifying ingress addon... |
| 74 | +🌟 The 'ingress' addon is enabled |
| 75 | +``` |
| 76 | + |
| 77 | +## Install `skaffold` |
| 78 | +*Note: If on Cloud Shell, `skaffold` is pre-installed.* |
| 79 | + |
| 80 | +Install `skaffold` via the instructions for your platform at <https://skaffold.dev/docs/install/> |
| 81 | + |
| 82 | +Confirm that `skaffold` is installed: |
| 83 | + |
| 84 | +```bash |
| 85 | +skaffold version |
| 86 | +``` |
| 87 | + |
| 88 | +You should see output similar to: |
| 89 | + |
| 90 | +```terminal |
| 91 | +v1.16.0 |
| 92 | +``` |
| 93 | + |
| 94 | +## Start `skaffold` |
| 95 | + |
| 96 | +Start `skaffold` with: |
| 97 | + |
| 98 | +```bash |
| 99 | +skaffold dev |
| 100 | +``` |
| 101 | + |
| 102 | +You should see output similar to: |
| 103 | + |
| 104 | +```terminal |
| 105 | +Starting deploy... |
| 106 | +Waiting for deployments to stabilize... |
| 107 | + - deployment/hello is ready. [1/2 deployment(s) still pending] |
| 108 | + - deployment/goodbye is ready. |
| 109 | +Deployments stabilized in 1.154162006s |
| 110 | +Watching for changes... |
| 111 | +``` |
| 112 | + |
| 113 | +This command will continue running indefinitely, watching for changes and redeploying as necessary. |
| 114 | + |
| 115 | +## Call your Cloud Functions |
| 116 | + |
| 117 | +Leaving the previous command running, in a **new terminal**, call your functions. To call the `hello` function: |
| 118 | + |
| 119 | +```bash |
| 120 | +curl `minikube ip`/hello |
| 121 | +``` |
| 122 | + |
| 123 | +You should see output similar to: |
| 124 | + |
| 125 | +```terminal |
| 126 | +Hello, World! |
| 127 | +``` |
| 128 | + |
| 129 | +To call the `goodbye` function: |
| 130 | + |
| 131 | +```bash |
| 132 | +curl `minikube ip`/goodbye |
| 133 | +``` |
| 134 | + |
| 135 | +You should see output similar to: |
| 136 | + |
| 137 | +```terminal |
| 138 | +Goodbye, World! |
| 139 | +``` |
0 commit comments