Command line Utilities


Run the following commands on the master node:

ps -aux | grep kube-apiserver

ps -aux | grep kube-scheduler

ps -aux | grep kube-controller-manager

ps -aux | grep etcd


Run the following commands on the worker nodes:

ps -aux | grep kubelet

ps -aux | grep kube-proxy

ps -aux | grep docker   # If Docker is used as the container runtime

ps -aux | grep containerd  # If containerd is used as the container runtime


Kubectl commands

kubectl run nginx --image nginx

kubectl get pods


Kubernetes Service 

kubectl get service

kubectl get svc 

kubectl describe svc <service_name>


Deployment 

kubectl get deploy 

kubectl describe deploy <deployment_name>


Namespace 

kubectl get pods --namespace=kube-system

kubectl create -f pod-definition --namespace=dev

If you do not want to mention the namespace in the command line you can 

apiVersion: v1
kind : Pod

metadata:
   - name: my-app
     namespace: dev

Creating Namespace 
---

apiVersion: v1
kind : Namespace

metadata:
   - name: dev

---

kubectl create -f namespace-definition.yml

command line

kubectl create namespace dev


Switching Namespace 

kubectl config set-context $(kubectl config current-context) --namespace=dev

kubectl get pods  -- now the pods in dev namespace will be displayed.


To see all the Pods in all namespaces 

kubectl get pods --all-namespaces 


kubectl get pods --namespace=research
or
kubectl get pods -n=research


Create a Pod in finance namespace

kubectl run redis --image=redis --namespace=finance 

kubectl get pods --all-namespaces 
or
kubectl get pods -A


This will completely delete the configuration and recreate


kubectl replace --force -f nginx.yaml

or you just want to make a permanent change in the file such as changing the version.

kubectl replace -f nginx.yaml

-- If you do not want to keep typing the command again and again

kubectl get pod --watch


-- kubectl get pod --selector env=prod --no-header


taint and tolerance

kubectl taint nodes node-name key=value:taint-effect

example
kubectl taint nodes node1 app=blue:NoSchedule

taint-effect -- what will happen to the pods if they do not tolerate the taints

there are three taint effects

--NoSchedule : which means the pods will not be scheduled on the nodes.
--PreferNoSchedule: which means the system will try to avoid placing a pod on the node but that is not guaranteed 
-- NoExecute: No pods will be scheduled on the node and exisiting pod if any will be evicted if they do not tolerate the taint.

The master node in the cluster is tainted to see this

kubectl describe node kubemaster | grep Taint

removing a taint
 
kubectl taint node controlplane <taint-name->  // minus is added to the end of the line.












Comments

Popular posts from this blog

Delploy Cluster : Managed K8 & Self Managed K8

ctr | nerdctl | crictl

Deploy To Kubernetes with Jenkins GitOps GitHub Pipeline