How to Install Kubernetes to Run Docker on VMware vSphere

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   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
  name: web-db-pod
    app: web-db-pod
  - name: mywebdock
    image: "cricket/webdock"
    - containerPort: 80
      hostPort: 80
  - name: mydbdock
    image: "cricket/dbdock"
    - 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
# -*- coding: utf-8 -*-
import MySQLdb as mdb
import os
con = mdb.connect(os.getenv('DB_SERVICE_SERVICE_HOST',''), 'dbuser1', 'redhat', 'gss')

Note the IP address does not exist in my environment. Simply change it to and save it. Then try the URL in a browser will work

Note: Your container IP address can be different.

This entry was posted in Applications & Tools, Cloud Computing and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.