Subscribe Us


Breaking

Recent In Voip

Popular

Comments

Recent

Setup Kubernets Cluster in Ubuntu

 

Install Docker

1. Update the package list with the command:

    sudo apt-get update

2. Next, install Docker with the command:

sudo apt-get install docker.io

3. Repeat the process on each server that will act as a node.

4. Check the installation (and version) by entering the following:

docker ––version

Start and Enable Docker

1. Set Docker to launch at boot by entering the following:

sudo systemctl enable docker

2. Verify Docker is running:

sudo systemctl status docker

To start Docker if it’s not running:

   sudo systemctl start docker

Install Kubernetes

Add Kubernetes Signing Key

Since you are downloading Kubernetes from a non-standard repository, it is essential to ensure that the software is authentic. This is done by adding a signing key.

1. Enter the following to add a signing key:

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

If you get an error that curl is not installed, install it with:

sudo apt-get install curl

2. Then repeat the previous command to install the signing keys. Repeat for each server node.

Add Software Repositories

Kubernetes is not included in the default repositories. To add them, enter the following:

sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

Repeat on each server node.

Kubernetes Installation Tools

Kubeadm (Kubernetes Admin) is a tool that helps initialize a cluster. It fast-tracks setup by using community-sourced best practices. Kubelet is the work package, which runs on every node and starts containers. The tool gives you command-line access to clusters.

1. Install Kubernetes tools with the command:

sudo apt-get install kubeadm kubelet kubectl
sudo apt-mark hold kubeadm kubelet kubectl

Allow the process to complete.

2. Verify the install


Deploy Pod Network to Cluster

A Pod Network is a way to allow communication between different nodes in the cluster. This tutorial uses the flannel virtual network.

Enter the following:

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

Allow the process to complete.

Verify that everything is running and communicating:

kubectl get pods --all-namespaces

kubeadm version

Soma commands to manage kubernets cluster .

# kubectl get nodes.

#kubectl get pods 

#kubectl get pods -all-namespaces

#kubectl describe nodes

#kubectl describe pods 

Command to check if deployment was created 

kubectl get deployments


Deployment & NodePort service manifest file Example

Deployment YAML file:

~~~~~~~~~~~~~~~~~~~~~

# Deployment

# nginx-deploy.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: nginx-deployment

  labels:

    app: nginx-app

spec:

  replicas: 1

  selector:

    matchLabels:

      app: nginx-app

  template:

    metadata:

      labels:

        app: nginx-app

    spec:

      containers:

      - name: nginx-container

        image: nginx:1.7.9

        ports:

        - containerPort: 80

--------------------------------------


NodePort Service YAML file:

~~~~~~~~~~~~~~~~~~~~~~~~~~

# Service

# nginx-svc-np.yaml

apiVersion: v1

kind: Service

metadata:

  name: my-service

  labels:

    app: nginx-app

spec:

  selector:

    app: nginx-app

  type: NodePort

  ports:

  - nodePort: 31111

    port: 80

    targetPort: 80


*******************************************************************

Create and Display Deployment and NodePort

kubectl create -f nginx-deploy.yaml

kubectl create -f nginx-svc.yaml

kubectl get service -l app=nginx-app

kubectl get po -o wide

kubectl describe svc my-service

*******************************************************************

Testing

# To get inside the pod

kubectl exec [POD-IP] -it /bin/sh

# Create test HTML page

cat <<EOF > /usr/share/nginx/html/test.html

<!DOCTYPE html>

<html>

<head>

<title>Testing..</title>

</head>

<body>

<h1 style="color:rgb(90,70,250);">Hello, NodePort Service...!</h1>

<h2>Congratulations, you passed :-) </h2>

</body>

</html>

EOF

exit

Test using Pod IP:

~~~~~~~~~~~~~~~~~~~~~~~

kubectl get po -o wide

curl http://[POD-IP]/test.html

NodePort  ñ  Accessing using Service IP


Test using Service IP:

~~~~~~~~~~~~~~~~~~~~~~~~~~~

kubectl get svc -l app=nginx-app

curl http://[cluster-ip]/test.html

Test using Node IP (external IP)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

http://nodep-ip:nodePort/test.html

note: node-ip is the external ip address of a node.

*******************************************************************

 Cleanup

kubectl delete -f nginx-deploy.yaml

kubectl delete -f nginx-svc.yaml

kubectl get deploy

kubectl get svc

kubectl get pods

*******************************************************************

REPLICA SET EXAMPLE.

ReplicaSet YAML file


# nginx-rs.yaml

apiVersion: apps/v1

kind: ReplicaSet

metadata:

  name: nginx-rs

spec:

  replicas: 3

  template:

    metadata:

      name: nginx-pod

      labels:

        app: nginx-app

        tier: frontend

    spec:

      containers:

      - name: nginx-container

        image: nginx

        ports:

        - containerPort: 80

  selector:

    matchLabels:

      app: nginx-app

    matchExpressions:

      - {key: tier, operator: In, values: [frontend]}



*******************************************************************

Create and display replicaset

kubectl create -f nginx-rs.yaml

kubectl get po -o wide

kubectl get po -l app=nginx-app

kubectl get rs nginx-rs -o wide

kubectl describe rs nginx-rs


*******************************************************************

Automatic Pod Reschedule 

kubectl get po -o wide --watch

kubectl get po -o wide

kubectl get nodes

*******************************************************************

Scale up pods

kubectl scale rs nginx-rs --replicas=5

kubectl get rs nginx-rs -o wide

kubectl get po -o wide


*******************************************************************

Scale down pods

kubectl scale rs nginx-rs --replicas=3

kubectl get rs nginx-rs -o wide

kubectl get po -o wide

*******************************************************************

Cleanup

kubectl delete -f nginx-rs.yaml

kubectl get rs

kubectl get po -l app=nginx-app

*******************************************************************


0 on: "Setup Kubernets Cluster in Ubuntu"