Installing Google Kubernetes does not require VMware vSphere or any other virtual machine hypervisor. However, doing that on a VM is very convenient, so it’s highly recommended especially for development and testing environment.
Regardless VM or physical machine, a Linux OS is a must. As always, I picked CentOS 7 which is a fork of RHEL. Once getting a CentOS installed, the rest is easy. If you have a CentOS template already, deploying a new one should be very fast.
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
For better user experience, you want to have clean CentoS. When I tried the installation, I used a CentOS that had Nginx installed already and that gave me quite some trouble. In the end, I had to start again from scratch.
Here are the command lines that I used to install the Kubernetes while studying the book Docker Containers – Build and Deploy with Kubernetes, Flannel, Cockpit, and Atomic (highly recommended). Because it’s for testing only, I just installed everything together in one VM. If real system, you want to have master and different nodes.
Are you ready?
Installation of Both Master and Client
First, bring the CentOS to latest and the reboot the machine.
# yum update # reboot
Then, start to install the mater node using the yum command line.
# yum install -y kubernetes etcd # systemctl stop firewalld # systemctl disable firewalld # vi /etc/kubernetes/apiserver # systemctl restart etcd kube-apiserver kube-controller-manager kube-scheduler # systemctl enable etcd kube-apiserver kube-controller-manager kube-scheduler
Now, let’s install the client:
# systemctl restart kube-proxy kubelet docker # systemctl enable kube-proxy kubelet docker
To verify it’s been successfully installed, try the following command line:
[root@vSearch ~]# kubectl get node NAME STATUS AGE 127.0.0.1 Ready 5h
Creating a New Cluster/Pod
Kubernetes uses json file to describe a POD blueprint in a real “software defined” fashion.
# vi web-db.json # kubectl create -f web-db.json
The author of the docker book I mentioned early has created a nice Pod sample as follows. It has two containers: one for Web server and the other for DB. Simple but good for illustrating a pod.
apiVersion: v1 kind: Pod metadata: name: web-db-pod labels: app: web-db-pod spec: containers: - name: mywebdock image: "cricket/webdock" ports: - containerPort: 80 hostPort: 80 - name: mydbdock image: "cricket/dbdock" ports: - containerPort: 3306 hostPort: 3306
The deployment takes a few minutes to finish. Along the way, you can use the docker ps command to see what containers are there already:
# docker ps
When you see both the containers are ready, you can verify if the Web server is running correctly:
# curl localhost:80 # curl localhost:80/cgi-bin/action
In my case, the second command failed with 500 Internal Service Error. To find out why, I login into the container for more information. It’s actually pretty easy with the following command line. Note that the docker attach command is not enough because the existing container does not have any shell running.
# docker exec -it 9392c4458609 bash
Once getting into the container, you can see the file of the
# vi /var/www/cgi-bin/action #!/usr/bin/python # -*- coding: utf-8 -*- import MySQLdb as mdb import os con = mdb.connect(os.getenv('DB_SERVICE_SERVICE_HOST','172.17.42.1'), 'dbuser1', 'redhat', 'gss')
Note the IP address 172.17.42.1 does not exist in my environment. Simply change it to 127.0.0.1 and save it. Then try the URL in a browser will work
Note: Your container IP address can be different.