Kubernetes is software for managing a cluster of Docker containers. Kubernetes orchestration includes scheduling, distributing workload, and scaling. Kubernetes takes the software encapsulation provided by Docker further by introducing Pods. A Pod is a collection of one or more Docker containers with single interface features such as providing networking and filesystem at the Pod level rather than at the container level. Kubernetes also introduces labels using which services and replication controllers (replication controller is used to scale a cluster) identify or select the containers or pods they manage. Kubernetes is lightweight, portable (suited for the cloud architecture), and modular.
Kubernetes may be run on almost any platform. Local machine solutions include local Docker based, Vagrant, and no-VM local cluster. Hosted solutions include Google Container Engine. Some of the other platforms supported by Kubernetes are Fedora (Ansible and Manual), Amazon Web Services, Mesos, vSphere, and CoreOS. Kubernetes is an orchestration software for Docker containers; the recommended solution for installation is to use the Docker Engine. In this chapter we shall install Kubernetes on Docker, which runs on Ubuntu. We shall use an Amazon EC2 instance hosting Ubuntu as the operating system. In this chapter, a single node installation of Kubernetes is discussed. Multi-node installation of Kubernetes is discussed in chapter . This chapter has the following sections.
Setting the Environment
Installing Docker
Installing Kubernetes
Starting etcd
Starting Kubernetes Master
Starting Service Proxy
Listing the Kubernetes Docker Containers
Installing kubectl
Listing Services
Listing Nodes
Testing the Kubernetes Installation
Setting the Environment
The following software is required for this chapter.
Linux is required to support 64-bit software. We have used an Amazon EC2 instance created from AMI Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-d05e75b8. An Amazon EC2 instance based on the Ubuntu AMI is shown in Figure .
Figure 1-1.
Amazon EC2 Instance Based on Ubuntu AMI
A different Ubuntu version may be used if the requirement of a 64-bit architecture is met. The minimum kernel version requirement is 3.10. The kernel version may be verified with the following command.
uname r
The Public IP would be different for different users. Multiple Amazon EC2 instances and therefore multiple Public IP addresses have been used in the book as a different Public IP is assigned each time an Amazon EC2 instance is started. The Private IP Address of an Amazon EC2 instance is the same across restarts. SSH into an Ubuntu instance on Amazon EC2 (Public IP is 52.91.80.173 in following command).
ssh -i "docker.pem" ubuntu@52.91.80.173
The Amazon EC2 instance gets logged in as shown in Figure . The command prompt becomes ubuntu@ip-172-30-1-190 instead of root@localhost. Ip 172.30.1.190 is the Private IP of the Amazon EC2 instance and would also be different for different users.
Figure 1-2.
Loging into an Amazon EC2 instance
In the next section we shall install Docker on Ubuntu hosted on an Amazon EC2 instance.
Installing Docker
Ubuntu uses apt for package management; apt stores a list of repositories in the /etc/apt/sources.list list. Dockers apt repository is kept in the /etc/apt/sources.list.d/docker.list file. First, add the new repository key (gpg key) for the Docker repository with the following command.
sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
The new gpg key gets added as shown in Figure .
Figure 1-3.
Adding a new gpg key
Next, update the apt sources for the Docker repository in the /etc/apt/sources.list.d/docker.list file based on the Ubuntu distribution, which may be found with the following command.
lsb_release a
For Ubuntu Trusty, add the following line to the /etc/apt/sources.list.d/docker.list file; the docker.list file may be opened with sudo vi /etc/apt/sources.list.d/docker.list.
deb https://apt.dockerproject.org/repo ubuntu-trusty main
Create the /etc/apt/sources.list.d/docker.list file if the file does not already exist. The updated file is shown in Figure . Save the file with the :wq command if opened in the vi editor.
Figure 1-4.
Creating the docker.list file
The entry to be added would be different for different Ubuntu distributions as listed in Table .
Table 1-1.
The docker.list file Entry Based on Ubuntu Distribution
Ubuntu Distribution | Entry |
---|
Ubuntu Precise 12.04 (LTS) | deb https://apt.dockerproject.org/repo ubuntu-precise main |
Ubuntu Trusty 14.04 (LTS) | deb https://apt.dockerproject.org/repo ubuntu-trusty main |
Ubuntu Vivid 15.04 | deb https://apt.dockerproject.org/repo ubuntu-vivid main |
Run the following commands after updating the /etc/apt/sources.list.d/docker.list file to update the apt package index.
sudo apt-get update
Apt package index gets updated as shown in Figure .
Figure 1-5.
Updating Ubuntu Package List
Purge the old repository if it exists with the following command.
sudo apt-get purge lxc-docker*
The output in Figure indicates that the old packages lxc-docker and lxc-docker-virtual-package are not installed and therefore not removed.
Figure 1-6.
Purging the Old Repository
Run the following command to verify that apt is pulling from the updated repository for Docker.
sudo apt-cache policy docker-engine
The output in Figure indicates that the new repository ubuntu-trusty as specified in the /etc/apt/sources.list.d/docker.list is being used.