Adding a new Kubernetes deployment context

How to enable Kubernetes deployments to a new cluster and/or namespace in deployment-all

Problem

A new Kubernetes context needs to be enabled in deployment-all.

Steps

  1. Verify that the deployment-all checkout works correctly:

    ./openshift_login.sh
    
  2. Login to the cluster with admin rights, set the default namespace and show the context name (EXTERNAL_CONTEXT) via

    KUBECONFIG= oc login https://K8S.API.URL:6443 --token=TOKEN
    KUBECONFIG= oc config set-context --current --namespace=NAMESPACE
    KUBECONFIG= oc config current-context  # Save as EXTERNAL_CONTEXT, used later
    

    For OpenShift, the token can be obtained after logging into the web interface by clicking on your name in the top-right corner and selecting Copy login command.

  3. Add the new context to the KUBERNETES_CREDENTIALS variable in secrets.yml.

      NEW_CONTEXT:  # name of new context
        server: https://K8S.API.URL:6443
        namespace: NAMESPACE
        token: OPENSHIFT_NEW_CONTEXT_KEY  # env var for new sa token
        pvcmode: ReadWriteOnce  # RWO for AWS/EBS, RWX if possible for EFS/NFS
        dns_record_type: cname  # 'cname' for AWS, 'a' everywhere else
    

    Import the secrets again and deploy the setup project from openshift/setup via

    ./openshift_setup_context.sh NEW_CONTEXT EXTERNAL_CONTEXT
    
  4. Edit secrets.yml and move the new token env variable (OPENSHIFT_NEW_CONTEXT_KEY) to the appropriate place.

  5. Edit .gitlab-ci.yml and add the new context to the deployment of the setup project.

Last modified August 4, 2021: Update k8s context instructions (908eaec)