Debug School


Posted on

Working With Namespace,POD,ReplicationController and Deployment

NameSpace : (its kind of resources) (logical seperatin of cluster

  1. There are situation like each k8s cluster used by multiple teams. If one team container consuming more memory than it affects the other team also and also every team member can access all the team pods which is not correct

On that time we will use the namespace one where each team can create there own process and allocate there resources (like it cant consume more than some amount of CPU and memory)

To create a NameSpace :
kubectl create ns ex kubectl create ns nagendra (which creates the namespace call nagendra)

To describe the namespace :
kubectl describe ns nagendra

To edit the namespace
kubectl edit ns nagendra

To delete the namespace
kubectl delete ns nagendra

TO list all the namespace
kubectl get ns

Note : For all the resources we use the CRUD operations are common


POD is a logical unit which cant be created. We can instantiate the POD (which create a own network space like port space)

Write pod.yaml file (Attach the content of pod.yaml once we got the access)

To create a POD :
kubectl create -f pod.yaml ( whcih creates the pod mention in the pod.yaml file here ex nagendrapod)

To describe the POD:
kubectl describe pod nagendrapod

To edit the pod
kubectl edit pod nagendrapod (Which edit directly the eecd)

To delete the pod
kubectl delete -f pod.yaml

TO list all the pod
kubectl get pod

kubectl get pods -o wide (Shows the ip address fll details of the pods)

TroubleShoot Of PODS ( Each pod contains multiple containers>

kubectl logs --- > to get the logs of the pod
kubectl attach --> Which will attach to the pod to the PID1 (like docker)
kubectl exec ls --> Execute the command internal to the POD (like docker)
kubectl exec -it /bin/bash --> Interactive mode the POD
kubectl port-forward --address pod/rajesh 8888:80 (Explaination) --address (Any address) pod/nameofthepod nodeport:containerport (Explaination of the above command) Any address can communicate with the pod ( means) if it outside guy send data to the 8888 it forwards to 80)

kubectl auth can-i ( give the persmission of user )

kubectl auth can-i create ns (If the outpput is true ) then user have the access to create NS

Replication controller : (Another resources Replication means 1 to many and controller means it watches and maintains the desired state mentioned in the .yaml)

apiVersion: v1
kind: ReplicationController
name: nagendrarc
replicas: 5
app: nginx
- name: nginx
image: scmgalaxy/nginx-devopsschoolv1

kubectl scale --replicas=1 nagendrarc ( in above once we execute it creates 5 pods that image After that we execute this command then pod value come to 1)

kubectl create -f rc.yaml
kubectl get rc
kubectl edit rc nagendrarc
kubectl get rc nagendrarc -o yaml (Which gives the yaml file )
kubectl delete rc nagendrarc

NOw replicationController is deprecated instead of that we use the resource ReplicaSet means in .yaml file we use the ReplicaSet

Same command as replication controller

Deployment (Another resource most of the time we use this one)

We can do the deployment without yaml file like below

kubectl create deployment --image=scmgalaxy/nginx-devopsschoolv1 --replicas=5

Which will create the 5pods where that image container is running

kubectl describe deploy my-dep (which will describes the deployment)

kubectl scale --replicas=2 deploy/my-dep ( which will bring back the replica 5 to 2)

kubectl rollout history dep/my-dep ( whcih will tell the version of the deployment)

Suppose there is a situation we have to upgrade to higher version then it will be easy using this

kubectl patch deployment my-dep --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"scmgalaxy/nginx-devopsschoolv2"}]' ( Patch apply the patch )
kubectl rollout status deploy/my-dep ( which will status of the rollout)

IF we want to go back to previous version of deployment (means basically previous image in PODS ) it will be easy
kubectl rollout undo deploy/my-dep --to-revision=2

Top comments (0)