Kubernetes Kubeadm Ingress
Prerequisites
A running Kubernetes cluster (set up using kubeadm)
A registered domain in a Route 53 hosted zone for Ingress
kubectl CLI tool installed and configured to interact with your Kubernetes cluster.
Check if your Kubernetes nodes are running:
Step 1. Deploy Three deployment for different paths.
kubectl create deployment nodejs-deployment --image=babbalrai/ingress_nodejs_webapp --port=3000
kubectl create deployment python-deployment --image=babbalrai/ingress_python_webapp --port=3001
kubectl create deployment go-deployment --image=babbalrai/ingress_go_webapp --port=3002
- Check your deployment
kubectl get deployment
- Create Service for deployments
kubectl expose deployment nodejs-deployment --type=NodePort --name=nodejs-service --port=3000 --target-port=3000
kubectl expose deployment python-deployment --type=NodePort --name=python-service --port=3001 --target-port=3001
kubectl expose deployment go-deployment --type=NodePort --name=go-service --port=3002 --target-port=3002
Check services.
Step 2 : create ACM certificate
To enable HTTPS, configure TLS termination for your Ingress.
Step 2. Install an Ingress Controller
This ingress setup is for aws please find your ingress controller according to your cloud provider
https://kubernetes.github.io/ingress-nginx/deploy/
- First, ensure that an Ingress controller is installed in your cluster. The following example uses the NGINX Ingress Controller.
Step 2.1: Deploy NGINX Ingress Controller
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
Step 2.2: Verify Ingress Controller Installation
kubectl get pods -n ingress-nginx
- Ensure that all pods related to the ingress-nginx namespace are running.
Step 3. Create an Ingress Resource
- Create an Ingress resource to define the rules for routing traffic to your service.
Step 3.1: Define the Ingress Resource
Create a file named my-ingress.yaml with the following content:
nano my-ingress.yaml
Paste your Domain in the host value field.
For example -
- Doman - trainingdemy.com
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-ingress
annotations:
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:382541523649:certificate/c4c8c68f-4fd5-4cef-8c50-16389727c0ed
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/ssl-redirect: '443'
alb.ingress.kubernetes.io/scheme: internet-facing
spec:
ingressClassName: nginx
rules:
- host: "linuxwebuser.me"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nodejs-service
port:
number: 3000
- path: /python
pathType: Prefix
backend:
service:
name: python-service
port:
number: 3001
- path: /go
pathType: Prefix
backend:
service:
name: go-service
port:
number: 3002
Step 3.2: Apply the Ingress Resource
kubectl apply -f my-ingress.yaml
If you get this error -
Error from server (InternalError): error when creating "my-ingress.yaml": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": failed to call webhook: Post "https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1/ingresses?timeout=10s": dial tcp 10.96.64.42:443: i/o timeout
Step 3.3: Verify the Ingress Resource
This is the issue in nginx ingress
You can delete ValidatingWebhookConfiguration component
kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
After deleting ValidatingWebhookConfiguration again try to create ingress resource.
kubectl apply -f my-ingress.yaml
kubectl get ingress
This command will display the Ingress resource and its associated rules.
4. Configure DNS
Point your domain (e.g., example.com) to the external IP of the Ingress controller. This can be done by updating your DNS settings with your domain registrar.
Step 4.1: Get the Ingress Controller External IP
kubectl get service ingress-nginx-controller -n ingress-nginx
The external IP listed here should be used in your DNS settings.
Step 4.2: Update DNS Records
Create an A record in your DNS settings pointing example.com to the external IP of the Ingress controller.
5. Troubleshooting
Step 5.1: Check Ingress Controller Logs
If the Ingress resource isn't working as expected, check the Ingress controller logs:
$ kubectl logs -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx |
Step 5.2: Debugging Ingress Issues
Common issues may include misconfigured DNS, incorrect service names, or improper TLS settings. Review the Ingress resource configuration and logs to identify any errors.
6. Cleanup
Step 6.1: Remove Ingress Resources
To clean up all resources related to Ingress:
$ kubectl delete ingress my-ingress |
Step 6.2: Remove the Ingress Controller
$ kubectl delete -f raw.githubusercontent.com/kubernetes/ingres.. |