Docker 18.03.0 CE Release is now available under Docker for Mac Platform. Docker for Mac 18.03.0 CE is now shipped with Docker Compose version 1.20.1, Kubernetes v1.9.2, Docker Machine 0.14.0 & Notary 0.6.0. Few of the promising features included under this release are listed below-
- Changing VM Swap size under settings
- Linux Kernel 4.9.87
- Support of NFS Volume sharing under Kubernetes.
- Revert the default disk format to qcow2 for users running macOS 10.13 (High Sierra).
- DNS name `host.docker.internal` used for host resolution from containers.
- Improvement over Kubernetes Load balanced services (No longer marked as `Pending`)
- Fixed hostPath mounts in Kubernetes`.
- Fix support for AUFS.
- Fix synchronisation between CLI `docker login` and GUI login.
- Updated Compose on Kubernetes to v0.3.0. Existing Kubernetes stacks will be removed during migration and need to be re-deployed on the cluster… and many more
In my last blog, I talked about context switching and showcased how one can switch the context from docker-for-desktop to Minikube under Docker for Mac Platform. A context element in a kubeconfig file is used to group access parameters under a convenient name. Each context has three parameters: cluster, namespace, and user. By default, the
kubectl command-line tool uses parameters from the current context to communicate with the cluster. Under .kube/config file, you can see the list of context specified a shown below –
Under this blog, I will showcase how you can bootstrap Kubernetes Cluster on GKE Platform using context switching functionality under Docker for Mac Platform.
- Install/Upgrade Docker for Mac 18.03 CE Edition
- Install google-cloud-sdk
- Enable Google Cloud Engine API
- Authenticate Your Google Cloud using
Installing Docker for Mac 18.03 CE Edition
Installing Google Cloud SDK on your macOS
- Make sure that Python 2.7 is installed on your system:
Ajeets-MacBook-Air:~ ajeetraina$ python -V Python 2.7.10
- Download the below package based on your system.
|macOS 64-bit(x86_64)||google-cloud-sdk-195.0.0-darwin-x86_64.tar.gz||15.0 MB||56d72895dfc6c4208ca6599292aff629e357ad517e6979203a68a3a8ca5f6cc8|
|macOS 32-bit(x86)||google-cloud-sdk-195.0.0-darwin-x86.tar.gz||15.0 MB||e389ec98b65a0dbfc3f2c2637b9e3a375913b39d50e668fecb07cd04474fc080|
- Extract the archive to any location on your file system.
- Restart your terminal for the changes to take effect.
Initializing the SDK
In your browser, log in to your Google user account when prompted and click Allow to grant permission to access Google Cloud Platform resources.
Enabling Kubernetes Engine API
You need to enable K8s engine API to bootstrap K8s cluster on Google Cloud Platform. To do so, open up this link.
Authenticate Your Google Cloud
Next, you need to authenticate your Google Cloud using
Done. We are all set to bootstrap K8s cluster…
Creating GKE Cluster Node
Ajeets-MacBook-Air:~ ajeetraina$ gcloud container clusters create k8s-lab1 --disk-size 10 --zone asia-east1-a --machine-type n1-standard-2 --num-nodes 3 --scopes compute-rw WARNING: The behavior of --scopes will change in a future gcloud release: service-control and service-management scopes will no longer be added to what is specified in --scopes. To use these scopes, add them explicitly to --scopes. To use the new behavior, set container/new_scopes_behavior property (gcloud config set container/new_scopes_behavior true). WARNING: Starting in Kubernetes v1.10, new clusters will no longer get compute-rw and storage-ro scopes added to what is specified in --scopes (though the latter will remain included in the default --scopes). To use these scopes, add them explicitly to --scopes. To use the new behavior, set container/new_scopes_behavior property (gcloud config set container/new_scopes_behavior true). Creating cluster k8s-lab1...done. Created [https://container.googleapis.com/v1/projects/spheric-temple-187614/zones/asia-east1-a/clusters/k8s-lab1]. To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/asia-east1-a/k8s-lab1?project=spheric-temple-187614 kubeconfig entry generated for k8s-lab1. NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS k8s-lab1 asia-east1-a 1.7.11-gke.1 184.108.40.206 n1-standard-2 1.7.11-gke.1 3 RUNNING
Viewing it on Docker for Mac UI
Click on Whale icon on the top right of Docker for Mac and by now, you must be able to see the new Context getting appeared.
Listing the Nodes
Ajeets-MacBook-Air:~ ajeetraina$ kubectl get nodes NAME STATUS ROLES AGE VERSION gke-k8s-lab1-default-pool-042d2598-591g Ready <none> 7m v1.7.11-gke.1 gke-k8s-lab1-default-pool-042d2598-c633 Ready <none> 7m v1.7.11-gke.1 gke-k8s-lab1-default-pool-042d2598-q603 Ready <none> 7m v1.7.11-gke.1
Viewing it directly under GCP Platform
Connecting to Your GKE Cluster
There are 2 ways to do this:
Method-1: Click on “Connection” button to see how to connect to K8s-lab1.
You can connect to your cluster via command-line or using a dashboard.
Ajeets-MacBook-Air:~ ajeetraina$gcloud container clusters get-credentials k8s-lab1 --zone asia-east1-a --project captain-199803 Fetching cluster endpoint and auth data. kubeconfig entry generated for k8s-lab1.
Fetching cluster endpoint and auth data. kubeconfig entry generated for k8s-lab1.
Listing the Nodes under Google Cloud Platform
Deploy Nginx on GKE Cluster
Let us see how to deploy Nginx on remote GKE cluster using Docker for Mac. This requires two commands. deploy and expose.
Step 1: Deploy nginx
$ kubectl run nginx --image=nginx --replicas=3 deployment "nginx" created
This will create a replication controller to spin up 3 pods, each pod runs the nginx container.
Step 2: Verify that the pods are running.
You can see the status of deployment by running:
kubectl get pods -owide NAME READY STATUS RESTARTS AGE IP NODE nginx-7c87f569d-glczj 1/1 Running 0 8s 10.12.2.6 gke-k8s-lab1-default-pool-b2aaa29b-w904 nginx-7c87f569d-pll76 1/1 Running 0 8s 10.12.0.8 gke-k8s-lab1-default-pool-b2aaa29b-2gzh nginx-7c87f569d-sf8z9 1/1 Running 0 8s 10.12.1.8 gke-k8s-lab1-default-pool-b2aaa29b-qpc7
Youcan see that each nginx pod is now running in a different node (virtual machine).
Once all pods have the Running status, you can then expose the nginx cluster as an external service.
Step 3: Expose the nginx cluster as an external service.
$ kubectl expose deployment nginx --port=80 --target-port=80 \ --type=LoadBalancer service "nginx" exposed
This command will create a network load balancer to load balance traffic to the three nginx instances.
Step 4: Find the network load balancer address:
kubectl get service nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx LoadBalancer 10.15.247.8 <pending> 80:30253/TCP 12s
It may take several minutes to see the value of EXTERNAL_IP. If you don’t see it the first time with the above command, retry every minute or so until the value of EXTERNAL_IP is displayed.
You can then visit http://EXTERNAL_IP/ to see the server being served through network load balancing.
GKE provides amazing platform to view workloads & Load-balancer as shown below:
GKE also provides UI for displaying Loadbalancer:
In my upcoming blog post, I will showcase how context switching can help you in switching your project between Dev, QA & Production environment flawlessly.
Did you find this blog helpful? Feel free to share your experience. Get in touch with me on Twitter – @ajeetsraina
If you are looking out for contribution, join me at Docker Community Slack Channel.