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
- Apply the ReplicaSet
bashCopyEditkubectl apply -f rs.yml
- Check the Pods
bashCopyEditkubectl get pods -l microsoft=apple
- Apply the LoadBalancer Service
bashCopyEditkubectl apply -f loadbalancer-rc.yml
- 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.
Subscribe to my newsletter
Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
