Introduction
I was trying to understand the Replicaset and wanted to see if we can run it directly and can it be accessible like Deployment Resource.
ReplicaSet
The YAML for the replicaset is:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: helloweb-rs
labels:
app: hello
spec:
replicas: 3
selector:
matchLabels:
app: hello
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello-app
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
I launched the 3 pods using the above YAML.
$ kubectl apply -f replicaset.yaml
replicaset.apps/helloweb-rs created
The status of the K8 cluster:
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/helloweb-rs-8grmh 1/1 Running 0 6s
pod/helloweb-rs-9bstq 1/1 Running 0 6s
pod/helloweb-rs-rzjc8 1/1 Running 0 6s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42h
NAME DESIRED CURRENT READY AGE
replicaset.apps/helloweb-rs 3 3 3 6s
Created load balancer service YAML
apiVersion: v1
kind: Service
metadata:
name: helloweb-svc
labels:
app: hello
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: hello
Launched it via kubectl:
$ kubectl apply -f service-lb.yaml service/helloweb-svc created
The status of the service
$ kubectl get all NAME READY STATUS RESTARTS AGE pod/helloweb-rs-8grmh 1/1 Running 0 3m9s pod/helloweb-rs-9bstq 1/1 Running 0 3m9s pod/helloweb-rs-rzjc8 1/1 Running 0 3m9s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/helloweb-svc LoadBalancer 10.102.140.85 localhost 80:30971/TCP 6s service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42h NAME DESIRED CURRENT READY AGE replicaset.apps/helloweb-rs 3 3 3 3m9s
Happy Coding !!
No comments:
Post a Comment