Mise à jour du secret d'extraction global dans les clusters Satellite

Après avoir mis en place un cluster Satellite, vous pouvez mettre à jour le secret d'extraction global de votre cluster afin d'extraire des données d'un registre de conteneurs privé autre que quay.io ou icr.io. Par exemple, vous pourriez vouloir extraire des images du Cloud Pak Entitled Registry (cp.icr.io) ou de votre propre registre privé.

Il existe deux façons de mettre à jour le secret d'extraction global dans les clusters Satellite.

Mise à jour du secret d'extraction global.
Utilisez cette approche si vous avez un ou plusieurs clusters à gérer. Vous devez répéter ces étapes pour chaque cluster dans lequel vous souhaitez appliquer le secret.
Mise à jour du secret d'extraction global à l'aide de la configuration Satellite.
Utilisez cette approche si vous gérez plusieurs clusters et groupes de clusters Satellite. En utilisant la configuration Satellite, vous pouvez appliquer les modifications de secret à vos clusters et groupes de clusters Satellite.

Mise à jour du secret d'extraction global

Procédez comme suit pour mettre à jour le secret d'extraction global dans votre cluster Satellite.

  1. Créez un secret qui possède les données d'identification pour le registre que vous souhaitez utiliser.
    oc create secret docker-registry docker-auth-secret \
    --docker-server=REGISTRY \
    --docker-username=USERNAME \
    --docker-password=PASSWORD \
    --namespace kube-system
    
    Exemple de commande create secret pour l'utilisation de Cloud Pak Entitled Registry.
    oc create secret docker-registry docker-auth-secret \
    --docker-server=cp.icr.io \
    --docker-username=cp \
    --docker-password=ENTITLEMENT-KEY \
    --namespace kube-system
    
  2. Créez un objet DaemonSet pour appliquer le secret à tous les noeuds worker.
    cat << EOF | oc create -f -
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: update-docker-config
      namespace: kube-system
      labels:
        app: update-docker-config
    spec:
      selector:
        matchLabels:
          name: update-docker-config
      template:
        metadata:
          labels:
            name: update-docker-config
        spec:
          initContainers:
            - command: ["/bin/sh", "-c"]
              args:
                - >
                  echo "Checking if RHEL or RHCOS host";
                  [[ -s /docker-config/.docker/config.json  ]] && CONFIG_PATH=/docker-config/.docker || CONFIG_PATH=/docker-config/root/.docker;
                  echo "Backing up or restoring config.json";
                  [[ -s \$CONFIG_PATH/config.json ]] && cp \$CONFIG_PATH/config.json \$CONFIG_PATH/config.json.bak || cp \$CONFIG_PATH/config.json.bak \$CONFIG_PATH/config.json;
                  echo "Merging secret with config.json";
                  /host/usr/bin/jq -s '.[0] * .[1]' \$CONFIG_PATH/config.json /auth/.dockerconfigjson > \$CONFIG_PATH/config.tmp;
                  mv \$CONFIG_PATH/config.tmp \$CONFIG_PATH/config.json;
                  echo "Sending signal to reload crio config";
                  pidof crio;
                  kill -1 \$(pidof crio)
              image: icr.io/ibm/alpine:latest
              imagePullPolicy: IfNotPresent
              name: updater
              resources: {}
              securityContext:
                privileged: true
              volumeMounts:
                - name: docker-auth-secret
                  mountPath: /auth
                - name: docker
                  mountPath: /docker-config
                - name: bin
                  mountPath: /host/usr/bin
                - name: lib64
                  mountPath: /lib64
          containers:
            - resources:
                requests:
                  cpu: 0.01
              image: icr.io/ibm/alpine:latest
              name: sleepforever
              command: ["/bin/sh", "-c"]
              args:
                - >
                  while true; do
                    sleep 100000;
                  done
          hostPID: true
          volumes:
            - name: docker-auth-secret
              secret:
                secretName: docker-auth-secret
            - name: docker
              hostPath:
                path: /
            - name: bin
              hostPath:
                path: /usr/bin
            - name: lib64
              hostPath:
                path: /lib64
                hostPathType: Directory
    EOF
    
  3. Vérifier que les pods fonctionnent.
    oc get daemonset -n kube-system update-docker-config
    

Mise à jour du secret d'extraction global à l'aide de la configuration Satellite

Procédez comme suit pour utiliser la configuration Satellite afin d'appliquer le secret d'extraction global à vos clusters et groupes de clusters Satellite.

  1. Veillez à activer Satellite config.

  2. Ajoutez vos clusters à des groupes de clusters.

  3. Créez un secret dans l'un de vos clusters Satellite. Notez que ce secret sera supprimé ultérieurement.

    oc create secret docker-registry docker-auth-secret \
    --docker-server=REGISTRY \
    --docker-username=USERNAME \
    --docker-password=PASSWORD \
    --namespace kube-system
    

    Exemple de commande create secret pour l'utilisation de Cloud Pak Entitled Registry.

    oc create secret docker-registry docker-auth-secret \
    --docker-server=cp.icr.io \
    --docker-username=cp \
    --docker-password=ENTITLEMENT-KEY \
    --namespace kube-system
    
  4. Obtenez les détails de votre secret. Copiez et sauvegardez la section base64 base64 dockerconfigjson.

    oc get secret docker-auth-secret -o yaml
    
  5. Supprimez le secret.

    oc delete secret docker-auth-secret -n kube-system
    
  6. Créez un fichier de configuration appelé secret.yaml qui contient vos données d'identification de registre. Collez la section base64 dockerconfigjson que vous avez sauvegardée à l'étape précédente.

    kind: Secret
    apiVersion: v1
    metadata:
      name: docker-auth-secret
      namespace: kube-system
    data:
      .dockerconfigjson: >-
        BASE64-ENCODED-SECRET
    type: kubernetes.io/dockerconfigjson
    
  7. Créer une configuration Satellite. Dans l'option --data-location, spécifiez la région Géré à partir de de votre emplacement.

    ibmcloud sat config create --data-location wdc --name my-config
    
  8. Ajoutez une version à votre configuration. Indiquez le chemin d'accès au fichier secret.yaml que vous avez créé précédemment.

    ibmcloud sat config version create --name 1 --config my-config --file-format yaml --read-config /Users/username/Desktop/secret.yaml
    
  9. Créez un abonnement pour appliquer DaemonSet à un groupe de clusters.

    ibmcloud sat subscription create --name my-subscription --config my-config --group GROUP
    
  10. Sauvegardez l'objet DaemonSet suivant dans un fichier appelé ds.yaml.

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: update-docker-config
      namespace: kube-system
      labels:
        app: update-docker-config
    spec:
      selector:
        matchLabels:
          name: update-docker-config
      template:
        metadata:
          labels:
            name: update-docker-config
        spec:
          initContainers:
            - command: ["/bin/sh", "-c"]
              args:
                - >
                  echo "Checking if RHEL or RHCOS host";
                  [[ -s /docker-config/.docker/config.json  ]] && CONFIG_PATH=/docker-config/.docker || CONFIG_PATH=/docker-config/root/.docker;
                  echo "Backing up or restoring config.json";
                  [[ -s \$CONFIG_PATH/config.json ]] && cp \$CONFIG_PATH/config.json \$CONFIG_PATH/config.json.bak || cp \$CONFIG_PATH/config.json.bak \$CONFIG_PATH/config.json;
                  echo "Merging secret with config.json";
                  /host/usr/bin/jq -s '.[0] * .[1]' \$CONFIG_PATH/config.json /auth/.dockerconfigjson > \$CONFIG_PATH/config.tmp;
                  mv \$CONFIG_PATH/config.tmp \$CONFIG_PATH/config.json;
                  echo "Sending signal to reload crio config";
                  pidof crio;
                  kill -1 \$(pidof crio)
              image: icr.io/ibm/alpine:latest
              imagePullPolicy: IfNotPresent
              name: updater
              resources: {}
              securityContext:
                privileged: true
              volumeMounts:
                - name: docker-auth-secret
                  mountPath: /auth
                - name: docker
                  mountPath: /docker-config
                - name: bin
                  mountPath: /host/usr/bin
                - name: lib64
                  mountPath: /lib64
          containers:
            - resources:
                requests:
                  cpu: 0.01
              image: icr.io/ibm/alpine:latest
              name: sleepforever
              command: ["/bin/sh", "-c"]
              args:
                - >
                  while true; do
                    sleep 100000;
                  done
          hostPID: true
          volumes:
            - name: docker-auth-secret
              secret:
                secretName: docker-auth-secret
            - name: docker
              hostPath:
                path: /
            - name: bin
              hostPath:
                path: /usr/bin
            - name: lib64
              hostPath:
                path: /lib64
                hostPathType: Directory
    
  11. Créer une configuration Satellite. Dans l'option --data-location, spécifiez la région Géré à partir de de votre emplacement, par exemple wdc.

    ibmcloud sat config create --data-location wdc --name my-ds
    
  12. Ajoutez une version à votre configuration. Indiquez le chemin d'accès au fichier ds.yaml que vous avez créé précédemment.

    ibmcloud sat config version create --name 1 --config my-ds --file-format yaml --read-config /Users/username/Desktop/ds.yaml
    
  13. Créez un abonnement pour appliquer DaemonSet à un groupe de clusters.

    ibmcloud sat subscription create --name my-subscription --config my-ds --group GROUP
    
  14. Vérifiez que le secret et DaemonSet sont déployés sur vos clusters.

    oc get secret docker-auth-secret -n kube-system
    
    oc get ds update-docker-config -n kube-system
    

Vous pouvez également consulter et gérer vos configurations et vos abonnements à partir de la console Satellite.