Skip to content

Instantly share code, notes, and snippets.

@officialdarnyc
Forked from calvin-puram/aws-load.md
Created September 11, 2022 20:31
Show Gist options
  • Save officialdarnyc/8de82b7fafe0d29fefb2cf13da35e0f5 to your computer and use it in GitHub Desktop.
Save officialdarnyc/8de82b7fafe0d29fefb2cf13da35e0f5 to your computer and use it in GitHub Desktop.

To verify that the controller is installed

kubectl get deployment -n kube-system aws-load-balancer-controller

Install Nginx controller in your cluster

This is what i used nginx controller please update the nginx controller service controller annotations. Once the manifest is applied next

Add deployment, service and ingress resource

I setup two deployment, service and ingress click here for setup 1 click here for setup 2 once the manifest is applied next

Setup the sub domain in route53 and point to the newly created loadbalancer

Then confirm if you can access the deployment using the domain you specify on your ingress resource. the http redirection won't work at this stage

Resolving HTTP Redirection

  1. Edit Configmap with
kubectl edit configmaps -n ingress-nginx ingress-nginx-controller

add

data:
  server-snippet: |
    listen 8000;
  ssl-redirect: "false"

Complete configmap as a reference:

apiVersion: v1
data:
  server-snippet: |
    listen 8000;
  ssl-redirect: "false"
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":null,"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"controller","app.kubernetes.io/i
nstance":"ingress-nginx","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"ingress-nginx","app.kubernetes.io/version":"0.34.1","helm.sh/chart":"
ingress-nginx-2.11.1"},"name":"ingress-nginx-controller","namespace":"ingress-nginx"}}
  creationTimestamp: "2020-08-03T17:29:25Z"
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/version: 0.34.1
    helm.sh/chart: ingress-nginx-2.11.1
  name: ingress-nginx-controller
  namespace: ingress-nginx

  1. Edit ingress-nginx deployment
kubectl edit deployments -n ingress-nginx ingress-nginx-controller

Add the following lines in ports: section

 - containerPort: 8000
     name: special
     protocol: TCP

More lines from deployments.

livenessProbe:
          failureThreshold: 5
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: controller
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        - containerPort: 443
          name: https
          protocol: TCP
        - containerPort: 8000
          name: special
          protocol: TCP
        - containerPort: 8443
          name: webhook
          protocol: TCP

When you save&exit deployments, it will create new ingress-nginx pod. finally, add the following annotations lines into your app ingress

nginx.ingress.kubernetes.io/server-snippet: |
      if ( $server_port = 80 ) {
         return 308 https://$host$request_uri;
      }

Complete app ingress resource yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: echo-ingress
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
      if ( $server_port = 80 ) {
         return 308 https://$host$request_uri;
      }
spec:
  ingressClassName: nginx
  rules:
    - host: meet.nautilustech.xyz
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: echo1
                port:
                  number: 80

then update the two ingress resource and test the redirection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment