The kubernetes nginx ingress controller has a default backend which show error pages of 404, 502 with nginx string in the error page. But some times we need to show a valid custom error page instead of showing the pages served by the default backend.
The process is simple. We need to create a configmap with custom error pages, create deployment with image k8s.gcr.io/ingress-nginx/nginx-errors with mounting the config map in /www. Also we need to create service which will be used as the default backend service of the ingress controller.
Configmap Manifest : https://github.com/divyaimca/my-k8s-test-projects/blob/main/ingress-nginx/custom-default-backend.yaml#L72-L539
Note : update the custom error pages under data with the required error HTML content
Deployment Manifest : https://github.com/divyaimca/my-k8s-test-projects/blob/main/ingress-nginx/custom-default-backend.yaml#L19-L70
Service Manifest : https://github.com/divyaimca/my-k8s-test-projects/blob/main/ingress-nginx/custom-default-backend.yaml#L2-L17
Modification in ingress controller arguments : https://github.com/divyaimca/my-k8s-test-projects/blob/main/ingress-nginx/ingress-deploy.yaml#L337
Note: Here update the service name matching the custom error service name
Next thing we need to update the ingress definition file for which we want to use the custom error pages.
We need to add 2 annotations for this :
- Pointing to the custom error service name
- mention the custom error to be served.
Ingress manifest update Example : https://github.com/divyaimca/my-k8s-test-projects/blob/main/rabbitmq_kustom/rabbitmq-ingress.yaml#L9-L10
Now if you want to access the webpage served by the ingress with some error, the ingress will serve the customised backend error pages instead of the default backend error pages.
Recently I was working on a release pipeline where the helm chart of 30+ environments need to be updated in git with the new chart versions from Jenkins input.
Here the helm chart was in yaml format and it was a umbrella chart and individual service chart was needed to be updated from Jenkins.
The umbrella chart file looks like this. https://raw.githubusercontent.com/divyaimca/my_projects/main/update_helm_chart/chart.yaml
description: Helm chart to deploy application NG
- name: service-a
- name: service-b
- name: service-c
- name: service-d
- name: service-e
Here you can see there are 5 dependent services and each version needs to be updated from
I used python module pyyaml.
Here is the code that is used in one stage to achieve this task.
The function takes the input as chart.yaml file path and the subchart and versions in keyword arguments format. Refer the full code from the above link.