Prerequisites for the setup:
1. Make sure you are not connected to any VPN
2. Hyper-V should be disabled in your system since minikube uses VirtualBox [Hyper-V is disabled by default]
Note:
Minikube package embeds both docker client and the daemon. You don’t need to install docker separately. But note that you can only execute docker commands from the minikube host, and not from your laptop.
Detailed Steps to setup kubernetes in local from scratch
1. Install Kubectl : curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/windows/amd64/kubectl.exe
2. Update the windows PATH to include kubectl.exe
3. Check if “kubectl version” runs properly
4. Install Minikube : https://github.com/kubernetes/minikube/releases/latest/download/minikube-installer.exe
5. Install Virtual Box
6. Start the minikube environment : minikube start
7. Check the dashboard : minikube dashboard
8. Create a tomcat deployment in the Kubernetes cluster with 3 replicas: kubectl run mytomcat –image=tomcat –replicas=3 [[This will create all the necessary pods for the deployment]]
9. List all PODs : kubectl get pods
10. You can login to any of the created PODs using : kubectl exec -it <pod_name> /bin/bash
11. Expose the deployment externally as a service : kubectl expose deployment mytomcat –port=8080 –target-port=8080 –type=NodePort
12. Check the exposed IP and Port : kubectl describe service mytomcat
13. Access the service : minikube service mytomcat
14. Check whether the requests are getting load balanced between all the replicas by checking access logs of each tomcat containers : kubectl exec -it mytomcat-75b679fc45-8t94j /bin/bash
15. Scale up the number of containers from 3 to 4 : kubectl scale –replicas=4 deployment mytomcat
16. Scale down the number of containers from 4 to 2 : kubectl scale –replicas=2 deployment mytomcat
17. Check the number of PODs Running : kubectl get pods
18. To perform a rolling update, first get the details of the deployment using : kubectl edit deployment mytomcat
19. Run the command to change the tomcat version : kubectl –record deployment/mytomcat set image deployment/mytomcat mytomcat=tomcat:7.0.96-jdk8-adoptopenjdk-hotspot
20. Look at the sequence of events below, how the new containers are spawned one by one and the old ones are terminated in a rolling fashion:
Poll on the URl to see if you get response code other than 200 : while true; do curl -I http://192.168.99.104:31906/; done
You can get a rollout history : kubectl rollout history deployment/mytomcat
deployment.apps/mytomcat REVISION CHANGE-CAUSE 1 kubectl deployment/mytomcat set image deployment/mytomcat tomcat=tomcat:7.0.96-jdk8-adoptopenjdk-hotspot –record=true 2 kubectl deployment/mytomcat set image deployment/mytomcat mytomcat=tomcat:7.0.96-jdk8-adoptopenjdk-hotspot –record=true 3 kubectl deployment/mytomcat set image deployment/mytomcat mytomcat=tomcat:8-jdk11-adoptopenjdk-hotspot –record=true |
Rolling back to the previous version : kubectl rollout undo deployment/mytomcat
Great stuff. Keep it up.