Working With Kubernetes

Kubernetes is an open-source platform that helps you deploy, scale, and manage resources across multiple containers. A Kubernetes cluster would generally have a master node and several worker-nodes or Minions. The worker-nodes are then managed from the master node, thus ensuring that the cluster is managed from a central point.

Master Node

  • API Server  – It provides kubernetes API using Jason / Yaml over http, states of API objects are stored in etcd
  • Scheduler  – It is a program on master node which performs the scheduling tasks like launching containers in worker nodes based on resource availability
  • Controller Manager – Main Job of Controller manager is to monitor replication controllers and create pods to maintain desired state.
  • etcd – It is a Key value pair data base. It stores configuration data of cluster and cluster state.
  • Kubectl utility – It is a command line utility which connects to API Server on port 6443. It is used by administrators to create pods, services etc

Worker Node

  • Kubelet – It is an agent which runs on every worker node, it connects to docker  and takes care of creating, starting, deleting containers.
  • Kube-Proxy – It routes the traffic to appropriate containers based on ip address and port number of the incoming request. In other words we can say it is used for port translation.
  • Pod – Pod can be defined as a multi-tier or group of containers that are deployed on a single worker node or docker host.

In my setup we have 3 worker nodes (minion) and 1 master node. I have mentioned the components which will be installed on Master node and and Worker node.

I have created 4 VM’s on ESXI 5.5 version running Centos 7.4 on HP DL380 ,Gen 8 , Server. Each VM has 50 GB drive, 6GB Ram.

Let me give some initial tips so that it can save your troubleshooting time post installation.

Ensure all nodes are time synced , you need to configure NTP service Master and worker nodes ,this is very vital else worker node will fail to register with Master node.

Ensure that iptables is set to 1 in the sysctl.conf. Node may not register without this setting.

vi /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
sysctl -p

1) Preparing Hostname,Firewall,Selinux and the Repos

Prepare all the hosts, Master and work er nodes as mentioned below.

Setting UP Repository

Install Kubeadm and Docker

I installed kubedm unknowingly



Disable Swap Off

 initialize and setup kubernetes master

Now that we have initialized Kubernetes successfully, lets us allow your user to start using the cluster.

To start using your cluster, you need to run the following 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

You should now deploy a pod network to the cluster.
Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.0.32:6443 –token kxnfd3.a0g83o8jjioudpbc \
–discovery-token-ca-cert-hash sha256:5ed5884c8aefe300885d77ba761e0f3dee417d295f92b70d0616c9be32652273

For Sudo user and root

Verify kubectl command is activated.


To make the cluster status ready and kube-dns status running, deploy the pod network so that containers of different host communicated each other.  POD network is the overlay network between the worker nodes.

Run the below command to deploy network.

Lets verify the status now

Join the Worker Node to the Kubernetes Cluster

# kubectl get nodes
NAME STATUS ROLES AGE VERSION
masternode.ranjeetbadhe.com Ready master 42h v1.18.2
workernode1.ranjeetbadhe.com Ready 41h v1.18.2
workernode2.ranjeetbadhe.com Ready 41h v1.18.2
workernode3.ranjeetbadhe.com Ready 41h v1.18.2

Deploying Applications

Let us deploy 2 applications now

  1. Nginx

2 Quagga router

Let us do deployment of NGINX using the NGINX image.




#kubectl describe deployment nginx
Name: nginx
Namespace: default
CreationTimestamp: Tue, 05 May 2020 12:41:19 +0530
Labels: app=nginx
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=nginx
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx
Port:
Host Port:
Environment:
Mounts:
Volumes:
Conditions:
Type Status Reason
—- —— ——
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets:
NewReplicaSet: nginx-f89759699 (1/1 replicas created)
Events:
Type Reason Age From Message
—- —— —- —- ——-
Normal ScalingReplicaSet 2m20s deployment-controller Scaled up replica set nginx-f89759699 to 1

Lets us access now our page from NGINX

On the Chrome Browser

So we have now successfully installed the NGINX on our Kubernettes!!!!

# kubectl config view
apiVersion: v1
clusters:

  • cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://192.168.0.32:6443
    name: kubernetes
    contexts:
  • context:
    cluster: kubernetes
    user: kubernetes-admin
    name: kubernetes-admin@kubernetes
    current-context: kubernetes-admin@kubernetes
    kind: Config
    preferences: {}
    users:
  • name: kubernetes-admin
    user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED

# kubectl cluster-info
Kubernetes master is running at https://192.168.0.32:6443
KubeDNS is running at https://192.168.0.32:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

#kubectl describe pod my-nginx

Name: my-nginx
Namespace: default
Priority: 0
Node: workernode1.ranjeetbadhe.com/192.168.0.33
Start Time: Sun, 03 May 2020 19:17:32 +0530
Labels: run=my-nginx
Annotations:
Status: Running
IP: 10.36.0.1
IPs:
IP: 10.36.0.1
Containers:
my-nginx:
Container ID: docker://55f1ef5ea958664196bf2a64d1653a281fa8beeae96d692359ee7d846ea29f0f
Image: nginx
Image ID: docker-pullable://docker.io/nginx@sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 05 May 2020 07:10:51 +0530
Last State: Terminated
Reason: Completed
Exit Code: 0
Started: Sun, 03 May 2020 19:17:46 +0530
Finished: Sun, 03 May 2020 19:19:08 +0530
Ready: True
Restart Count: 1
Environment:
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-72dlf (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-72dlf:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-72dlf
Optional: false
QoS Class: BestEffort
Node-Selectors:
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
—- —— —- —- ——-
Normal Scheduled 41h default-scheduler Successfully assigned default/my-nginx to workernode1.ranjeetbadhe.com
Normal Pulling 41h kubelet, workernode1.ranjeetbadhe.com Pulling image “nginx”
Normal Pulled 41h kubelet, workernode1.ranjeetbadhe.com Successfully pulled image “nginx”
Normal Created 41h kubelet, workernode1.ranjeetbadhe.com Created container my-nginx
Normal Started 41h kubelet, workernode1.ranjeetbadhe.com Started container my-nginx
Normal SandboxChanged 6h (x5 over 6h) kubelet, workernode1.ranjeetbadhe.com Pod sandbox changed, it will be killed and re-created.
Normal Pulling 6h kubelet, workernode1.ranjeetbadhe.com Pulling image “nginx”
Normal Pulled 6h kubelet, workernode1.ranjeetbadhe.com Successfully pulled image “nginx”
Normal Created 6h kubelet, workernode1.ranjeetbadhe.com Created container my-nginx
Normal Started 6h kubelet, workernode1.ranjeetbadhe.com Started container my-nginx

Leave a Reply

Your email address will not be published. Required fields are marked *