This cheat sheet provides a comprehensive overview of Kubernetes operations, including commands for configuration, managing namespaces, deployments, services, networking, and persistent storage. It also covers advanced topics such as Helm usage, role-based access control, and custom resources. Each section includes essential kubectl commands for efficient Kubernetes management.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
0 views
Kubernetes CheatSheet-1
This cheat sheet provides a comprehensive overview of Kubernetes operations, including commands for configuration, managing namespaces, deployments, services, networking, and persistent storage. It also covers advanced topics such as Helm usage, role-based access control, and custom resources. Each section includes essential kubectl commands for efficient Kubernetes management.
● Get Custom Resources: kubectl get my-custom-resource ● Delete Custom Resource: kubectl delete my-custom-resource my-resource-name
12. Labeling and Annotations
● Add Label to Pod: kubectl label pods my-pod new-label=awesome
● Remove Label from Pod: kubectl label pod my-pod new-label- ● Add Annotation: kubectl annotate pod my-pod my-annotation="12345" ● Get Pods with Specific Label: kubectl get pods -l label-name=label-value
● Get Metrics for Pods: kubectl top pods ● Accessing the Kubernetes Dashboard for Monitoring: kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/d eploy/recommended.yaml
20. Managing Persistent Volumes
● List All Persistent Volumes: kubectl get pv
● Get Detailed Info on a Specific Persistent Volume: kubectl describe pv my-pv ● Deleting a Persistent Volume: kubectl delete pv my-pv
21. Managing Persistent Volume Claims
● List All Persistent Volume Claims (PVCs): kubectl get pvc
● Get Detailed Info on a Specific PVC: kubectl describe pvc my-pvc ● Deleting a PVC: kubectl delete pvc my-pvc
22. Working with ConfigMaps
● Create a ConfigMap from a File: kubectl create configmap my-config
--from-file=path/to/config-file ● Get ConfigMaps in a Namespace: kubectl get configmaps -n my-namespace ● Describe a Specific ConfigMap: kubectl describe configmap my-config
23. Managing Secrets
● Create a Secret from a File: kubectl create secret generic
my-secret --from-file=path/to/file ● Get Secrets in a Namespace: kubectl get secrets -n my-namespace ● Describe a Specific Secret: kubectl describe secret my-secret
By: Waleed Mousa
24. Advanced Pod Management
● Run a Pod Interactively: kubectl run my-pod --image=my-image
--stdin --tty ● Execute a Command Inside a Running Pod: kubectl exec my-pod -- ls / ● Copy Files from/to a Pod: kubectl cp /local/path my-pod:/pod/path
25. Advanced Deployment Management
● Updating a Deployment's Image: kubectl set image
deployment/my-deployment my-container=my-image:v2 ● Check Rollout History of a Deployment: kubectl rollout history deployment/my-deployment ● Undo a Deployment to an Earlier Revision: kubectl rollout undo deployment/my-deployment --to-revision=2
26. Working with Network Policies
● List All Network Policies: kubectl get networkpolicies
● Describe a Specific Network Policy: kubectl describe networkpolicy my-network-policy ● Delete a Network Policy: kubectl delete networkpolicy my-network-policy
27. Using Custom Resource Definitions (CRDs)
● Create a CRD: kubectl apply -f my-crd.yaml
● List All CRDs: kubectl get crds ● Delete a CRD: kubectl delete crd my-crd
28. Handling Jobs and CronJobs
● List Jobs in a Namespace: kubectl get jobs -n my-namespace
● Get Detailed Info on a Specific Job: kubectl describe job my-job ● Deleting a Job: kubectl delete job my-job ● List CronJobs in a Namespace: kubectl get cronjobs -n my-namespace
By: Waleed Mousa
● Get Detailed Info on a Specific CronJob: kubectl describe cronjob my-cronjob
29. Advanced Service Management
● Create a LoadBalancer Service: kubectl expose deployment
my-deployment --type=LoadBalancer --name=my-service ● Create a NodePort Service: kubectl expose deployment my-deployment --type=NodePort --name=my-service ● Patch a Service: kubectl patch service my-service -p '{"spec": {"type": "NodePort"}}'
30. Advanced Ingress Management
● List All Ingress Resources: kubectl get ingress
● Get Detailed Info on a Specific Ingress: kubectl describe ingress my-ingress ● Edit an Ingress Resource: kubectl edit ingress my-ingress
31. Using Labels and Selectors
● Label a Resource: kubectl label pods my-pod my-label=my-value
● Delete Resources by Label: kubectl delete pods -l my-label=my-value ● Get Resources with Specific Labels: kubectl get pods -l my-label=my-value
32. Managing DaemonSets
● List All DaemonSets: kubectl get daemonsets
● Get Detailed Info on a Specific DaemonSet: kubectl describe daemonset my-daemonset ● Delete a DaemonSet: kubectl delete daemonset my-daemonset
33. Managing StatefulSets
● List All StatefulSets: kubectl get statefulsets
● Get Detailed Info on a Specific StatefulSet: kubectl describe statefulset my-statefulset ● Delete a StatefulSet: kubectl delete statefulset my-statefulset By: Waleed Mousa 34. Utilizing Helm for Kubernetes
● List Installed Helm Charts: helm list --all-namespaces
● Install a Helm Chart: helm install my-release my-chart ● Upgrade an Installed Helm Chart: helm upgrade my-release my-chart