How to resolve proper Kubernetes Cluster external IP dynamically while using Gitlab, Helm and nginx chart

Everybody wants to have as versatile gitops pipelines as possible. We can get closer to maximal possible versatility by removing all hard coded values from configuration files. One such value could be an external IP of a server that you’re installing your httpd service on.

In our case it was HELM, Executed from GitLab docker runner environment that was used to deploy Nginx ingress on Kubernetes cluster. It took us a while of head scratching to figure out how to get external IP of an cluster dynamically.

In one of our stages of .gitlab-ci.yml file pipeline we used :

        - mkdir -p /root/.kube/
        - echo ${KUBE_CONFIG} | base64 -d > /root/.kube/config
        - helm init --client-only
        - helm repo add stable
        - helm repo add incubator
        - helm repo update

above statements need :

  • image: paremeter set to some docker image with HELM binary installed
  • $KUBE_CONFIG parameter with base64 KUBE_CONFIG file contents

Having that we can now get to the fun part of getting EXTERNAL IP dynamically, and exchange it for PLACEHOLDER string in values.yaml configuration file :

        - export EXTERNAL_IP=`kubectl run --generator=run-pod/v1 -i --rm only-one-curl-run --image=centos:7 --restart=Never -- bash -c "curl -s" | grep -v deleted`
        - echo "Going with external_ip : "$EXTERNAL_IP
        - sed -i "s/PLACEHOLDER/${EXTERNAL_IP}/g"  ./helm/nginx-values.yaml

Now you can use such yaml to deploy the Nginx ingress with no hardcoded external IP. Pipeline yielded with below output result :

Going with external_ip :

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *