๐Ÿš€ Demystifying Kubernetes Services: A Practical Walkthrough ๐Ÿ› ๏ธ Day - 34

ยท

2 min read

Greetings, Hashnode community! Today, we're embarking on a journey through the intricate world of Kubernetes Services. Whether you're a Kubernetes novice or a seasoned pro, mastering the art of deploying and exposing applications within a cluster is paramount. So, buckle up as we dive into some hands-on challenges!

Task 1: Crafting the Todo-App Service

Our first task involves creating a Service to provide our todo-app Pods with stable network identities. In the service.yml file, we're orchestrating a straightforward Service, complete with selectors and ports:

# service.yml
apiVersion: v1
kind: Service
metadata:
  name: todo-app-service
spec:
  selector:
    app: todo-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

To bring this to life in your namespace, execute:

kubectl apply -f service.yml -n <namespace-name>

Remember to replace <namespace-name> with your actual namespace.

Now, the real test begins! Confirm that your todo-app is accessible using the Service's IP and Port in your namespace.

Task 2: Elevating the Experience with ClusterIP Service

For more intimate internal communications within the cluster, let's introduce the ClusterIP Service. The cluster-ip-service.yml is our backstage pass to this exclusive interaction:

# cluster-ip-service.yml
apiVersion: v1
kind: Service
metadata:
  name: todo-app-clusterip-service
spec:
  selector:
    app: todo-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: ClusterIP

Initiate the magic (in your terminal, of course):

kubectl apply -f cluster-ip-service.yml -n <namespace-name>

Feel the vibes โ€“ make sure you can seamlessly access the todo-app from another Pod within the cluster.

Task 3: Unleashing the Glamour with LoadBalancer Service

Now, let's make our todo-app the star of the show! Enter the LoadBalancer Service. Our load-balancer-service.yml is your VIP invitation to this exclusive affair:

# load-balancer-service.yml
apiVersion: v1
kind: Service
metadata:
  name: todo-app-loadbalancer-service
spec:
  selector:
    app: todo-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer

Fire up the engines:

kubectl apply -f load-balancer-service.yml -n <namespace-name>

Hold your breath โ€“ check if the todo-app shines from outside the cluster in your namespace.

There you have it! You've just conquered Kubernetes Services like a seasoned navigator. These insights are invaluable for deploying applications in the Kubernetes playground. Keep exploring, and may your pods always be running smoothly! ๐Ÿš€โœจ

ย