ReplicaSets with YAML¶
Step-01: Create ReplicaSet Definition¶
- replicaset-definition.yml
apiVersion: apps/v1 kind: ReplicaSet metadata: name: myapp2-rs spec: replicas: 3 # 3 Pods should exist at all times. selector: # Pods label should be defined in ReplicaSet label selector matchLabels: app: myapp2 template: metadata: name: myapp2-pod labels: app: myapp2 # Atleast 1 Pod label should match with ReplicaSet Label Selector spec: containers: - name: myapp2 image: stacksimplify/kubenginx:2.0.0 ports: - containerPort: 80
Step-02: Create ReplicaSet¶
- Create ReplicaSet with 3 Replicas
- Delete a pod
- ReplicaSet immediately creates the pod.
Step-03: Create NodePort Service for ReplicaSet¶
apiVersion: v1
kind: Service
metadata:
name: replicaset-nodeport-service
spec:
type: NodePort
selector:
app: myapp2
ports:
- name: http
port: 80
targetPort: 80
nodePort: 31232
# Create NodePort Service
kubectl apply -f 03-replicaset-nodeport-servie.yml
# List NodePort Service
kubectl get svc
# Get Public IP
kubectl get nodes -o wide
# Access Application
http://<Worker-Node-Public-IP>:<NodePort>
http://<Worker-Node-Public-IP>:31232
AWS EKS - Elastic Kubernetes Service - Masterclass¶
API References¶
- ReplicaSet: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#replicaset-v1-apps
🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99
$84.99
81% OFF
APRIL2026
Enroll Now on Udemy
🎉 Offer
