DEV Community

Cover image for Part-87: ๐Ÿš€ Kubernetes Deployments with Imperative Commands in GCP (Google Kubernetes Engine)
Latchu@DevOps
Latchu@DevOps

Posted on

Part-87: ๐Ÿš€ Kubernetes Deployments with Imperative Commands in GCP (Google Kubernetes Engine)

In this guide, weโ€™ll explore Kubernetes Deployments using the imperative way on Google Kubernetes Engine (GKE).
Weโ€™ll cover creating, scaling, updating, exposing, and managing deployments step by step.


๐Ÿ“Œ Topics Covered

  • Create Deployment
  • Scale the Deployment
  • Expose Deployment as a Service
  • Update Deployment
  • Rollback Deployment
  • Rolling Restarts

๐Ÿ”น Step 01: Introduction to Deployments

What is a Deployment?

d1

A Deployment in Kubernetes is a higher-level abstraction that manages Pods and ReplicaSets.

It allows you to define:

  • The container image to run
  • The number of replicas (Pods)
  • Update strategies (rolling updates)
  • Rollback in case of failures

d2


What can we do with a Deployment?

Using a deployment, you can:

  • Roll out new application versions
  • Scale the number of Pods up/down
  • Ensure self-healing (Pods restart if they fail)
  • Perform rolling updates & rollbacks
  • Expose applications internally or externally

๐Ÿ”น Step 02: Create a Deployment

Letโ€™s create a simple Nginx deployment with 3 replicas.

d3

# Create Deployment
kubectl create deployment my-first-deployment \
  --image=ghcr.io/stacksimplify/kubenginx:1.0.0 \
  --replicas=3

# Verify Deployment
kubectl get deployments
kubectl get deploy 

# Describe Deployment
kubectl describe deployment my-first-deployment

# Verify ReplicaSet
kubectl get rs

# Verify Pods
kubectl get po
Enter fullscreen mode Exit fullscreen mode

โœ… At this point, we have 3 Pods running managed by a Deployment & ReplicaSet.

d4


๐Ÿ”น Rollout History with Change-Cause

Kubernetes allows tracking deployment revisions and rolling back if needed.

# Check Rollout History
kubectl rollout history deployment/my-first-deployment

# Add change-cause annotation
kubectl annotate deployment/my-first-deployment \
  kubernetes.io/change-cause="Deployment CREATE - App Version 1.0.0"

# Verify rollout history
kubectl rollout history deployment/my-first-deployment
Enter fullscreen mode Exit fullscreen mode

d5


๐Ÿ”น Step 03: Scaling a Deployment

We can easily scale the number of Pods up or down.

# Scale Up to 6 replicas
kubectl scale --replicas=6 deployment/my-first-deployment 

# Verify
kubectl get deploy
kubectl get rs
kubectl get po

# Scale Down to 3 replicas
kubectl scale --replicas=3 deployment/my-first-deployment
kubectl get deploy
Enter fullscreen mode Exit fullscreen mode

d6


๐Ÿ”น Step 04: Expose Deployment as a Service

By default, Pods are accessible only inside the cluster.
Weโ€™ll expose the Deployment using a LoadBalancer service so itโ€™s accessible externally.

# Expose Deployment
kubectl expose deployment my-first-deployment \
  --type=LoadBalancer \
  --port=80 \
  --target-port=80 \
  --name=my-first-deployment-service

# Get Service Info
kubectl get svc
Enter fullscreen mode Exit fullscreen mode

d7

๐Ÿ”‘ Note: On GCP, a public LoadBalancer IP will be created.


๐Ÿ”น Step 05: Access the Application

Once the LoadBalancer is provisioned, youโ€™ll see an External IP.

# Access Application in Browser
http://<External-IP>

# Or via curl
curl http://<External-IP>
Enter fullscreen mode Exit fullscreen mode

d8


โœ… Recap

With imperative commands in GKE, we:

  • Created a Deployment
  • Verified ReplicaSet & Pods
  • Scaled Pods up & down
  • Exposed app via LoadBalancer
  • Tracked rollout history

๐ŸŒŸ Thanks for reading! If this post added value, a like โค๏ธ, follow, or share would encourage me to keep creating more content.


โ€” Latchu | Senior DevOps & Cloud Engineer

โ˜๏ธ AWS | GCP | โ˜ธ๏ธ Kubernetes | ๐Ÿ” Security | โšก Automation
๐Ÿ“Œ Sharing hands-on guides, best practices & real-world cloud solutions

Top comments (0)