• Install Minikube (or use personal Cloud Cluster, for example AWS or Google Cloud)
  • Install Kubectl

* If you need help, see this Kubernetes setup tutorial

Table of contents

In this blog post, we will create a basic starter express application which will connect to nginx server with Kubernetes load balancer.

Project structure:

Project files

Available at GitHub

Build docker image locally:

docker build . -t devwl/k8s-node-express-nginx

* replace capital letters with your own values

Once the image is build, push the docker image to docker hub.

docker login

docker push devwl/k8s-node-express-nginx

* replace capital letters with your own values

Now run kubectl apply in terminal

kubectl apply -f k8s-node-express-nginx.yaml -f nginx.yaml

To investigate pods, deployments, and services run: kubectl get pods kubectl get deploy kubectl get svc . To run service use minikube service NAMEOFASERVICE for example minikube service k8s-node-express-nginx. Alternatively you could combine minikube IP address with service auto generated port number:

The above would combine to Note that your port number will be different.

Accession of specific pod from terminal in Kubernetes

If you need to run command with in one of the specific Kubernetes pods you can reach them via exec command. List all available pods kubectl get pods.

To connect to specific pods copy pods ID and type -- and enter your command. For example:

kubectl exec k8s-node-express-nginx-767d99757d-hk5q5 -- ls

Now let’s look up this pod IP address running:

kubectl exec k8s-node-express-nginx-767d99757d-hk5q5 -- nslookup nginx

Notice that the above IP address also represent nginx service IP address:

You can connect from web root container to nginx using wget:

kubectl exec k8s-node-express-nginx-767d99757d-hk5q5 -- wget -qO- http://nginx

Kubernetes – Clean up deployments

kubectl delete -f k8s-node-express-nginx.yaml -f nginx.yaml
kubectl delete --all pods --namespace=default

Kubernetes video tutorial

Would love your thoughts, please comment.x