Deploying Scalable HTTPD Applications on Kubernetes using ReplicaSet and LoadBalancer with Apple & Chinnu

๐Ÿงฑ Deploying Scalable HTTPD Applications Using ReplicaSet and LoadBalancer in Kubernetes

๐Ÿ‘‹ Introduction

In this blog, we explore how to deploy and expose a scalable HTTPD application using Kubernetes ReplicaSet with multiple label selectors. We'll walk through:

  • Creating a ReplicaSet with matchExpressions

  • Deploying an HTTPD-based container

  • Exposing it via a LoadBalancer service

  • Using custom labels like apple and chinnu


๐Ÿ“ File Structure

bashCopyEdit[root@ip-172-31-89-85 ReplicaSet]# tree
.
โ”œโ”€โ”€ loadbalancer-rc.yml
โ””โ”€โ”€ rs.yml

0 directories, 2 files

๐Ÿ“ฆ rs.yml (ReplicaSet Manifest)

yamlCopyEdit---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myrs-1
spec:
  replicas: 5
  selector:
    matchExpressions:
      - key: microsoft
        operator: In
        values:
          - apple
          - palukuri
          - bhashwanth
      - key: google
        operator: In
        values:
          - chinnu
  template:
    metadata:
      labels:
        microsoft: apple
        google: chinnu
    spec:
      containers:
        - name: container-rs-1
          image: httpd
          ports:
            - containerPort: 80

๐ŸŒ loadbalancer-rc.yml (Service Manifest)

yamlCopyEdit---
apiVersion: v1
kind: Service
metadata:
  name: loadbalancer-service-for-rs
spec:
  type: LoadBalancer
  selector:
    microsoft: apple
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30009

๐Ÿ”ง Steps to Deploy

  1. Apply the ReplicaSet
bashCopyEditkubectl apply -f rs.yml
  1. Check the Pods
bashCopyEditkubectl get pods -l microsoft=apple
  1. Apply the LoadBalancer Service
bashCopyEditkubectl apply -f loadbalancer-rc.yml
  1. Expose and Access the App
bashCopyEditkubectl get svc loadbalancer-service-for-rs

Use the EXTERNAL-IP:80 (or NodeIP:NodePort) to access the HTTPD application.


โœ… Output Snapshots

๐Ÿ“Œ Pods Running (5 replicas):

bashCopyEditNAME               READY   STATUS    RESTARTS   AGE
myrs-1-abcde       1/1     Running   0          1m
myrs-1-fghij       1/1     Running   0          1m
...

๐Ÿ“Œ Service Exposed:

bashCopyEditNAME                          TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
loadbalancer-service-for-rs   LoadBalancer   10.100.200.10    <pending>     80:30009/TCP   1m

๐Ÿ“Œ Application in Browser:
Visit http://<NodeIP>:30009 โ†’ You'll see the default Apache HTTPD welcome page.


๐ŸŽ‰ Conclusion

You now have a highly available HTTPD application running in a Kubernetes cluster using a ReplicaSet with multiple label selectors and exposed using a LoadBalancer. This kind of setup is helpful for grouping pods using complex label logic and scaling deployments easily.

0
Subscribe to my newsletter

Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

BHASHWANTH PALUKURI
BHASHWANTH PALUKURI