A ContainerGroup is a type of InstanceGroup that has an associated Credential that allows for connecting to an OpenShift cluster. To set up a container group, you must first have the following:

  • A namespace you can launch into (every cluster has a “default” namespace, but you may want to use a specific namespace)

  • A service account that has the roles that allow it to launch and manage Pods in this namespace

  • If you will be using execution environments in a private registry, and have a Container Registry credential associated to them in automation controller, the service account also needs the roles to get, create, and delete secrets in the namespace. If you do not want to give these roles to the service account, you can pre-create the ImagePullSecrets and specify them on the pod spec for the ContainerGroup. In this case, the execution environment should NOT have a Container Registry credential associated, or automation controller will attempt to create the secret for you in the namespace.

  • A token associated with that service account (OpenShift or Kubernetes Bearer Token)

  • A CA certificate associated with the cluster

This section describes creating a Service Account in an Openshift cluster (or K8s) in order to be used to run jobs in a container group via automation controller. After the Service Account is created, its credentials are provided to automation controller in the form of an Openshift or Kubernetes API bearer token credential. Below describes how to create a service account and collect the needed information for configuring automation controller.

To configure automation controller:

  1. To create a service account, you may download and use this sample service account, containergroup sa and modify it as needed to obtain the above credentials.

  2. Apply the configuration from containergroup-sa.yml:

    kubectl apply -f containergroup-sa.yml
    
  3. Create a token Secret for the service account; Kubernetes fills in its token and the CA of the cluster:

    kubectl apply -n containergroup-namespace -f - <<'EOF'
    apiVersion: v1
    kind: Secret
    metadata:
      name: containergroup-service-account-token
      annotations:
        kubernetes.io/service-account.name: containergroup-service-account
    type: kubernetes.io/service-account-token
    EOF
    
  4. Wait until Kubernetes has filled in the Secret, then write the token and the CA certificate to files only you can read:

    (
      set -euo pipefail; umask 077
      S="secret/containergroup-service-account-token -n containergroup-namespace"
      for _ in $(seq 30); do [ -n "$(kubectl get $S -o jsonpath='{.data.token}')" ] && break; sleep 2; done
      kubectl get $S -o jsonpath='{.data.token}' | base64 -d > containergroup-sa.token
      kubectl get $S -o jsonpath='{.data.ca\.crt}' | base64 -d > containergroup-ca.crt
      chmod 600 containergroup-sa.token containergroup-ca.crt
      test -s containergroup-sa.token && test -s containergroup-ca.crt
    )
    
  5. This token does not expire: delete the Secret to revoke it.

    To use a token that expires instead, skip steps 3 and 4 and request one; the API server may grant a shorter duration than requested, so renew the credential before it expires. The CA certificate is the one of your kubeconfig:

    (
      set -euo pipefail; umask 077
      kubectl create token containergroup-service-account -n containergroup-namespace \
        --duration=<time> > containergroup-sa.token
      kubectl config view --raw --minify \
        -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 -d > containergroup-ca.crt
      chmod 600 containergroup-sa.token containergroup-ca.crt
    )
    
  6. Use the contents of containergroup-sa.token and containergroup-ca.crt to provide the information for the OpenShift or Kubernetes API Bearer Token required for the container group.