How to Install and Deploy Kubernetes on Ubuntu 16.04

Prerequisites

  • Two fresh Alibaba Cloud Elastic Compute Service (ECS) instance with Ubuntu 16.04 server installed.
  • A static IP address 192.168.0.103 is configured on the first instance (Master) and 192.168.0.104 is configured on the second instance (Slave).
  • Minimum 2GB RAM per instance.
  • A Root password is setup on each instance.

Launch Alibaba Cloud ECS Instance

First, Login to your https://ecs.console.aliyun.com/?spm=a3c0i.o25424en.a3.13.388d499ep38szx">Alibaba Cloud ECS Console. Create a new ECS instance, choosing Ubuntu 16.04 as the operating system with at least 2GB RAM. Connect to your ECS instance and log in as the root user.

Configuring Your ECS Server

Before starting, you will need to configure hosts file and hostname on each server, so each server can communicate with each other using the hostname.

192.168.0.103 master-node
192.168.0.104 slave-node
192.168.0.103 master-node
192.168.0.104 slave-node
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda4 during installation
UUID=6f612675-026a-4d52-9d02-547030ff8a7e / ext4 errors=remount-ro 0 1
# swap was on /dev/sda6 during installation
#UUID=46ee415b-4afa-4134-9821-c4e4c275e264 none swap sw 0 0
/dev/sda5 /Data ext4 defaults 0 0

Install Docker

Before starting, you will need to install Docker on both the master and slave server. By default, the latest version of the Docker is not available in Ubuntu 16.04 repository, so you will need to add Docker repository to your system.

apt-get update -y
apt-get install docker-ce -y

Install Kubernetes

Next, you will need to install kubeadm, kubectl and kubelet on both the server. First, download and GPG key with the following command:

apt-get update -y
apt-get install kubelet kubeadm kubectl -y

Configure Master Node

All the required packages are installed on both servers. Now, it’s time to configure Kubernetes Master Node.

Your Kubernetes master has initialized successfully!To start using your cluster, you need to run the following as a regular user:  mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join --token 62b281.f819128770e900a3 192.168.0.103:6443 --discovery-token-ca-cert-hash sha256:68ce767b188860676e6952fdeddd4e9fd45ab141a3d6d50c02505fa0d4d44686
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
NAME          STATUS     ROLES     AGE       VERSION
master-node NotReady master 14m v1.9.4
NAMESPACE     NAME                                      READY     STATUS              RESTARTS   AGE
kube-system calico-etcd-p2gbx 0/1 ContainerCreating 0 35s
kube-system calico-kube-controllers-d554689d5-v5lb6 0/1 Pending 0 34s
kube-system calico-node-667j2 0/2 ContainerCreating 0 35s
kube-system etcd-master-node 1/1 Running 0 15m
kube-system kube-apiserver-master-node 1/1 Running 0 15m
kube-system kube-controller-manager-master-node 1/1 Running 0 15m
kube-system kube-dns-6f4fd4bdf-7rl74 0/3 Pending 0 15m
kube-system kube-proxy-hqb98 1/1 Running 0 15m
kube-system kube-scheduler-master-node 1/1 Running 0 15m
NAME          STATUS    ROLES     AGE       VERSION
master-node Ready master 7m v1.9.4

Add Slave Node to the Kubernetes Cluster

Next, you will need to log in to the Slave Node and add it to the Cluster. Remember the join command in the output from the Master Node initialization command and issue it on the Slave Node as shown below:

[discovery] Trying to connect to API Server "192.168.0.103:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.0.104:6443"
[discovery] Requesting info from "https://192.168.0.104:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.0.104:6443"
[discovery] Successfully established connection with API Server "192.168.0.103:6443"
This node has joined the cluster:
* Certificate signing request was sent to master and a response
was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the master to see this node join the cluster.
NAME          STATUS    ROLES     AGE       VERSION
master-node Ready master 35m v1.9.4
slave-node Ready <none> 7m v1.9.4

Deploy the Apache Container to the Cluster

Kubernetes Cluster is now ready, it’s time to deploy the Apache container.

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
apache 1 1 1 0 16s
Name:                   apache
Namespace: default
CreationTimestamp: Mon, 19 Mar 2018 19:04:03 +0530
Labels: app=apache
Annotations: deployment.kubernetes.io/revision=1
Selector: app=apache
Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=apache
Containers:
apache:
Image: apache
Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: apache-5fcc8cd4bf (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 43s deployment-controller Scaled up replica set apache-5fcc8cd4bf to 1
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
apache NodePort 10.107.95.29 <none> 80:30267/TCP 15s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 37m

Related Alibaba Cloud Products

After completing your Kubernetes Cluster, it makes perfect sense to scale it for production. That’s the whole design concept of using containers. To do this, we need to set up a database for our application. Ideally, for production scenarios, I do not recommend making your own database. Instead, you can choose from one of Alibaba Cloud’s suite of database products.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com