IT networking is the practice of connecting multiple computing devices together so they can exchange data, share resources, and communicate with each other . It forms the invisible digital backbone of our world, powering everything from your home Wi-Fi to corporate cloud environments and the global internet. Core Components of a Network To understand how an IT network operates, it helps to look at its fundamental building blocks: Nodes (End Devices) : Any physical device connected to the network that sends or receives information. Examples include laptops, smartphones, servers, printers, and IoT devices like smart TVs. Links (Transmission Media) : The channels used to connect the nodes together. These can be wired (like Ethernet and copper cables or high-speed fiber optics) or wireless (like Wi-Fi, Bluetooth, and cellular signals). Network Devices : Specialized hardware that directs traffic across the network. Switches : Connect multiple devices together within the same local network....
Of course. To set up host-based routing in EKS, you define an Ingress resource with multiple rules. Each rule specifies a hostname (e.g., app1.example.com) and maps it to a corresponding backend Service. The AWS Load Balancer Controller reads this resource and provisions an Application Load Balancer (ALB) to route traffic based on the Host header of incoming requests.
Here’s a complete guide.
Prerequisites
A running Amazon EKS cluster.
kubectl configured to connect to your cluster.
The AWS Load Balancer Controller installed in your cluster. This is the standard Ingress controller for EKS.
A registered domain name (e.g., your-domain.com) that you can manage.
Step 1: Deploy Sample Applications
First, let's deploy two different applications to route traffic to: a "coffee" app ☕ and a "tea" app ЁЯН╡. Each application will have a Deployment and a Service.
Save the following YAML as apps.yaml:
# apps.yaml
# --- Coffee App ---
apiVersion: apps/v1
kind: Deployment
metadata:
name: coffee-deployment
spec:
replicas: 2
selector:
matchLabels:
app: coffee
template:
metadata:
labels:
app: coffee
spec:
containers:
- name: coffee-container
image: hashicorp/http-echo:latest # A simple echo server
args:
- "-text=Welcome to the Coffee Service!"
ports:
- containerPort: 5678
---
apiVersion: v1
kind: Service
metadata:
name: coffee-service
spec:
type: ClusterIP
selector:
app: coffee
ports:
- protocol: TCP
port: 80
targetPort: 5678
---
# --- Tea App ---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tea-deployment
spec:
replicas: 2
selector:
matchLabels:
app: tea
template:
metadata:
labels:
app: tea
spec:
containers:
- name: tea-container
image: hashicorp/http-echo:latest
args:
- "-text=Welcome to the Tea Service!"
ports:
- containerPort: 5678
---
apiVersion: v1
kind: Service
metadata:
name: tea-service
spec:
type: ClusterIP
selector:
app: tea
ports:
- protocol: TCP
port: 80
targetPort: 5678
Apply this manifest to your cluster:
kubectl apply -f apps.yaml
Step 2: Create the Ingress Resource
Next, create the Ingress resource. This object defines the routing logic. The spec.rules section is where you map each hostname to its backend service.
Save the following as host-based-ingress.yaml. Remember to replace coffee.your-domain.com and tea.your-domain.com with your actual hostnames.
# host-based-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: main-ingress
annotations:
# This annotation specifies that the ALB should be internet-facing
alb.ingress.kubernetes.io/scheme: internet-facing
# This annotation directs the ALB to route traffic directly to pod IPs
alb.ingress.kubernetes.io/target-type: ip
spec:
# This field tells Kubernetes that the AWS Load Balancer Controller should manage this Ingress
ingressClassName: alb
rules:
# Rule for requests to the coffee host
- host: "coffee.your-domain.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: coffee-service # Routes traffic to the coffee-service
port:
number: 80
# Rule for requests to the tea host
- host: "tea.your-domain.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: tea-service # Routes traffic to the tea-service
port:
number: 80
Apply the Ingress manifest:
kubectl apply -f host-based-ingress.yaml
Step 3: Verify the Load Balancer
The AWS Load Balancer Controller will now provision an ALB in your AWS account. This can take a few minutes.
Check Ingress Status: Find the DNS address of the newly created ALB.
kubectl get ingress main-ingress
Wait until the ADDRESS column is populated with a DNS name (e.g., k8s-...-.elb.amazonaws.com).
Test Routing: Before setting up DNS, you can test the routes using curl and specifying the Host header. Let's say your ALB address is YOUR_ALB_ADDRESS.
Test the coffee route:
# Replace YOUR_ALB_ADDRESS with the address from the previous command
curl http://YOUR_ALB_ADDRESS -H "Host: coffee.your-domain.com"
This should return Welcome to the Coffee Service!.
Test the tea route:
curl http://YOUR_ALB_ADDRESS -H "Host: tea.your-domain.com"
This should return Welcome to the Tea Service!.
Step 4: Configure DNS ЁЯМР
The final step is to point your public hostnames to the ALB.
Go to your DNS provider (e.g., Amazon Route 53, GoDaddy, Cloudflare).
Create two CNAME records:
Record 1:
Name: coffee (or coffee.your-domain.com)
Type: CNAME
Value/Target: The ALB address you got from kubectl get ingress.
Record 2:
Name: tea (or tea.your-domain.com)
Type: CNAME
Value/Target: The same ALB address.
Note: If you use Amazon Route 53, it is best practice to create an A record and use the Alias feature to point it directly to the Application Load Balancer.
After the DNS records propagate, you can access your services using their public URLs:
curl http://coffee.your-domain.com
curl http://tea.your-domain.com
Comments
Post a Comment