Practical Implementation
Step-by-Step Ingress Configuration
Prerequisites
Before implementing Ingress, ensure you have:
- Kubernetes cluster
- Ingress controller installed
- Multiple services ready for routing
graph TD
A[Kubernetes Cluster] --> B[Ingress Controller]
B --> C[Multiple Services]
C --> D[Ingress Resource]
Deployment Workflow
1. Create Sample Services
## Create user service
kubectl create deployment users --image=nginx
kubectl expose deployment users --port=80
## Create products service
kubectl create deployment products --image=nginx
kubectl expose deployment products --port=80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: microservices-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: app.labex.io
http:
paths:
- path: /users
pathType: Prefix
backend:
service:
name: users
port:
number: 80
- path: /products
pathType: Prefix
backend:
service:
name: products
port:
number: 80
Ingress Configuration Options
Annotation |
Purpose |
Example |
nginx.ingress.kubernetes.io/rewrite-target |
Redirect traffic |
rewrite-target: / |
kubernetes.io/ingress.class |
Specify controller |
nginx |
cert-manager.io/cluster-issuer |
SSL/TLS management |
letsencrypt-prod |
Verification Steps
## Apply Ingress configuration
kubectl apply -f ingress.yaml
## Check Ingress status
kubectl get ingress
## Verify service endpoints
kubectl describe ingress microservices-ingress
Troubleshooting Common Issues
Routing Problems
## Check Ingress controller logs
kubectl logs -n ingress-nginx ingress-nginx-controller-xxx
Network Debugging
## Verify service connectivity
kubectl get services
kubectl describe service users
kubectl describe service products
Advanced Configuration Techniques
SSL/TLS Termination
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: secure-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- app.labex.io
secretName: app-tls-secret
rules:
- host: app.labex.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: users
port:
number: 80
- Use path-based routing efficiently
- Minimize complex routing rules
- Monitor Ingress controller performance
LabEx Learning Approach
LabEx provides interactive labs that simulate real-world Ingress configurations, helping developers master multi-service routing techniques through hands-on experience.