k8s

Simple Ingress Controller for Kubernetes (NGINX-based)

🌐 Simple Ingress Controller for Kubernetes (NGINX-based)

This guide provides a simple setup for deploying NGINX Ingress Controller on a Kubernetes cluster, suitable for bare-metal or lab environments using NodePort service type.


📦 Step 1: Create Namespace

kubectl create namespace ingress-nginx

🚀 Step 2: Deploy Ingress Controller

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.1/deploy/static/provider/baremetal/deploy.yaml

Wait a few seconds for the pods to be created in the ingress-nginx namespace.


🌍 Step 3: Expose Ingress via NodePort (Optional)

Edit the service to use NodePort instead of LoadBalancer:

kubectl edit svc ingress-nginx-controller -n ingress-nginx

Change this:

spec:
  type: LoadBalancer

To:

spec:
  type: NodePort

Then check the assigned ports:

kubectl get svc -n ingress-nginx

You’ll see output like:

NAME                       TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller   NodePort   10.96.221.42   <none>        80:31234/TCP,443:31235/TCP   2m

🧪 Step 4: Test with a Sample Ingress

Create a test Ingress resource:

# hello-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
    - host: local.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: hello-service
                port:
                  number: 80

Don’t forget to create the backend service (hello-service) and add local.example.com to your /etc/hosts file pointing to your Node IP.


📄 Reference

0
Uncategorized