Day 04 Expose ReplicaSet Using NodePort Service.

Day 04 Expose ReplicaSet Using NodePort Service.

(1) What is Service in Kubernetes?

There are 4 Types of services.

  1. ClusterIP

  2. NodePort

  3. Load Balancer

  4. External Name

Kubernetes ServiceTypes allow you to specify what kind of Service you want. It allows us to communicate with the running pod on a Port of the Node.

NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). To make the node port available.

(2) Creating ReplicaSet.

  • Create ReplicaSet kubectl create -f frontend.yaml

  • frontend.yaml

      apiVersion: apps/v1
      kind: ReplicaSet
      metadata:
        name: frontend
        labels:
          app: guestbook
          tier: frontend
      spec:
        # modify replicas according to your case
        replicas: 3
        selector:
          matchLabels:
            tier: frontend
        template:
          metadata:
            labels:
              tier: frontend
          spec:
            containers:
            - name: php-redis
              image: gcr.io/google_samples/gb-frontend:v3
    

List ReplicaSet

kubectl get replicaset
kubectl get rs

Step-03: Expose ReplicaSet

Expose ReplicaSet using NodePort Service to access the application from the browser.

# Expose ReplicaSet
kubectl expose rs frontend  --type=NodePort --port=80 --target-port=8080 --name=frontend-service

# Check created Service
kubectl get service
      OR
kubectl get svc

# Get Public IP of Worker Nodes
kubectl get nodes -o wide
  • Please access it using public IP:

http://<node1-ip>:<NodePortNumber>/index.html

Step-04: Delete ReplicaSet & NodePort

# Delete ReplicaSet
kubectl delete rs <front-end
# Verify
kubectl get rs 

# Delete Service
kubectl delete svc front-end-service
# Verify
kubectl get svc

Made with :heart: by Pratikkumar Panchal