kubernetes commands for beginners

Pinterest LinkedIn Tumblr

Kubernetes Components

The Kubernetes has worker node and control plane. The control plane manages the nodes and the Pods in the cluster. The worker node host the Pods and other client components. kube-apiserver is server side component and expose the API. It also contains etcd, kube scheduler, kube controller manager.

kubelet is client side component and connect through API using command line.


Kubectl is a command line tool for controlling Kubernetes Server. Kubernet uses the configuration from the default location $HOME/.kube/config file. The user can pass though the KUBECONFIG environment variable or by setting the –kubeconfig flag.

It contains clusters ( the list of cluster details), context and user details. The current-context uses to execute the command by default cluster.

current-context: minikube

Kubectl client side tool supports Linux, macOS and Windows Operating system. The installation guide explains more https://kubernetes.io/docs/tasks/tools/install-kubectl/. The user can set in path and use it.


kubectl config get-contextsDisplay the list of context available
kubectl config current-contextDisplay the current context
kubectl config use-context my-context-nameset the default context to my-context-name. The user can change in config file or use commands to update the current context.
kubectl get pods -w -n devGet all the pods from namespace dev
kubectl get replicasets -w -n devGet all replica set from namespace dev
kubectl get deployments -w -n devGet all the deployments from namespace dev
kubectl get events -w -n devget all the events from namespace dev
kubectl delete deploy/<dep-app-name>delete the deployment name <dep-app-name>
kubectl get all -n dev | findstr <app-name>get all kubernet objects (pod, replica set, service and deployment) from namespace dev and filter using findstr/grep command
kubectl exec -it –namespace=dev <application-pod-name> — bashget into the pod which deployed on dev namespace bash command
kubectl describe pod/<app-pod-name> -n devdescribe the pod <app-pod-name> from dev namespace. The user can check the app status
kubectl rollout undo deployment/<deployment -name> –to-revision=2undo the deployment to given version
kubectl logs <pod-app-name> -n prodfind the application log from pod under prod namespace. The pod should up and running state for checking the logs.
kubectl rollout history deployment/<deployment-name> -n devlist the versions available to undo from namespace dev

Copy files from/to kubernetes

kubectl cp <local file with path> dev/<pod-application-name>:<pod-remote-path>

Copy <local file with path> local file to <pod-application-name> pod <pod-remote-path> in a remote pod dev namespace

kubectl cp dev/<pod-application-name>:<pod-remote-path-file> <local path>

Copy pod <pod-application-name> file <pod-remote-path-file> with namespace dev to local path<local path>

Kubernetes Objects

The following command shows all the kubernetes objects. All the kubernetes components controlled by object type.

kubectl api-resources



Write A Comment