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

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://

# Or via curl
curl http://
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



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *