Kubernetes
Introduction
This cheat sheet provides a quick reference for some common Kubernetes commands and concepts. Kubernetes is an open-source container orchestration platform for automating the deployment, scaling, and management of containerized applications.
Installation
To use Kubernetes, you need to set up a Kubernetes cluster. Installation methods vary depending on your environment. Refer to the official Kubernetes documentation for installation instructions.
Kubernetes Concepts
Pods
Create a Pod from a YAML file:
kubectl create -f pod.yamlList all Pods in a namespace:
kubectl get podsDescribe a Pod:
kubectl describe pod pod_nameDelete a Pod:
kubectl delete pod pod_name
Deployments
Create a Deployment from a YAML file:
kubectl create -f deployment.yamlList all Deployments in a namespace:
kubectl get deploymentsScale a Deployment:
kubectl scale deployment deployment_name --replicas=3Rollback a Deployment:
kubectl rollout undo deployment/deployment_name
Services
Create a Service from a YAML file:
kubectl create -f service.yamlList all Services in a namespace:
kubectl get servicesExpose a Deployment as a Service:
kubectl expose deployment deployment_name --port=80 --type=LoadBalancerDelete a Service:
kubectl delete service service_name
ConfigMaps and Secrets
Create a ConfigMap from a file:
kubectl create configmap config_name --from-file=file_pathCreate a Secret from a file:
kubectl create secret generic secret_name --from-file=file_path
Namespaces
Create a Namespace:
kubectl create namespace namespace_nameList all Namespaces:
kubectl get namespaces
Contexts
List all available contexts:
kubectl config get-contextsSwitch to a different context:
kubectl config use-context context_name
Logs and Debugging
View Pod logs:
kubectl logs pod_nameExecute a command in a running container:
kubectl exec -it pod_name -- command
Helm (Kubernetes Package Manager)
Install a Helm chart:
helm install my-release stable/chart_nameUpgrade a Helm release:
helm upgrade my-release stable/chart_nameList Helm releases:
helm list
Conclusion
This cheat sheet covers some basic Kubernetes commands and concepts. Kubernetes offers a wide range of features and functionality; refer to the Kubernetes documentation for more in-depth information and advanced usage.