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.
Before you begin this tutorial, you’ll need the following:
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:
Server | Hostname |
---|---|
1 | kube-01 |
2 | kube-02 |
3 | kube-03 |
Kubernetes will need to assign specialized roles to each server. We will setup one server to act as the master:
Hostname | Role |
---|---|
kube-01 | Master |
kube-02 | Node |
kube-03 | Node |
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:
1apt-get update && apt-get install -y apt-transport-https2curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -3cat <<EOF >/etc/apt/sources.list.d/kubernetes.list4deb http://apt.kubernetes.io/ kubernetes-xenial main5EOF6apt-get update7apt-get install -y kubelet=1.15.4-00 kubeadm=1.15.4-00 kubectl=1.15.4-00 docker.io
On the kube-01 node run the following command:
1kubeadm init
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:
1mkdir -p $HOME/.kube2sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config3sudo chown $(id -u):$(id -g) $HOME/.kube/config
Your Kubernetes master has initialized successfully!
Run the following commands on kube-01:
1mkdir -p $HOME/.kube2sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config3sudo chown $(id -u):$(id -g) $HOME/.kube/config
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:
1kubeadm join --token 702ff6.bc7aacff7aacab17 174.138.15.158:6443 --discovery-token-ca-cert-hash sha256:68bc22d2c631800fd358a6d7e3998e598deb2980ee613b3c2f1da8978960c8ab
When you join your kube-02 and kube-01 nodes you will see the following on the node:
1This node has joined the cluster:2* Certificate signing request was sent to master and a response was received.3* The Kubelet was informed of the new secure connection details.
To check that all nodes are now joined to the master run the following command on the Kubernetes master kube-01:
1kubectl get nodes
The successful result will look like this:
1NAME STATUS ROLES AGE VERSION2kube-01 Ready master 8m v1.9.33kube-02 Ready <none> 6m v1.9.34kube-03 Ready <none> 6m v1.9.3
You will notice that the nodes do not have a role set on join, there is an open PR to resolve this.
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/
Get the Weave Net yaml:
1curl -o weave.yaml https://cloud.weave.works/k8s/v1.8/net.yaml
Inspect the yaml contents:
1cat weave.yaml
On the kube-01 Kubernetes master node run the following commands:
1kubectl apply -f weave.yaml
The result will look like this:
1serviceaccount "weave-net" created2clusterrole "weave-net" created3clusterrolebinding "weave-net" created4role "weave-net" created5rolebinding "weave-net" created6daemonset "weave-net" created
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:
1kubectl get pods --all-namespaces
The successful result will look like this, every container should be running:
1NAMESPACE NAME READY STATUS RESTARTS AGE2kube-system etcd-kube-01 1/1 Running 0 5m3kube-system kube-apiserver-kube-01 1/1 Running 0 6m4kube-system kube-controller-manager-kube-01 1/1 Running 0 5m5kube-system kube-dns-6f4fd4bdf-whbhd 3/3 Running 0 6m6kube-system kube-proxy-2hdhk 1/1 Running 0 6m7kube-system kube-proxy-tvhjk 1/1 Running 0 5m8kube-system kube-proxy-wspmv 1/1 Running 0 5m9kube-system kube-scheduler-kube-01 1/1 Running 0 6m10kube-system weave-net-9ghn5 2/2 Running 1 5m11kube-system weave-net-lh8tq 2/2 Running 0 5m12kube-system weave-net-qhr25 2/2 Running 0 5m
Congratulations, now your Kubernetes cluster running on Ubuntu 16.04 is up and ready for you to deploy a microservices application.
Next we will deploy a demo microservices application to your kubernetes cluster.
First, on kube-01, clone the microservices sock shop git repo:
1git clone https://github.com/microservices-demo/microservices-demo.git
Go to the microservices-demo/deploy/kubernetes folder:
1kubectl create namespace sock-shop
You will see the following result:
1namespace "sock-shop" created
Next apply the demo to your kubernetes cluster:
1kubectl apply -f complete-demo.yaml
You will see the following result:
1deployment "carts-db" created2service "carts-db" created3deployment "carts" created4service "carts" created5deployment "catalogue-db" created6service "catalogue-db" created7deployment "catalogue" created8service "catalogue" created9deployment "front-end" created10service "front-end" created11deployment "orders-db" created12service "orders-db" created13deployment "orders" created14service "orders" created15deployment "payment" created16service "payment" created17deployment "queue-master" created18service "queue-master" created19deployment "rabbitmq" created20service "rabbitmq" created21deployment "shipping" created22service "shipping" created23deployment "user-db" created24service "user-db" created25deployment "user" created26service "user" created
Check to see if all of your pods are running:
1kubectl get pods --namespace sock-shop
You will see the following result when all pods are ready, they will have the status of “Running”:
1NAMESPACE NAME READY STATUS RESTARTS AGE2kube-system etcd-kube-01 1/1 Running 0 23m3kube-system kube-apiserver-kube-01 1/1 Running 0 24m4kube-system kube-controller-manager-kube-01 1/1 Running 0 23m5kube-system kube-dns-6f4fd4bdf-whbhd 3/3 Running 0 24m6kube-system kube-proxy-2hdhk 1/1 Running 0 24m7kube-system kube-proxy-tvhjk 1/1 Running 0 23m8kube-system kube-proxy-wspmv 1/1 Running 0 23m9kube-system kube-scheduler-kube-01 1/1 Running 0 24m10kube-system weave-net-9ghn5 2/2 Running 1 23m11kube-system weave-net-lh8tq 2/2 Running 0 23m12kube-system weave-net-qhr25 2/2 Running 0 23m13sock-shop carts-74f4558cb8-h9924 1/1 Running 0 11m14sock-shop carts-db-7fcddfbc79-v64fw 1/1 Running 0 11m15sock-shop catalogue-676d4b9f7c-55n4g 1/1 Running 0 11m16sock-shop catalogue-db-5c67cdc8cd-hvk96 1/1 Running 0 11m17sock-shop front-end-977bfd86-hq9x9 1/1 Running 0 11m18sock-shop orders-787bf5b89f-xfdl6 1/1 Running 0 11m19sock-shop orders-db-775655b675-gv456 1/1 Running 0 11m20sock-shop payment-75f75b467f-4zzqs 1/1 Running 0 11m21sock-shop queue-master-5c86964795-t8sjg 1/1 Running 0 11m22sock-shop rabbitmq-96d887875-lf46w 1/1 Running 0 11m23sock-shop shipping-5bd69fb4cc-vprmp 1/1 Running 0 11m24sock-shop user-5bd9b9c468-4rms8 1/1 Running 0 11m25sock-shop user-db-5f9d89bbbb-r69pd 1/1 Running 0 11m
Visit http://174.138.15.158:30001/ to see the Sock Shop working:
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.
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.
Get started