Kubernetes

From Network Security Wiki
Revision as of 12:20, 17 May 2018 by Amanjosan2008 (talk | contribs) (Created page with " [https://www.techrepublic.com/article/how-to-quickly-install-kubernetes-on-ubuntu/ techrepublic.com] Installing dependencies The first thing you must do is install the nece...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

techrepublic.com

Installing dependencies

The first thing you must do is install the necessary dependencies. This will be done on all machines that will join the Kubernetes cluster. The first piece to be install is apt-transport-https (a package that allows using https as well as http in apt repository sources). This can be installed with the following command:

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

Our next dependency is Docker. Our Kubernetes installation will depend upon this, so install it with:

sudo apt install docker.io

Once that completes, start and enable the Docker service with the commands

sudo systemctl start docker sudo systemctl enable docker

Installing Kubernetes

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

Next add a repository by creating the file /etc/apt/sources.list.d/kubernetes.list and enter the following content:

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

Save and close that file. Install Kubernetes with the following commands:

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

Initialize your master

With everything installed, go to the machine that will serve as the Kubernetes master and issue the command:

sudo kubeadm init


Before you join a node, you need to issue the following commands (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

Deploying a pod network

You must deploy a pod network before anything will actually function properly. I'll demonstrate this by installing the Flannel pod network. This can be done with two commands (run on the master):

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml

Issue the command sudo kubectl get pods —all-namespaces

Joining a node

With everything in place, you are ready to join the node to the master. To do this, go to the node's terminal and issue the command:

sudo kubeadm join --token TOKEN MASTER_IP:6443


Deploying a service

At this point, you are ready to deploy a service on your Kubernetes cluster. To deploy an NGINX service (and expose the service on port 80), run the following commands (from the master):

sudo kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster" sudo kubectl expose deployment nginx-app --port=80 --name=nginx-http

If you go to your node and issue the command sudo docker ps -a, you should see the service listed (Figure D).