I've been tinkering with Docker Swarm for container orchestration since last year. A few months ago, I watched this video about Kubernetes auto-scaling features so I was curious about how Kubernetes is now compared to Docker. Been in several discussions and looks like it is Docker Swarm vs. Kubernetes nowadays.
There are a lot of similarities in the CLI. Kubernetes has even published "kubectl for Docker Users" which basically shows the counterpart of kubectl commands to docker commands.
- You need minikube to run a Kubernetes cluster in your local machine. https://kubernetes.io/docs/tasks/tools/install-minikube/
- You need a docker image to run. You can use my docker image of a sample Spring Boot application in Dockerhub. https://hub.docker.com/r/melvindave/spring-boot-example/.
So here's how you run a docker image as a service in a Kubernetes cluster.
- Create a deployment
kubectl run mv-spring-boot-example --image=melvindave/spring-boot-example:latest --port=8080
- Check if the deployment has been created
kubectl get deployments
- Check if the container is running
kubectl get pods
- Create a service so the Pod is accessible from outside the Kubernetes virtual network.
kubectl expose deployment mv-spring-boot-example --type=LoadBalancer
- Check if the service has been created
kubectl get services
- Assuming, you've run a web application which can be accessible using a web browser, execute this command. This will automatically open up a browser using a local IP address.
minikube service mv-spring-boot-example
- Check the logs of the service
kubectl logs <pod name>
- Optionally, you can increase your service replicas to 3 for example.
kubectl scale deployments/mv-spring-boot-example --replicas=3
- Clean up - Delete the service
kubectl delete service mv-spring-boot-example
- Clean up - Delete the deployment
kubectl delete deployment mv-spring-boot-example
Here are all the commands I've used and the usual output.
It was really straightforward for someone who is familiar with Docker CLI.
Here are some references I've used:
Cheers and 'til the next article!