Kubernetes – Ingress few backends

Configuration example Kubernetes Ingress with the choice of backend based on the value of the argument “proxy“. And the default backend, if the value of the argument “proxy” is different from “1” and “2“, or is missing.

manifest.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: artem-test-proxy-0-app
  namespace: staging
  labels:
    app: artem-test-proxy-0-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: artem-test-proxy-0-app
  strategy:
    type: RollingUpdate
  progressDeadlineSeconds: 300
  minReadySeconds: 60
  template:
    metadata:
      labels:
        app: artem-test-proxy-0-app
    spec:
      containers:
      - name: artem-test-proxy-0
        image: dockersamples/static-site
        env:
        - name: AUTHOR
          value: Default
        ports:
        - containerPort: 80
      nodeSelector:
        nodegroup: staging
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: artem-test-proxy-1-app
  namespace: staging
  labels:
    app: artem-test-proxy-1-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: artem-test-proxy-1-app
  strategy:
    type: RollingUpdate
  progressDeadlineSeconds: 300
  minReadySeconds: 60
  template:
    metadata:
      labels:
        app: artem-test-proxy-1-app
    spec:
      containers:
      - name: artem-test-proxy-1
        image: dockersamples/static-site
        env:
        - name: AUTHOR
          value: Proxy=1
        ports:
        - containerPort: 80
      nodeSelector:
        nodegroup: staging
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: artem-test-proxy-2-app
  namespace: staging
  labels:
    app: artem-test-proxy-2-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: artem-test-proxy-2-app
  strategy:
    type: RollingUpdate
  progressDeadlineSeconds: 300
  minReadySeconds: 60
  template:
    metadata:
      labels:
        app: artem-test-proxy-2-app
    spec:
      containers:
      - name: artem-test-proxy-2
        image: dockersamples/static-site
        env:
        - name: AUTHOR
          value: Proxy=2
        ports:
        - containerPort: 80
      nodeSelector:
        nodegroup: staging

---

apiVersion: v1
kind: Service
metadata:
  name: artem-test-proxy-0-svc
  namespace: staging
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: artem-test-proxy-0-app
---
apiVersion: v1
kind: Service
metadata:
  name: artem-test-proxy-1-svc
  namespace: staging
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: artem-test-proxy-1-app
---
apiVersion: v1
kind: Service
metadata:
  name: artem-test-proxy-2-svc
  namespace: staging
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: artem-test-proxy-2-app

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: artem-test-proxy-ing
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: ingress-staging
    certmanager.k8s.io/cluster-issuer: letsencrypt-prod
    certmanager.k8s.io/acme-challenge-type: dns01
    certmanager.k8s.io/acme-dns01-provider: dns
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/configuration-snippet: |
                    if ($arg_proxy = 1) {
                      proxy_pass http://artem-test-proxy-1-svc.staging.svc.cluster.local;
                    }
                    if ($arg_proxy = 2) {
                      proxy_pass http://artem-test-proxy-2-svc.staging.svc.cluster.local;
                    }
spec:
  tls:
  - hosts:
    - artem.services
    secretName: artem.services-secret-tls
  rules:
  - host: artem.services
    http:
      paths:
      - path: /
        backend:
          serviceName: artem-test-proxy-0-svc
          servicePort: 80

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments