Wednesday, December 16, 2020

Kubernetes - LAB - Resource Requirements and Limits, Daemonset, Static PODS

 Kubernetes - LAB

OOMkill - outof memory killed

LAB - Resource Requirements and Limits, Daemonset, Static PODS

1. A pod named 'rabbit' is deployed. Identify the CPU requirements set on the Pod
in the current(default) namespace

-> Run the command 'kubectl describe pod rabbit' and inspect requests.
under Requests, there is 1.

2. Delete the 'rabbit' Pod.
Once deleted, wait for the pod to fully terminate.
-> Run the command 'kubectl delete pod rabbit'.

3. Inspect the pod elephant and identify the status.

OOM killed

4. The status 'OOMKilled' indicates that the pod ran out of memory. Identify the memory limit set on the POD.
Under Request, mem is set to 5Mi

5. The elephant runs a process that consume 15Mi of memory. Increase the limit of the elephant pod to 20Mi.
Delete and recreate the pod if required. Do not modify anything other than the required fields.

    Pod Name: elephant
    Image Name: polinux/stress
    Memory Limit: 20Mi

# kc edit pod elephant

change the value to 20m on lilit section and save it. It will same a temp file as /tmp/kuber....

once you exit with error, delete the pod and recreate it.
wq!
# kc delete pod elephant
# kc create -f /tmp/kuber.....
# kc get pod
you will see running state.


6. Delete the 'elephant' Pod.
Once deleted, wait for the pod to fully terminate.
-> Run the command 'kubectl delete pod elephant'.


Daemon-set - LAB
------------------
1. How many DaemonSets are created in the cluster in all namespaces?
Check all namespaces
-> Run the command kubectl get daemonsets --all-namespaces

# kc get daemonset
# kc get daemonsets --all-namespaces
6 of them available
# kc get ds --all-namespaces

2. Which namespace are the DaemonSets created in?

The above command show, its kube-system

3. Which of the below is a DaemonSet?
-> Run the command kubectl get all --all-namespaces and identify the types

# kc get all --all-namespaces | more
weave-net

4. On how many nodes are the pods scheduled by the DaemonSet kube-proxy

-> Run the command kubectl describe daemonset kube-proxy --namespace=kube-system
# kc describe daemonset kube-proxy --namespace=kube-system | more

no of nodes scheduled : 2

or

Daemonsets are created on all nodes
# kc get nodes
# kc -n kube-system  get pods | proxy

we have two pods
# kc -n kube-system  get pods -o wide | proxy

You can see the nodes schedules..

5. What is the image used by the POD deployed by the kube-flannel-ds-amd64 DaemonSet?

# kc -n kue-system describe ds weave-net | grep -i image
you see 2 image output

6. Deploy a DaemonSet for FluentD Logging.
Use the given specifications.

    Name: elasticsearch
    Namespace: kube-system
    Image: k8s.gcr.io/fluentd-elasticsearch:1.20

Look for kubernetes documentation
# kc create deployment elasticsearch --image=k8s.gcr.io/fluentd-elasticsearch:1:20 --dry-run -o yaml > elastic-search.yaml
# vi elastic-search.yaml
chane from deployment to DaemoSset

go to metadata section and add a new entry for
namespace: kube-system

delete the replicas field
also delete strategy since daemonset does not use strategy

delete any extra fields not required.

# kc apply -f elastic-.yaml
# kc -n kube-system get ds elasticsearch


Static PODS - check kubelet.service file to see the config or definition file location
/etc/kubernetes/manifests

-----------------
# docker ps

1. How many static pods exist in this cluster in all namespaces?
-> Run the command kubectl get pods --all-namespaces and look for those with -controlplane appended in the name

# kc get all --all-namespaces

for static node look for master node name or other node name - suffix

There are 4 controlplances

or
# kc get pods --all-namespaces
# kc get pods -all-namespaces | grep "\-master"

2. Which of the below components is NOT deployed as a static pod?
kubeproxy

3. On what nodes are the static pods created?
-> Run the kubectl get pods --all-namespaces -o wide

control plane

4. What is the path of the directory holding the static pod definition files?

# ps -ef | grep kiubelet

look for --config
/var/lib/kubelet/config/yaml
and search for static
# grep -i statilc /var/lib/kubelet/config/yaml

you see /etc/kubernetes/manifests

5. How many pod definition files are present in the manifests folder?
-> ount the number of files under /etc/kubernetes/manifests

6. What is the docker image used to deploy the kube-api server as a static pod?
-> Check the image defined in the /etc/kubernetes/manifests/kube-apiserver.yaml manifest file.
# grep -i image /kube-apiserver.yaml

7. Create a static pod named static-busybox that uses the busybox image and the command sleep 1000

    Name: static-busybox
    Image: busybox


# kc run static-busubx --image=busybox --command sleep 1000 --restart+never --dry-run  -o yaml>static-busybox.yaml
# kc get pods




8. Edit the image on the static pod to use busybox:1.28.4

    Name: static-busybox
    Image: busybox:1.28.4
# cat statuc.busybox.yaml
change the image version to
image: busybox:1.28.4

kc get pods

9. kc get pods
check the suffix

look for the config file

# kc get pods
# kc get node node01 -o wide

# ssh node01
it failed because it is not added to host entry or dns

copy the internal-ip form kc get node node01 -o wide output

# ssh IP-address

you can login

# ps -ef | grep kubelet | grep "\--config"

check the --config path
# grep -i static /var/lib/kubelet/config

Remove the pod definition file...
# rm -rf greenbox.yaml
logout

go to master node and run
# kc get nodes
# kc get pods

10. We just created a new static pod named static-greenbox. Find it and delete it.

    Static pod deleted


Remove the pod definition file...
# rm -rf greenbox.yaml
logout

go to master node and run
# kc get nodes
# kc get pods



Multiple Schedulers
--------------------------

1. What is the name of the POD that deploys the default kubernetes scheduler in this environment?
-> Run the command 'kubectl get pods --namespace=kube-system'
# kc -n kube-system get pods

we see name of the scheduler is kube-scheduler-master

2. What is the image used to deploy the kubernetes scheduler?
Inspect the kubernetes scheduler pod and identify the image
-> Run the command 'kubectl describe pod kube-scheduler-controlplane --namespace=kube-system'

# kc -n kube-system describe pod kube-scheduler-controlplane  | grpe -i image

we see two images
the version is 1:19.0

3. Deploy an additional scheduler to the cluster following the given specification.
Use the manifest file used by kubeadm tool. Use a different port than the one used by the current one.

    Namespace: kube-system
    Name: my-scheduler
    Status: Running
    Custom Scheduler Name

-> Use the file at /etc/kubernetes/manifests/kube-scheduler.yaml to create your own scheduler.

# cd /etc/kubernetes/manifests
# cp kube-scheduler.yaml /root/my-scheduler.yaml

google for multiple scheduler or @kubernetes doc page, search for multiple schedulers

go to the example section

look under command section
copy leader
and scheduler sections and change the value to

--leader-elect=false
--scheduler-name=my-scheduler

go to metadata section and change the name to
name: my-scheduler

go to spec section and go down and change the name of container

name: my-scheduler

once modified, run the command

# kc create -f my-scheduler.yaml
# kc -n kube-system get pods

review the output
my-scheduler is created..

4. A POD definition file is given. Use it to create a POD with the new custom scheduler.
File is located at /root/nginx-pod.yaml

    Name: nginx
    Uses custom scheduler
    Status: Running


create a new schection under spec section

spec:
  schedulerName:my-scheduler

save the file and run,
# kc create -f my-scheduler.yaml

# kc -n kube-system get pods
# kc describe pod nginx



Kube-scheduler


No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...