How to Create a Kubernetes Cluster on Ubuntu 16.04 with kubeadm and Weave Net
Introduction
Kubernetes is a system designed to manage applications built within containers across clustered environments. It handles the entire life cycle of a containerized application including deployment and scaling.
In this guide, we'll demonstrate how to get started by creating a Kubernetes cluster (v1.15) on Ubuntu 16.04. We will be using kubeadm to setup kubernetes. We will then deploy the Weaveworks Socks Shop Microservices Application as a demonstration of how to run microservices on Kubernetes.
The purpose of this tutorial is to enable you to run a demo microservices application on a kubernetes cluster you have created.
The overall feature state of kubeadm is Beta and will be graduated to General Availability (GA) in 2018.
Prerequisites
Before you begin this tutorial, you’ll need the following:
- 3 Ubuntu 16.04 servers with 4GM RAM and private networking enabled
Step 1 - Get each server ready to run Kubernetes
We will start with creating three Ubuntu 16.04 servers. This will give you three servers to configure. To get this three member cluster up and running, you will need to select Ubuntu 16.04, 4GM RAM servers and enable Private Networking.
Create 3 hosts and call them kube-01, kube-02 and kube-03. You need to be running hosts with a minimum of 4GB RAM for the Weave Socks Shop Demo.
Set your hostnames for your servers as follows:
Kubernetes will need to assign specialized roles to each server. We will setup one server to act as the master:
Step 2 - Set up each server in the cluster to run Kubernetes.
SSH to each of the servers you created. Proceed with executing the following commands as root. You may become the root user by executing sudo -i after SSH-ing to each host.
On each of the three Ubuntu 16.04 servers run the following commands as root:
Step 3 - Setup the Kubernetes Master
On the kube-01 node run the following command:
This can take a minute or two to run, the result will look like this:
To start using your cluster, you need to run the following as a regular user:
Your Kubernetes master has initialized successfully!
Run the following commands on kube-01:
Step 4 - Join your nodes to your Kubernetes cluster
You can now join any number of machines by running the kubeadm join command on each node as root. This command will be created for you as displayed in your terminal for you to copy and run.
An example of what this looks like is below:
When you join your kube-02 and kube-01 nodes you will see the following on the node:
To check that all nodes are now joined to the master run the following command on the Kubernetes master kube-01:
The successful result will look like this:
You will notice that the nodes do not have a role set on join, there is an open PR to resolve this.
Step 5 - Setup a Kubernetes Add-On For Networking Features And Policy
Kubernetes Add-Ons are pods and services that implement cluster features. Pods extend the functionality of Kubernetes. You can install addons for a range of cluster features including Networking and Visualization.
We are going to install the Weave Net Add-On on the kube-01 master which provides networking and network policy, will carry on working on both sides of a network partition, and does not require an external database. Read more about the Weave Net Add-on in the Weave Works Docs.
Next you will deploy a pod network to the cluster.
The options are listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/
Installing the Weave Net Add-On
Get the Weave Net yaml:
Inspect the yaml contents:
On the kube-01 Kubernetes master node run the following commands:
The result will look like this:
It may take a minute or two for DNS to be ready, continue to check for DNS to be ready before moving on by running the following command:
The successful result will look like this, every container should be running:
Congratulations, now your Kubernetes cluster running on Ubuntu 16.04 is up and ready for you to deploy a microservices application.
Step 6 - Deploying The Weaveworks Microservices Sock Shop
Next we will deploy a demo microservices application to your kubernetes cluster.
First, on kube-01, clone the microservices sock shop
Go to the microservices-demo/deploy/kubernetes folder:
You will see the following result:
Next apply the demo to your kubernetes cluster:
You will see the following result:
Check to see if all of your pods are running:
You will see the following result when all pods are ready, they will have the status of “Running”:
Visit http://174.138.15.158:30001/ to see the Sock Shop working:
Conclusion
You have created a Kubernetes cluster and learned how to use the Kubernetes command-line tool kubectl. You then deployed Weave Socks Shop Microservices Application as a demonstration of how to run microservices on Kubernetes. You have now started to see how Kubernetes is designed to manage applications built within containers across clustered environments.
To create Gremlin attacks on Kubernetes follow our guide on "How To Install And Use Gremlin With Kubernetes". Join the Chaos Engineering Slack Community to discuss how Chaos Engineering can be practiced on Kubernetes.
Avoid downtime. Use Gremlin to turn failure into resilience.
Gremlin empowers you to proactively root out failure before it causes downtime. See how you can harness chaos to build resilient systems by requesting a demo of Gremlin.