DEV Community


Try Kubernetes locally with minikube

lechatthecat profile image lechat ・3 min read


  • OS: ubuntu 18.04.2 LTS

What is Kubernetes?

Kubernetes is a container orchestration tool developed by Google. Kubernetes is a platform tool to manage containerized workloads and services.

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

-- Kubernetes

Official Interactive tutorial

If you don't want to install minikube locally, you can also try the official kubernetes interactive tutorial.


But we don't use the tutorial. We will use Minikube to run Kubernetes locally. But what is minikube? The website of Kubernetes explains what it is.

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day.

-- Kubernetes

Kubernetes vs Docker-compose vs Docker Swarm

Kubernetes is for running and connecting containers on multiple hosts (= cluster). Each node is a VM or a physical computer that serves as a worker machine in a Kubernetes cluster according to their explanation.

See the following stackoverflow for more detail:

What's the difference between docker compose and kubernetes? - stackoverflow

For docker/docker-compose, see "how to use docker/docker-compose to create Laravel environment".

Use minikube

Install minikube

See this page of Kubernetes. This tutorial is well written.

Use minikube and kubectl

Simply run this command to start minikube.

$ minikube start
Enter fullscreen mode Exit fullscreen mode

Then you will see these messages:

Now we are ready to use "kubectl" locally. Kubectl is a command line tool for controlling Kubernetes clusters.

Create nginx service

With kubectl, we will use a container image nginx:1.7.9 to deploy nginx in our kubernetes cluster.

At first, make sure the maser node is working:

$ kubectl get all 
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP    <none>        443/TCP   3d7h
Enter fullscreen mode Exit fullscreen mode

Then create yaml files somewhere as follows:


apiVersion: apps/v1
kind: Deployment
  name: nginx-deployment
    name: nginx
      name: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
        name: nginx
      - name: nginx
        image: nginx:1.7.9
        - containerPort: 80
Enter fullscreen mode Exit fullscreen mode


apiVersion: v1
kind: Service
  name: nginx
    name: nginx
  type: NodePort
    - port: 80
      nodePort: 30080
      name: http
    name: nginx
Enter fullscreen mode Exit fullscreen mode

Save the files and run this command:

$ cd (the directory where you saved the two yaml files)
$ kubectl apply -f ./nginx_deploy.yml  -f ./nginx_service.yml
Enter fullscreen mode Exit fullscreen mode

Check the nginx from browser

Check your minikube IP:

$ minikube ip
Enter fullscreen mode Exit fullscreen mode

Check port number:

$ kubectl describe service/nginx
Name:                     nginx
Namespace:                default
Labels:                   name=nginx
Selector:                 name=nginx
Type:                     NodePort
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  30080/TCP ####Port number is here!!!!!!!####
Endpoints:      ,
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
Enter fullscreen mode Exit fullscreen mode

Check from the browser with the IP and port. Confirm nginx is working in the cluster.

To delete the service and deployment after confirming from the browser:

$ kubectl delete service/nginx deployment.apps/nginx-deployment
$ kubectl get all 
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Editor guide