0% 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.

Uploaded by

Ayush Naphade
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

Ayush Naphade
Copyright
© © All Rights Reserved
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
You are on page 1/ 9

# [ Kubernetes Operations ] ( CheatSheet )

1. Basic Configuration

● Set Kubeconfig: kubectl config use-context my-cluster-name


● View Current Context: kubectl config current-context
● List All Contexts: kubectl config get-contexts
● Switch Context: kubectl config set-context my-cluster-name
● View Cluster Info: kubectl cluster-info

2. Working with Namespaces

● List Namespaces: kubectl get namespaces


● Create Namespace: kubectl create namespace my-namespace
● Delete Namespace: kubectl delete namespace my-namespace
● Switch Namespace for Context: kubectl config set-context --current
--namespace=my-namespace
● Describe Namespace: kubectl describe namespace my-namespace

3. Deployments and Pods

● Create Deployment: kubectl create deployment my-deployment


--image=my-image
● List Deployments: kubectl get deployments
● Delete Deployment: kubectl delete deployment my-deployment
● Scale Deployment: kubectl scale deployment my-deployment
--replicas=3
● List Pods: kubectl get pods
● Describe Pod: kubectl describe pod my-pod
● Delete Pod: kubectl delete pod my-pod
● Edit Deployment: kubectl edit deployment my-deployment
● Get Deployment YAML: kubectl get deployment my-deployment -o yaml
● Rollout Status of Deployment: kubectl rollout status
deployment/my-deployment

By: Waleed Mousa


4. Services and Networking

● Create Service: kubectl expose deployment my-deployment


--type=LoadBalancer --name=my-service
● Get Services: kubectl get services
● Delete Service: kubectl delete service my-service
● Describe Service: kubectl describe service my-service
● Port Forward to Pod: kubectl port-forward pod/my-pod 8080:80
● Apply Network Policy: kubectl apply -f network-policy.yaml
● List Network Policies: kubectl get networkpolicy

5. Configuration and Secrets

● Create ConfigMap: kubectl create configmap my-config


--from-literal=key1=value1 --from-literal=key2=value2
● Get ConfigMaps: kubectl get configmaps
● Delete ConfigMap: kubectl delete configmap my-config
● Create Secret: kubectl create secret generic my-secret
--from-literal=key1=value1
● Get Secrets: kubectl get secrets
● Delete Secret: kubectl delete secret my-secret

6. Ingress and Routing

● Create Ingress: kubectl apply -f ingress.yaml


● List Ingresses: kubectl get ingresses
● Delete Ingress: kubectl delete ingress my-ingress
● Describe Ingress: kubectl describe ingress my-ingress

7. Volumes and Persistent Storage

● Create Persistent Volume: kubectl apply -f persistent-volume.yaml


● Get Persistent Volumes: kubectl get pv
● Delete Persistent Volume: kubectl delete pv my-pv
● Create Persistent Volume Claim: kubectl apply -f
persistent-volume-claim.yaml
● Get Persistent Volume Claims: kubectl get pvc

By: Waleed Mousa


● Delete Persistent Volume Claim: kubectl delete pvc my-pvc

8. Jobs and CronJobs

● Create Job: kubectl create -f job.yaml


● List Jobs: kubectl get jobs
● Delete Job: kubectl delete job my-job
● Create CronJob: kubectl create -f cronjob.yaml
● List CronJobs: kubectl get cronjobs
● Delete CronJob: kubectl delete cronjob my-cronjob

9. Logs and Troubleshooting

● View Pod Logs: kubectl logs my-pod


● Stream Pod Logs: kubectl logs -f my-pod
● Exec into Pod: kubectl exec -it my-pod -- /bin/bash
● Describe for Troubleshooting: kubectl describe
pod/service/deployment my-name
● Get Events: kubectl get events
● Attach to Running Container: kubectl attach my-pod -i
● Copy Files from/to Pod: kubectl cp /tmp/foo_dir my-pod:/tmp/bar_dir
● Port Forward to Service: kubectl port-forward svc/my-service
8080:80

10. Advanced Kubectl Commands

● Apply YAML File: kubectl apply -f my-resource.yaml


● Get Resource Details in YAML: kubectl get pod my-pod -o yaml
● Explain Resources: kubectl explain pods,svc
● Autoscale Deployment: kubectl autoscale deployment my-deployment
--min=2 --max=5 --cpu-percent=80
● Rolling Update Deployment: kubectl set image
deployment/my-deployment my-container=new-image
● Rollback Deployment: kubectl rollout undo deployment/my-deployment
● Pause/Resume Rollout: kubectl rollout pause/resume
deployment/my-deployment

By: Waleed Mousa


● Record Command for Future Rollbacks: kubectl apply -f
my-deployment.yaml --record
● Get Top Node or Pod: kubectl top node/pod
● Drain Node: kubectl drain my-node
● Cordon/Uncordon Node: kubectl cordon/uncordon my-node
● Taint Node: kubectl taint nodes my-node key=value:taint-effect
● Patch Resource: kubectl patch pod my-pod -p
'{"spec":{"containers":[{"name":"my-container","image":"new-image"}
]}}'

11. Working with Custom Resources

● Create Custom Resource: kubectl apply -f custom-resource.yaml


● 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

13. Resource Quotas and Limits

● Create Resource Quota: kubectl apply -f resource-quota.yaml


● Describe Resource Quota: kubectl describe quota
● Set Limits on Namespace: kubectl apply -f limit-range.yaml

14. Role-Based Access Control (RBAC)

● Create Role: kubectl create role my-role --verb=get --verb=list


--resource=pods
● Create ClusterRole: kubectl create clusterrole my-clusterrole
--verb=get --verb=list --resource=nodes

By: Waleed Mousa


● Create RoleBinding: kubectl create rolebinding my-rolebinding
--role=my-role --user=my-user
● Create ClusterRoleBinding: kubectl create clusterrolebinding
my-clusterrolebinding --clusterrole=my-clusterrole --group=my-group

15. Using Helm (Package Manager)

● Install Helm Chart: helm install my-release


helm-chart-repo/my-chart
● List Helm Releases: helm list
● Upgrade Helm Release: helm upgrade my-release
helm-chart-repo/my-chart
● Uninstall Helm Release: helm uninstall my-release

16. Working with Helm Charts

● Create Helm Chart: helm create my-chart


● Package Helm Chart: helm package my-chart
● Lint Helm Chart: helm lint my-chart
● View Helm Chart Dependencies: helm dependency list my-chart

17. StatefulSets and DaemonSets

● Create StatefulSet: kubectl apply -f statefulset.yaml


● Get StatefulSets: kubectl get statefulsets
● Delete StatefulSet: kubectl delete statefulset my-statefulset
● Create DaemonSet: kubectl apply -f daemonset.yaml
● Get DaemonSets: kubectl get daemonsets
● Delete DaemonSet: kubectl delete daemonset my-daemonset

18. Kubernetes Dashboard

● Access Dashboard: kubectl proxy


● Create Dashboard Admin User: kubectl create -f
dashboard-adminuser.yaml

By: Waleed Mousa


19. Monitoring and Metrics

● Get Metrics for Nodes: kubectl top nodes


● 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

By: Waleed Mousa

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy