Kubectl deployment is the fastest way to push workloads to a Kubernetes cluster. It is direct, controlled, and scriptable. With a single command, you define the desired state of your application and let Kubernetes match reality to that state.
What is Kubectl Deployment
Kubectl is the CLI for Kubernetes. The kubectl apply and kubectl create commands handle deployments. A Deployment resource manages ReplicaSets and pods. It ensures your app runs with the exact number of instances, updated with zero downtime, and rolled back if something fails.
Create a Deployment
Start with a YAML manifest. This file describes:
- apiVersion:
apps/v1 - kind:
Deployment - metadata: name, labels
- spec: replicas, selector, pod template
Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: myimage:latest
ports:
- containerPort: 80
Run:
kubectl apply -f deployment.yaml
Update a Deployment
Change the image version in your manifest. Apply again. Kubernetes rolls out the new pods while keeping the old ones running until the new version is ready.