
This blog is part of a multi-part blog series that shows how to run your applications on Kubernetes. It will use the Couchbase, an open source NoSQL distributed document database, as the Docker container.
The first part (Couchbase on Kubernetes) explained how to start the Kubernetes cluster using Vagrant. The second part (Kubernetes on Amazon) explained how run that setup on Amazon Web Services.
This third part will show:
- How to setup and start the Kubernetes cluster on Google Cloud
- Run Docker container in the Kubernetes cluster
- Expose Pod on Kubernetes as Service
- Shutdown the cluster
Here is a quick overview:
Let’s get into details!
Getting Started with Google Compute Engine provide detailed instructions on how to setup Kubernetes on Google Cloud.
Download and Configure Google Cloud SDK
There is a bit of setup required if you’ve never accessed Google Cloud on your machine. This was a bit overwhelming and wish can be simplified.
- Create a billable account on Google Cloud
- Install Google Cloud SDK
- Configure credentials: gcloud auth login
- Create a new Google Cloud project and name it
couchbase-on-kubernetes - Set the project:
gcloud config set project couchbase-on-kubernetes - Set default zone:
gcloud config set compute/zone us-central1-a - Create an instance:
gcloud compute instances create example-instance --machine-type n1-standard-1 --image debian-8 - SSH into the instance:
gcloud compute ssh example-instance - Delete the instance:
gcloud compute instances delete example-instance
Setup Kubernetes Cluster on Google Cloud
Kubernetes cluster can be created on Google Cloud as:
|
1 2 |
establecer KUBERNETES_PROVIDER=gce ./clúster/kube–up.sh |
Make sure KUBERNETES_PROVIDER is either set to gce or not set at all. By default, this provisions a 4 node Kubernetes cluster with one master. This means 5 Virtual Machines are created.
If you downloaded Kubernetes from github.com/kubernetes/kubernetes/releases, then all the values can be changed in cluster/aws/config-default.sh.
Starting Kubernetes on Google Cloud shows the following log. Google Cloud SDK was behaving little weird but taking the defaults seem to work:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
./Kubernetes/clúster/kube–up.sh ... Starting clúster usando proveedor: gce ... calling verify–prereqs You have specified individual components to update. If you are trying to Instalar nuevo components, use: $ gcloud components Instalar alpha Do you want to run Instalar instead (y/N)? Your current Cloud SDK version is: 99.0.0 Installing components desde version: 99.0.0 ┌──────────────────────────────────────────────┐ │ These components will be installed. │ ├───────────────────────┬────────────┬─────────┤ │ Nombre │ Version │ Size │ ├───────────────────────┼────────────┼─────────┤ │ gcloud Alpha Commands │ 2016.01.12 │ < 1 MiB │ └───────────────────────┴────────────┴─────────┘ Para el latest full release notes, please visit: https://cloud.google.com/sdk/release_notes Do you want to continue (Y/n)? ╔════════════════════════════════════════════════════════════╗ ╠═ Creating update staging area ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Installing: gcloud Alpha Commands ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Creating respaldo y activating nuevo installation ═╣ ╚════════════════════════════════════════════════════════════╝ Performing post processing steps...done. Update done! You have specified individual components to update. If you are trying to Instalar nuevo components, use: $ gcloud components Instalar beta Do you want to run Instalar instead (y/N)? Your current Cloud SDK version is: 99.0.0 Installing components desde version: 99.0.0 ┌─────────────────────────────────────────────┐ │ These components will be installed. │ ├──────────────────────┬────────────┬─────────┤ │ Nombre │ Version │ Size │ ├──────────────────────┼────────────┼─────────┤ │ gcloud Beta Commands │ 2016.01.12 │ < 1 MiB │ └──────────────────────┴────────────┴─────────┘ Para el latest full release notes, please visit: https://cloud.google.com/sdk/release_notes Do you want to continue (Y/n)? ╔════════════════════════════════════════════════════════════╗ ╠═ Creating update staging area ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Installing: gcloud Beta Commands ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Creating respaldo y activating nuevo installation ═╣ ╚════════════════════════════════════════════════════════════╝ Performing post processing steps...done. Update done! All components are up to date. ... calling kube–up Your active configuration is: [default] Project: Couchbase–en–Kubernetes Zone: us–central1–b Creating gs://kubernetes-staging-9479406781 Creating gs://kubernetes-staging-9479406781/… +++ Staging server tars to Google Storage: gs://kubernetes-staging-9479406781/devel +++ Kubernetes–server–linux–amd64.tar.gz uploaded (sha1 = 1ff42f7c31837851d919a66fc07f34b9dbdacf28) +++ Kubernetes–salt.tar.gz uploaded (sha1 = f307380ad6af7dabcf881b132146fa775c18dca8) Looking para already existing resources Starting maestro y configuring firewalls Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/disks/kubernetes-master-pd]. NAME ZONE SIZE_GB TYPE STATUS Kubernetes–maestro–pd us–central1–b 20 pd–ssd READY Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/regions/us-central1/addresses/kubernetes-master-ip]. Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/default-default-ssh]. Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-master-https]. NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS default–default–ssh default 0.0.0.0/0 tcp:22 NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS Kubernetes–maestro–https default 0.0.0.0/0 tcp:443 Kubernetes–maestro +++ Registro usando Fluentd to GCP ./Kubernetes/clúster/../clúster/../clúster/gce/útil.sh: línea 434: @: unbound variable ./Kubernetes/clúster/../clúster/../clúster/gce/útil.sh: línea 434: @: unbound variable ./Kubernetes/clúster/../clúster/../clúster/gce/útil.sh: línea 434: @: unbound variable ./Kubernetes/clúster/../clúster/../clúster/gce/útil.sh: línea 434: @: unbound variable Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/default-default-internal]. NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS default–default–internal default 10.0.0.0/8 tcp:1–65535,udp:1–65535,icmp Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-minion-all]. NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS Kubernetes–minion–todo default 10.244.0.0/16 tcp,udp,icmp,esp,ah,sctp Kubernetes–minion Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instances/kubernetes-master]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS Kubernetes–maestro us–central1–b n1–standard–1 10.128.0.2 104.197.213.249 RUNNING Creating minions. ./Kubernetes/clúster/../clúster/../clúster/gce/útil.sh: línea 434: @: unbound variable ./Kubernetes/clúster/../clúster/../clúster/gce/útil.sh: línea 434: @: unbound variable Attempt 1 to crear Kubernetes–minion–template WARNING: You have selected a disk size of under [200GB]. Este may resultado en poor I/O performance. Para more information, see: https://developers.google.com/compute/docs/disks/persistent-disks#pdperformance. Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/instanceTemplates/kubernetes-minion-template]. NAME MACHINE_TYPE PREEMPTIBLE CREATION_TIMESTAMP Kubernetes–minion–template n1–standard–1 2016–03–03T14:01:14.322–08:00 Creado [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instanceGroupManagers/kubernetes-minion-group]. NAME ZONE BASE_INSTANCE_NAME SIZE TARGET_SIZE INSTANCE_TEMPLATE AUTOSCALED Kubernetes–minion–group us–central1–b Kubernetes–minion 4 Kubernetes–minion–template Waiting para group to become stable, current operations: creating: 4 Waiting para group to become stable, current operations: creating: 4 Waiting para group to become stable, current operations: creating: 4 Waiting para group to become stable, current operations: creating: 4 Waiting para group to become stable, current operations: creating: 4 Waiting para group to become stable, current operations: creating: 4 Waiting para group to become stable, current operations: creating: 3 Group is stable MINION_NAMES=Kubernetes–minion–1hmm Kubernetes–minion–3x1d Kubernetes–minion–h1ov Kubernetes–minion–nshn Using maestro: Kubernetes–maestro (external IP: 104.197.213.249) Waiting para clúster initialization. Este will continually check to see si el API para Kubernetes is reachable. Este might loop forever si there was some uncaught error during start up. Kubernetes clúster created. clúster “couchbase-on-kubernetes_kubernetes” establecer. usuario “couchbase-on-kubernetes_kubernetes” establecer. context “couchbase-on-kubernetes_kubernetes” establecer. switched to context “couchbase-on-kubernetes_kubernetes”. usuario “couchbase-on-kubernetes_kubernetes-basic-auth” establecer. Wrote configuración para Couchbase–en–kubernetes_kubernetes to /Users/arungupta/.kube/configuración Kubernetes clúster is running. El maestro is running at: https://104.197.213.249 El usuario name y contraseña to use is located en /Users/arungupta/.kube/configuración. ... calling validate–clúster Waiting para 4 ready nodes. 0 ready nodes, 0 registered. Retrying. Waiting para 4 ready nodes. 0 ready nodes, 2 registered. Retrying. Waiting para 4 ready nodes. 0 ready nodes, 3 registered. Retrying. Waiting para 4 ready nodes. 0 ready nodes, 4 registered. Retrying. Waiting para 4 ready nodes. 3 ready nodes, 4 registered. Retrying. Waiting para 4 ready nodes. 3 ready nodes, 4 registered. Retrying. Found 4 node(s). NAME LABELS STATUS AGE Kubernetes–minion–1hmm Kubernetes.yo/hostname=Kubernetes–minion–1hmm Ready 1m Kubernetes–minion–3x1d Kubernetes.yo/hostname=Kubernetes–minion–3x1d Ready 52s Kubernetes–minion–h1ov Kubernetes.yo/hostname=Kubernetes–minion–h1ov Ready 1m Kubernetes–minion–nshn Kubernetes.yo/hostname=Kubernetes–minion–nshn Ready 1m Validate output: NAME STATUS MESSAGE ERROR controller–manager Healthy ok nil scheduler Healthy ok nil etcd–0 Healthy {“health”: “true”} nil etcd–1 Healthy {“health”: “true”} nil Clúster validation succeeded Done, listing clúster services: Kubernetes maestro is running at https://104.197.213.249 GLBCDefaultBackend is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/default-http-backend Heapster is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/heapster KubeDNS is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/kube-dns KubeUI is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/kube-ui Grafana is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana InfluxDB is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb |
There are a couple of unbound variables and a WARNING message, but that didn’t seem to break the script. Google Cloud Console shows: 
Five instances are created as shown – one for master node and four for worker nodes.
Run Docker Container in Kubernetes Cluster on Google Cloud
Now that the cluster is up and running, get a list of all the nodes:
|
1 2 3 4 5 6 |
./Kubernetes/clúster/kubectl.sh conseguir no NAME LABELS STATUS AGE Kubernetes–minion–1hmm Kubernetes.yo/hostname=Kubernetes–minion–1hmm Ready 47m Kubernetes–minion–3x1d Kubernetes.yo/hostname=Kubernetes–minion–3x1d Ready 46m Kubernetes–minion–h1ov Kubernetes.yo/hostname=Kubernetes–minion–h1ov Ready 47m Kubernetes–minion–nshn Kubernetes.yo/hostname=Kubernetes–minion–nshn Ready 47m |
It shows four worker nodes. Create a Couchbase pod:
|
1 2 |
./Kubernetes/clúster/kubectl.sh run Couchbase —image=arungupta/Couchbase replicationcontroller “couchbase” created |
Notice, how the image name can be specified on the CLI. This command creates a Replication Controller with a single pod. The pod uses arungupta/couchbase Docker image that provides a pre-configured Couchbase server. Any Docker image can be specified here.
Get all the RC resources:
|
1 2 3 |
./Kubernetes/clúster/kubectl.sh conseguir rc CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE Couchbase Couchbase arungupta/Couchbase run=Couchbase 1 48s |
This shows the Replication Controller that is created for you.
Get all the Pods:
|
1 2 3 |
./Kubernetes/clúster/kubectl.sh conseguir po NAME READY STATUS RESTARTS AGE Couchbase–s8v9r 1/1 Running 0 1m |
The output shows the Pod that is created as part of the Replication Controller.
Get more details about the Pod:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
./Kubernetes/clúster/kubectl.sh describe po Couchbase–s8v9r Nombre: Couchbase–s8v9r Namespace: default Image(s): arungupta/Couchbase Node: Kubernetes–minion–3x1d/10.128.0.3 Start Time: Thu, 03 Mar 2016 14:53:36 –0800 Labels: run=Couchbase Status: Running Reason: Mensaje: IP: 10.244.3.3 Replication Controllers: Couchbase (1/1 replicas created) Containers: Couchbase: Container ID: Docker://601ee2e4c822814c3969a241e37c97bf4d0d209f952f24707ab308192d289098 Image: arungupta/Couchbase Image ID: Docker://298618e67e495c2535abd17b60241565e456a4c9ee96c923ecf844a9dbcccced QoS Tier: cpu: Burstable Requests: cpu: 100m State: Running Started: Thu, 03 Mar 2016 14:54:46 –0800 Ready: True Restart Count: 0 Environment Variables: Conditions: Type Status Ready True Volumes: default–token–frsd7: Type: Secret (a secret that should populate este volume) SecretName: default–token–frsd7 Events: FirstSeen LastSeen Count From SubobjectPath Reason Mensaje ───────── ──────── ───── ──── ───────────── ────── ─────── 1m 1m 1 {kubelet Kubernetes–minion–3x1d} implicitly required contenedor POD Pulled Container image “gcr.io/google_containers/pause:0.8.0” already present en machine 1m 1m 1 {scheduler } Scheduled Successfully assigned Couchbase–s8v9r to Kubernetes–minion–3x1d 1m 1m 1 {kubelet Kubernetes–minion–3x1d} implicitly required contenedor POD Creado Creado con Docker identificación c1de9da87f1e 1m 1m 1 {kubelet Kubernetes–minion–3x1d} spec.contenedores{Couchbase} Pulling Pulling image “arungupta/couchbase” 1m 1m 1 {kubelet Kubernetes–minion–3x1d} implicitly required contenedor POD Started Started con Docker identificación c1de9da87f1e 29s 29s 1 {kubelet Kubernetes–minion–3x1d} spec.contenedores{Couchbase} Pulled Successfully pulled image “arungupta/couchbase” 29s 29s 1 {kubelet Kubernetes–minion–3x1d} spec.contenedores{Couchbase} Creado Creado con Docker identificación 601ee2e4c822 29s 29s 1 {kubelet Kubernetes–minion–3x1d} spec.contenedores{Couchbase} Started Started con Docker identificación 601ee2e4c822 |
Expose Pod on Kubernetes as Service
Now that our pod is running, how do I access the Couchbase server? You need to expose it outside the Kubernetes cluster. The kubectl expose command takes a pod, service or replication controller and expose it as a Kubernetes Service.
Let’s expose the replication controller previously created and expose it:
|
1 2 |
./Kubernetes/clúster/kubectl.sh expose rc Couchbase —target–port=8091 —port=8091 —tipo=LoadBalancer service “couchbase” exposed |
Get more details about Service:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
./Kubernetes/clúster/kubectl.sh describe svc Couchbase Nombre: Couchbase Namespace: default Labels: run=Couchbase Selector: run=Couchbase Type: LoadBalancer IP: 10.0.37.150 LoadBalancer Ingress: 104.197.118.35 Port: 8091/TCP NodePort: 30808/TCP Endpoints: 10.244.3.3:8091 Session Affinity: None Events: FirstSeen LastSeen Count From SubobjectPath Reason Mensaje ───────── ──────── ───── ──── ───────────── ────── ─────── 2m 2m 1 {service–controller } CreatingLoadBalancer Creating cargar balancer 1m 1m 1 {service–controller } CreatedLoadBalancer Creado cargar balancer |
El Loadbalancer Ingress attribute gives you the IP address of the load balancer that is now publicly accessible. Wait for 3 minutes to let the load balancer settle down. Access it using port 8091 and the login page for Couchbase Web Console shows up: 
Enter the credentials as “Administrator” and “password” to see the Web Console: 
And so you just accessed your pod outside the Kubernetes cluster.
Shutdown Kubernetes Cluster
Finally, shutdown the cluster using cluster/kube-down.sh script.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
./Kubernetes/clúster/kube–down.sh Bringing down clúster usando proveedor: gce You have specified individual components to update. If you are trying to Instalar nuevo components, use: $ gcloud components Instalar alpha Do you want to run Instalar instead (y/N)? All components are up to date. You have specified individual components to update. If you are trying to Instalar nuevo components, use: $ gcloud components Instalar beta Do you want to run Instalar instead (y/N)? All components are up to date. All components are up to date. Your active configuration is: [default] Project: Couchbase–en–Kubernetes Zone: us–central1–b Bringing down clúster Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instanceGroupManagers/kubernetes-minion-group]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/instanceTemplates/kubernetes-minion-template]. Updated [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instances/kubernetes-master]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instances/kubernetes-master]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-master-https]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-minion-all]. Deleting routes Kubernetes–ad3beb92–e18b–11e5–8e71–42010a800002 Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/routes/kubernetes-ad3beb92-e18b-11e5-8e71-42010a800002]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/regions/us-central1/addresses/kubernetes-master-ip]. property “clusters.couchbase-on-kubernetes_kubernetes” unset. property “users.couchbase-on-kubernetes_kubernetes” unset. property “users.couchbase-on-kubernetes_kubernetes-basic-auth” unset. property “contexts.couchbase-on-kubernetes_kubernetes” unset. property “current-context” unset. Cleared configuración para Couchbase–en–kubernetes_kubernetes desde /Users/arungupta/.kube/configuración Done |
Enjoy!


Deja un comentario
Lo siento, debes estar conectado para publicar un comentario.