Kubernetes Deploy Example - Part 1

Kubernetes is a container orchestration system for automating application deployment, scaling and management. Here we will show a simple example of nginx deployment by kubernetes.

Requirements

  1. install kubernetes, for me, I use minikube
  2. install docker

Step 1: Pull the image from Docker Registry

1
2
$ kubectl run nginx --image=nginx:latest --port=80

Step 2: Check if deployment ok

1
2
3
4
5
$ kubectl get pods

NAME READY STATUS RESTARTS AGE
nginx-6bfb654d7c-xjvhg 1/1 Running 0 1h

Step 3: Expose service through NodePort

As I use minikube in local, I don’t have LoadBalancer installed, so I use NodePort as type here

1
2
3
4
kubectl expose deployment nginx --type=NodePort --port=80 --target-port=80

service "nginx" exposed

Step 4: Get service port

1
2
3
4
5
kubectl get svc nginx

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.109.174.66 <none> 80:32598/TCP 45m

Here we can find that the service if exposed by port 32598

Step 5: Get kubernetes ip

1
2
3
4
5
kubectl get endpoints kubernetes

NAME ENDPOINTS AGE
kubernetes 192.168.99.100:8443 143d

Step 6: Access to nginx

Open your navigator and type the url of kubernetes with the port of nginx, you will access to welcome page of nginx

1
2
http://192.168.99.100:32598