How to setup HTTP Basic Auth for Kubernetes Ingress in Gitlab (using Gitlab's auto-deploy Docker images)

I am sharing a tutorial on how to setup a HTTP Basic Auth for Ingress when deploying to Kubernetes cluster to Google Cloud Platform (GCP) or Amazon AWS EKS

I am using excellent Gitlab’s Build and Deploy templates from here:

There is an easy way how to add HTTP Basis Auth to Ingress. You need to patch Ingress configuration after deployment.

See attached screenshot.

WARNING
If your password contains dollar sign “$”, you have to escape it in the code, eg. user: foo, password: bar

- echo "foo:\$apr1\$eUw/512K\$An/ZO8P.FRWDInvvxcHwH." > auth 

Important
Pay attention to the Service name which you can find in your GCP / AWS.