Skip to content

Use a custom 404 page with kubernetes nginx ingress default backend

License

Notifications You must be signed in to change notification settings

dewhurstwill/k8s-custom-default-backend

Repository files navigation

K8S Custom Default Backend

default backend

Build instructions

React.JS

  1. Run docker build
docker build -t some_tag --build-arg REDIRECT_URL=https://some-url.com .
  1. Push image to registry
docker push some_registry/k8s-custom-default-backend:some_tag

Build Instructions (Native HTML + CSS + JS)

  1. Delete template from content folder
  2. Place index.html and related css/js files in content folder
  3. Remove lines 1 through 19 inclusive in Dockerfile
  4. Replace the new line 12 with COPY ./content /var/www/html/ in Dockerfile
  5. Run docker build
docker build -t some_tag .
  1. Push image to registry
docker push some_registry/k8s-custom-default-backend:some_tag

Usage instructions

  1. Create manifest (custom_default_backend.yaml)
---
apiVersion: v1
kind: Service
metadata:
  name: custom-default-backend
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: custom-default-backend
    app.kubernetes.io/part-of: ingress-nginx
spec:
  selector:
    app.kubernetes.io/name: custom-default-backend
    app.kubernetes.io/part-of: ingress-nginx
  ports:
  - port: 80
    targetPort: 80
    name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: custom-default-backend
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: custom-default-backend
    app.kubernetes.io/part-of: ingress-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: custom-default-backend
      app.kubernetes.io/part-of: ingress-nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/name: custom-default-backend
        app.kubernetes.io/part-of: ingress-nginx
    spec:
      containers:
      - name: custom-default-backend
        image: registry/k8s-custom-default-backend:some_tag
        imagePullPolicy: Always
        ports:
        - containerPort: 80
  1. Kubectl create the manifest
kubectl create -f custom_default_backend.yaml
  1. Delete previous Nginx Ingress Controller Helm installation
helm delete nginx-ingress -n ingress-nginx
  1. Reinstall
helm install nginx-ingress --namespace kube-system ingress-nginx/ingress-nginx --set defaultBackend.enabled=false,controller.defaultBackendService=ingress-nginx/custom-default-backend

Supporting

Please consider supporting my projects, the more caffine I have, the quicker I can type.

"Buy Me A Coffee"

About

Use a custom 404 page with kubernetes nginx ingress default backend

Resources

License

Stars

Watchers

Forks