kubectl commands
This page gives an overview of the kubectl commands I mostly use
Listing Resources
# Show all namespaces
kubectl get namespaces
# Show all pods
kuebctl get pods
# Show a list of all pods, containing information such as node name:
kubectl get pods -o wide
Creating a Resource
# Create a new namespace
kubectl create namespace [namespace-name]
Applying and Updating a Resource
# Create a new service with the definition contained in a [service-name].yaml file:
kubectl apply -f [service-name].yaml
Displaying the State of Resources
# View details about a particular node:
kubectl describe nodes [node-name]
# View details about a particular pod:
kubectl describe pods [pod-name]
#Show details about all pods:
kubectl describe pods
Deleting Resources
# Remove a pod with the name [pod-name]
kubectl delete pods [pod-name]
# Remove deployment with the name [deployment-name]
kubectl delete deployment [deployment-name]
Modifying kubeconfig
# Display the current context:
kubectl config current-context
# Set a cluster entry in kubeconfig:
kubectl config set-cluster [cluster-name] --server=[server-name]
# Unset an entry in kubeconfig:
kubectl config unset [property-name]
Launch a shell within a pod
kubectl exec --stdin --tty <name_of_POD> -- /bin/bash