Skip to content

Instantly share code, notes, and snippets.

@hossambarakat
Created January 25, 2019 12:25
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hossambarakat/d54277918b254702186496b5af7a0075 to your computer and use it in GitHub Desktop.
Save hossambarakat/d54277918b254702186496b5af7a0075 to your computer and use it in GitHub Desktop.
Kubernestes Cross Namespace Ingress

Example

This is simple example showing:

  • Service service-alpha in service-alpha namespace
  • Service service-beta in service-beta namespace
  • Nginx Ingress controller in kube-ingress namespace
  • Ingress called ingress-demo inside service-alpha namespace
  • Ingress called ingress-demo inside service-beta namespace

Steps:

  • Install ingress on AKS. my demo cluster does not have rbac enabled that's why there is => --set rbac.create=false helm install stable/nginx-ingress --namespace kube-ingress --set controller.replicaCount=2 --set rbac.create=false

  • Get the public IP address of the ingress controller kubectl get service -l app=nginx-ingress --namespace kube-ingress

  • Add azure-samples helm repo as it contains the sample helm chart used for both service-alpha and service-beta helm repo add azure-samples https://azure-samples.github.io/helm-charts/

The used sample => https://github.com/Azure-Samples/helm-charts/tree/master/chart-source/aks-helloworld

  • Create service-alpha
helm install azure-samples/aks-helloworld --namespace service-alpha --set title="AKS Service Alpha" --set serviceName="service-alpha"
  • Create service-beta
helm install azure-samples/aks-helloworld --namespace service-beta --set title="AKS Service Beta" --set serviceName="service-beta"
  • Deploy the ingress route You need to create two ingress resources (not controllers) one in each namespace
kubectl apply -f ingress-route.yaml

This will create two ingress resources with one load balancer

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-demo
namespace: service-alpha
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /service-alpha
backend:
serviceName: service-alpha
servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-demo
namespace: service-beta
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /service-beta
backend:
serviceName: service-beta
servicePort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment