Ingress

K8s AKS ingress

Deploy NGINX ingress

Create a values file:

cat <<EOF >ingress-internal.yml
controller:
  service:
    loadBalancerIP: 10.240.0.42
    annotations:
      service.beta.kubernetes.io/azure-load-balancer-internal: "true"

EOF

Check you network CIDR to specify loadBalancerIP.

You can also omit it in order to leave Azure to allocate an IP.

Create a namespace.

kubectl create namespace ingress-internal

Deploy NGINX ingress

helm install stable/nginx-ingress \
    --name=ingress-internal \
    --namespace ingress-internal \
    -f ingress-internal.yml \
    --set controller.replicaCount=2 \
    --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
    --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux

Check service IP.

kubectl -n ingress-internal get service ingress-internal-nginx-ingress-controller

The EXTERNAL-IP is actually the ingress internal IP.

References

https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/aks/ingress-internal-ip.md

Test it

kubectl create -f - <<EOF
---
apiVersion: v1
kind: Namespace
metadata:
  name: test-ingress
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-example
  namespace: test-ingress
  labels:
    app: my-example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-example
  template:
    metadata:
      labels:
        app: my-example
    spec:
      containers:
      - name: my-example
        image: nginx
                   
        ports:
        - containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
  name: my-example
  namespace: test-ingress
spec:
  selector:
    app: my-example
  ports:
  - protocol: TCP
    port: 80
  type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: example
  namespace: test-ingress
spec:
  rules:
    - host: www.example.com
      http:
        paths:
          - backend:
              serviceName: my-example
              servicePort: 80
            path: /

EOF

Edit your hosts file and point www.example.com to your ingress internal IP.

Last updated