abbas baman
3 min readMar 1, 2021

--

List of kubectl Commands

Listing Resources

kubectl get namespaces
kubectl get pods
kubectl get pods -o wide
kubectl get pods --field-selector=spec.nodeName=[server-name]
kubectl get replicationcontroller [replication-controller-name]
kubectl get replicationcontroller,services
kubectl get daemonset

Creating a Resource

kubectl create namespace [namespace-name]
kubectl create –f [filename]

Applying and Updating a Resource

kubectl apply -f [service-name].yaml
kubectl apply -f [controller-name].yaml
kubectl apply -f [directory-name]
kubectl edit svc/[service-name]
KUBE_EDITOR=”[editor-name]” kubectl edit svc/[service-name]

Displaying the State of Resources

kubectl describe nodes [node-name]
kubectl describe pods [pod-name]
Kubectl describe –f pod.json
kubectl describe pods [replication-controller-name]
kubectl describe pods

Deleting Resources

kubectl delete -f pod.yaml
kubectl delete pods,services -l [label-key]=[label-value]
kubectl delete pods --all

Executing a Command

kubectl exec [pod-name] -- [command]
kubectl exec [pod-name] -c [container-name] -- [command]
kubectl exec -ti [pod-name] -- /bin/bash

Modifying kubeconfig Files

kubectl config current-context
kubectl config set-cluster [cluster-name] --server=[server-name]
kubectl config unset [property-name]

Printing Container Logs

kubectl logs [pod-name]
kubectl logs -f [pod-name]

Short Names for Resource Types

kubectl create namespace [namespace-name]
kubectl create ns [namespace-name]

--

--

abbas baman

DevOps Engineer in Cerence, Pune