kubernetes and docker

In this post, I’ll be deploying a docker cluster running a number of nginx containers. Bare with me though as I am still learning about kubernetes and docker.

Machines

The master node will be controlling the worker nodes. Deployments will not run on the master node itself. From my experience, at least 1.5Gi of memory is needed for these machines.

k8s-ms | 10.0.0.165

k8s-wk1 | 10.0.0.44

k8s-wk2 | 10.0.0.58

Prereq work

  1. disable selinux
  2. populate hosts files

Installing the yum repo

Create k8s.repo

Installing the master node

Create a kube config so kubectl knows where to connect to the master

Install a pod network. I’ll be using the weave net plugin. There are a number of others – https://kubernetes.io/docs/concepts/cluster-administration/addons/

Installing the worker nodes

Create the same yum repo file and then install the packages

Join the workers to the master node

Listing nodes from the master

I now see all 3 nodes in the cluster

Create an Nginx deployment

Deploy image

Go through the worker nodes and I found 1 instance of nginx running on k8s-wk2.

Then create a service and expose port 80 on the master node’s public ip

Scale out the deployment

See the above in action

To quickly test the deployment, I go to my worker instances, locate the index.html file of the containers, and edit them. I’ve replaced the default landing page with text that can uniquely identify the containers. Then run a http GET on the load balancer IP and I see responses from different containers:

Make nginx serve a docroot from the local fs

Here the previous deployment and service will be removed. New ones will be deployed with a spec file. The nginx will also be configured to serve a local directory as docroot instead of the default /usr/share/nginx/html.

On each worker machine, create a /var/sites/default. On the master node, create a deployment spec called nginx-deployment.yml.

Delete the previous deployment and then deploy a new one with the yml file.

On each worker mode, create an index.html under /var/sites/default and test it from the master node

Dump service in yaml

This is one way to see how to write an yaml based on existing service.

References

  • https://blog.sourcerer.io/a-kubernetes-quick-start-for-people-who-know-just-enough-about-docker-to-get-by-71c5933b4633
  • https://blog.alexellis.io/kubernetes-in-10-minutes/