🎯Day 34 - Working with Services in Kubernetes

🎯Day 34 - Working with Services in Kubernetes

🎯What are Services in K8s

In Kubernetes, Services are objects that provide stable network identities to Pods and abstract away the details of Pod IP addresses. Services allow Pods to receive traffic from other Pods, Services, and external clients.

🎯Task-1:

  • Create a Service for your todo-app Deployment from Day-32

  • Create a Service definition for your todo-app Deployment in a YAML file.

apiVersion: v1
kind: Service
metadata:
  name: node-app-service
  namespace: node-app-deployment
  labels:
    app: node-app
spec:
  type: NodePort
  selector:
    app: node-app
  ports:
    - port: 80
      targetPort: 8000
      nodePort: 30003
  • Apply the Service definition to your K8s (minikube) cluster using the kubectl apply -f service.yml -n <namespace-name> command.

  • Verify that the Service is working by accessing the todo-app using the Service's IP and Port in your Namespace.

🎯Task-2:

  • Create a ClusterIP Service for accessing the todo-app from within the cluster

  • Create a ClusterIP Service definition for your todo-app Deployment in a YAML file.

      apiVersion: v1
      kind: Service
      metadata:
        name : node-app-service
        namespace: node-app-deployment
      spec:
        selector:
          app: node-app
        ports:
          - port: 8000
            targetPort: 8000
        type: ClusterIP
    
  • Apply the ClusterIP Service definition to your K8s (minikube) cluster using the kubectl apply -f cluster-ip-service.yml -n <namespace-name> command.

  • Verify that the ClusterIP Service is working by accessing the todo-app from another Pod in the cluster in your Namespace.

🎯Task-3:

  • Create a LoadBalancer Service for accessing the todo-app from outside the cluster

  • Create a LoadBalancer Service definition for your todo-app Deployment in a YAML file.

       apiVersion: v1
      kind: Service
      metadata:
        name : node-app
        namespace: node-app-deployment
      spec:
        selector:
          app: node-app
        ports:
          - port: 8000
            targetPort: 8000
        type: LoadBalancer
    
    • Apply the LoadBalancer Service definition to your K8s (minikube) cluster using the kubectl apply -f load-balancer-service.yml -n <namespace-name> command.

  • Verify that the LoadBalancer Service is working by accessing the todo-app from outside the cluster in your Namespace.

📚Happy Learning :)