banner



How To Create Kubernetes Cluster In Linux

How to Create a Kubernetes Cluster on Ubuntu 16.04 with kubeadm and Weave Net

How to Create a Kubernetes Cluster on Ubuntu 16.04 with kubeadm and Weave Net

Tammy Butow

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:

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

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:

            

1 apt-get update && apt-get install -y apt-transport-https

2 curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

3 cat <<EOF >/etc/apt/sources.list.d/kubernetes.list

4 deb http://apt.kubernetes.io/ kubernetes-xenial main

5 EOF

6 apt-get update

7 apt-get install -y kubelet=1.15.4-00 kubeadm=1.15.4-00 kubectl=1.15.4-00 docker.io

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:

            

1 mkdir -p $HOME/.kube

2 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

3 sudo chown $(id -u):$(id -g) $HOME/.kube/config

Your Kubernetes master has initialized successfully!

Run the following commands on kube-01:

            

1 mkdir -p $HOME/.kube

2 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

3 sudo chown $(id -u):$(id -g) $HOME/.kube/config

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:

            

1 kubeadm 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:

            

1 This 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:

The successful result will look like this:

            

1 NAME STATUS ROLES AGE VERSION

2 kube-01 Ready master 8m v1.9.3

3 kube-02 Ready <none> 6m v1.9.3

4 kube-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.

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:

            

1 curl -o weave.yaml https://cloud.weave.works/k8s/v1.8/net.yaml

Inspect the yaml contents:

On the kube-01 Kubernetes master node run the following commands:

            

1 kubectl apply -f weave.yaml

The result will look like this:

            

1 serviceaccount "weave-net" created

2 clusterrole "weave-net" created

3 clusterrolebinding "weave-net" created

4 role "weave-net" created

5 rolebinding "weave-net" created

6 daemonset "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:

            

1 kubectl get pods --all-namespaces

The successful result will look like this, every container should be running:

            

1 NAMESPACE NAME READY STATUS RESTARTS AGE

2 kube-system etcd-kube-01 1/1 Running 0 5m

3 kube-system kube-apiserver-kube-01 1/1 Running 0 6m

4 kube-system kube-controller-manager-kube-01 1/1 Running 0 5m

5 kube-system kube-dns-6f4fd4bdf-whbhd 3/3 Running 0 6m

6 kube-system kube-proxy-2hdhk 1/1 Running 0 6m

7 kube-system kube-proxy-tvhjk 1/1 Running 0 5m

8 kube-system kube-proxy-wspmv 1/1 Running 0 5m

9 kube-system kube-scheduler-kube-01 1/1 Running 0 6m

10 kube-system weave-net-9ghn5 2/2 Running 1 5m

11 kube-system weave-net-lh8tq 2/2 Running 0 5m

12 kube-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.

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 git repo:

            

1 git clone https://github.com/microservices-demo/microservices-demo.git

Go to the microservices-demo/deploy/kubernetes folder:

            

1 kubectl create namespace sock-shop

You will see the following result:

            

1 namespace "sock-shop" created

Next apply the demo to your kubernetes cluster:

            

1 kubectl apply -f complete-demo.yaml

You will see the following result:

            

1 deployment "carts-db" created

2 service "carts-db" created

3 deployment "carts" created

4 service "carts" created

5 deployment "catalogue-db" created

6 service "catalogue-db" created

7 deployment "catalogue" created

8 service "catalogue" created

9 deployment "front-end" created

10 service "front-end" created

11 deployment "orders-db" created

12 service "orders-db" created

13 deployment "orders" created

14 service "orders" created

15 deployment "payment" created

16 service "payment" created

17 deployment "queue-master" created

18 service "queue-master" created

19 deployment "rabbitmq" created

20 service "rabbitmq" created

21 deployment "shipping" created

22 service "shipping" created

23 deployment "user-db" created

24 service "user-db" created

25 deployment "user" created

26 service "user" created

Check to see if all of your pods are running:

            

1 kubectl get pods --namespace sock-shop

You will see the following result when all pods are ready, they will have the status of "Running":

            

1 NAMESPACE NAME READY STATUS RESTARTS AGE

2 kube-system etcd-kube-01 1/1 Running 0 23m

3 kube-system kube-apiserver-kube-01 1/1 Running 0 24m

4 kube-system kube-controller-manager-kube-01 1/1 Running 0 23m

5 kube-system kube-dns-6f4fd4bdf-whbhd 3/3 Running 0 24m

6 kube-system kube-proxy-2hdhk 1/1 Running 0 24m

7 kube-system kube-proxy-tvhjk 1/1 Running 0 23m

8 kube-system kube-proxy-wspmv 1/1 Running 0 23m

9 kube-system kube-scheduler-kube-01 1/1 Running 0 24m

10 kube-system weave-net-9ghn5 2/2 Running 1 23m

11 kube-system weave-net-lh8tq 2/2 Running 0 23m

12 kube-system weave-net-qhr25 2/2 Running 0 23m

13 sock-shop carts-74f4558cb8-h9924 1/1 Running 0 11m

14 sock-shop carts-db-7fcddfbc79-v64fw 1/1 Running 0 11m

15 sock-shop catalogue-676d4b9f7c-55n4g 1/1 Running 0 11m

16 sock-shop catalogue-db-5c67cdc8cd-hvk96 1/1 Running 0 11m

17 sock-shop front-end-977bfd86-hq9x9 1/1 Running 0 11m

18 sock-shop orders-787bf5b89f-xfdl6 1/1 Running 0 11m

19 sock-shop orders-db-775655b675-gv456 1/1 Running 0 11m

20 sock-shop payment-75f75b467f-4zzqs 1/1 Running 0 11m

21 sock-shop queue-master-5c86964795-t8sjg 1/1 Running 0 11m

22 sock-shop rabbitmq-96d887875-lf46w 1/1 Running 0 11m

23 sock-shop shipping-5bd69fb4cc-vprmp 1/1 Running 0 11m

24 sock-shop user-5bd9b9c468-4rms8 1/1 Running 0 11m

25 sock-shop user-db-5f9d89bbbb-r69pd 1/1 Running 0 11m

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.

How To Create Kubernetes Cluster In Linux

Source: https://www.gremlin.com/community/tutorials/how-to-create-a-kubernetes-cluster-on-ubuntu-16-04-with-kubeadm-and-weave-net/

Posted by: ruffinhiscambeste.blogspot.com

0 Response to "How To Create Kubernetes Cluster In Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel