Running a Service in a Kubernetes cluster using a Docker image

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.


  1. You need minikube to run a Kubernetes cluster in your local machine.
  2. You need a docker image to run. You can use my docker image of a sample Spring Boot application in Dockerhub.


So here's how you run a docker image as a service in a Kubernetes cluster.

  1. Create a deployment
kubectl run mv-spring-boot-example --image=melvindave/spring-boot-example:latest --port=8080
  1. Check if the deployment has been created
kubectl get deployments
  1. Check if the container is running
kubectl get pods
  1. Create a service so the Pod is accessible from outside the Kubernetes virtual network.
kubectl expose deployment mv-spring-boot-example --type=LoadBalancer
  1. Check if the service has been created
kubectl get services
  1. 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


  1. Check the logs of the service
kubectl logs <pod name>


  1. Optionally, you can increase your service replicas to 3 for example.
kubectl scale deployments/mv-spring-boot-example --replicas=3
  1. Clean up - Delete the service
kubectl delete service mv-spring-boot-example
  1. 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:

Hope you learned something from the article, would love to connect in LinkedIn!

Cheers and 'til the next article!