Here is my Kubernetes kubectl cheat sheet that I use everyday as a reference. There are some many commands that form part of the toolkit for managing a Kubernetes cluster on a day to day basis. Enjoy!!
list all pods in nodes across names spaces.
kubectl get pod --all-namespaces
Describe a node to see its configuration
## get a list of nodes first
kubectl get nodes
### describe the required node
kubectl describe nodes <node name>
Describing a pod will showing its configuration and it events.
## get the pods name
kubectl get pod --all-namespaces
## describe pod to see its configuration
kubectl describe pod <pod name>
Use exec to connect to a pod and execute command locally on the pod. This can be usefule for troubleshooting the pod itself.
## get the pods name
kubectl get pod --all-namespaces
## this example is for exec'ing to a ribbitmq pod
kubectl exec-it my-rabbitmq-0 -- /bin/bash
Cheat sheet: Context and Configuration
Set which Kubernetes cluster kubectl
communicates with and modifies configuration information.
kubectl config view # Show Merged kubeconfig settings.
# use multiple kubeconfig files at the same time and view merged config
KUBECONFIG=~/.kube/config:~/.kube/kubconfig2
kubectl config view
# get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
kubectl config view -o jsonpath='{.users[].name}' # display the first user
kubectl config view -o jsonpath='{.users[*].name}' # get a list of users
kubectl config get-contexts # display list of contexts
kubectl config current-context # display the current-context
kubectl config use-context my-cluster-name # set the default context to my-cluster-name
# add a new cluster to your kubeconf that supports basic auth
kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword
# permanently save the namespace for all subsequent kubectl commands in that context.
kubectl config set-context --current --namespace=ggckad-s2
# set a context utilizing a specific username and namespace.
kubectl config set-context gce --user=cluster-admin --namespace=foo \
&& kubectl config use-context gce
kubectl config unset users.foo # delete user foo
What is Kuberbetes
Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate deploying, scaling, and operating application containers. It was originally developed by Google, but now it’s maintained by the Cloud Native Computing Foundation (CNCF).
Here are some key features of Kubernetes:
- Container Orchestration: Kubernetes manages clusters of containers, handling the logistics of container deployment, scaling, and operation.
- Automatic Scaling: Kubernetes can automatically scale your applications up or down based on demand, ensuring optimal resource utilization.
- Self-Healing: If a container fails, Kubernetes can restart it, replace it, and reschedule it on another node.
- Service Discovery and Load Balancing: Kubernetes can expose a container using the DNS name or its own IP address and balance the load between containers.
- Storage Orchestration: Kubernetes allows you to mount storage systems automatically, whether it’s local storage, public cloud providers, or network storage.
- Configuration Management: Kubernetes can manage application configurations and secrets, and handle updates without causing downtime.
Kubernetes is widely used for managing microservices architectures, facilitating a DevOps culture, and improving the resilience and efficiency of applications in production.
In addition to this great kubectl cheat sheet we also have a number of other articles that are useful reference for Kubernetes management.