Kubernetes – Deployments

A Deployment provides declarative updates for Pods and ReplicaSets.

Deployments | Kubernetes

Creating a deployment

(Example) A simple deployment of 2 nginx pods

  • Create a YAML file
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: my-nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-nginx
    template:
      metadata:
        labels:
          app: my-nginx
      spec:
        containers:
        - name: my-nginx
          image: nginx:latest
          ports:
          - containerPort: 80
  • Create/Apply
kubectl create -f <yaml-file>

# Use --save-config when you want to use 'kubectl apply' in the future
kubectl create -f <yaml-file> --save-config

kubectl apply -f <yaml-file>

Checking deployments

kubectl get deployments

kubectl describe deployment <deployment-name>

Checking replica sets

kubectl get replicasets

kubectl describe replicaset <replicaset-name>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s