Kubernetes has become the go-to container orchestration platform for modern application deployment. However, navigating the world of Kubernetes commands and concepts can be challenging. In this Kubernetes cheatsheet, we will provide you with a clear and concise guide, complete with definitions and practical examples, to help you master Kubernetes like a pro.
What is Kubernetes?
Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It provides a powerful framework for managing containers in a highly available and scalable manner.
Basic Kubernetes Commands
Here are some fundamental kubectl
(Kubernetes command-line tool) commands you should know:
kubectl get
View resources in your cluster.
kubectl get pods
kubectl create
Create a resource from a file or stdin.
kubectl create -f my-pod.yaml
kubectl delete
Delete resources by file, name, label, or selector.
kubectl delete pod my-pod
kubectl apply
Apply changes to resources.
kubectl apply -f my-pod.yaml
Managing Kubernetes Resources
Kubernetes resources are crucial components of your applications. Here’s how to manage them:
Pods
Create and manage Pods to run your containers.
apiVersion: v1
kind: Pod
metadata:
name: my-pod ...
Services
Expose your Pods as network services.
apiVersion: v1
kind: Service
metadata:
name: my-service ...
Deployments
Manage application deployments for high availability.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment ...
ConfigMaps and Secrets
Store configuration data and sensitive information.
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config ...
Scaling and Updating Deployments
Efficiently scale and update your applications:
Scaling Pods
Scale a Deployment to a specific number of replicas.
kubectl scale deployment my-deployment --replicas=3
Updating Deployments
Roll out updates to your application.
kubectl set image deployment/my-deployment my-container=new-image:tag
Working with Kubernetes YAML Files
YAML files are at the heart of Kubernetes configuration:
Creating Resources
Create resources from YAML files.
kubectl create -f my-resource.yaml
Applying Configuration
Apply changes to resources.
kubectl apply -f my-resource.yaml
Advanced Kubernetes Operations
Explore advanced Kubernetes features:
Managing Persistent Volumes
Ensure data persistence in Pods.
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv ...
Network Policies
Control network traffic to and from your Pods.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: my-policy ...
RBAC (Role-Based Access Control)
Define access permissions for resources.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: my-role ...
Conclusion
This Kubernetes cheatsheet is your essential companion for mastering Kubernetes operations. Whether you’re a beginner learning the basics or an experienced user exploring advanced features like RBAC and network policies, this guide will help you navigate the Kubernetes ecosystem with ease.