0
0
Kubernetesdevops~30 mins

Ingress vs LoadBalancer Service decision in Kubernetes - Hands-On Comparison

Choose your learning style9 modes available
Ingress vs LoadBalancer Service Decision in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster for a small company. You need to expose your web application to users outside the cluster. You want to decide whether to use an Ingress resource or a LoadBalancer service type to route external traffic to your application.
🎯 Goal: Build a simple Kubernetes configuration to understand the difference between using an Ingress and a LoadBalancer service. You will create a basic service and deployment, then add either a LoadBalancer service or an Ingress resource to expose the app externally. This will help you learn when to choose each option.
📋 What You'll Learn
Create a deployment named webapp with one replica running the nginx image
Create a service named webapp-service exposing port 80
Add a LoadBalancer service type to expose the app externally
Add an Ingress resource to route traffic to the service
Understand the difference in configuration and usage between LoadBalancer and Ingress
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, exposing applications to users outside the cluster is common. Choosing between LoadBalancer services and Ingress resources affects cost, flexibility, and features.
💼 Career
DevOps engineers and cloud administrators must understand how to expose services securely and efficiently. Knowing when to use LoadBalancer or Ingress is essential for managing Kubernetes networking.
Progress0 / 4 steps
1
Create a Deployment for the web application
Create a Kubernetes deployment named webapp with one replica running the nginx image. Use port 80 in the container spec.
Kubernetes
Need a hint?

Use kind: Deployment and set replicas: 1. The container should use the nginx image and expose port 80.

2
Create a Service to expose the Deployment internally
Create a Kubernetes service named webapp-service that selects pods with label app: webapp. Expose port 80 and target port 80. Use service type ClusterIP.
Kubernetes
Need a hint?

Use kind: Service with type: ClusterIP. Match pods with label app: webapp. Expose port 80.

3
Change the Service type to LoadBalancer to expose externally
Modify the webapp-service service to use type: LoadBalancer instead of ClusterIP. Keep all other settings the same.
Kubernetes
Need a hint?

Change the type field in the service spec to LoadBalancer to expose the service externally.

4
Create an Ingress resource to route traffic to the Service
Create a Kubernetes Ingress resource named webapp-ingress that routes HTTP traffic from host example.com to the webapp-service on port 80. Use the nginx ingress class.
Kubernetes
Need a hint?

Use kind: Ingress with annotation kubernetes.io/ingress.class: nginx. Route host example.com to service webapp-service on port 80.