Configurazione dei profili attendibili per il componente aggiuntivo OpenShift Data Foundation

Virtual Private Cloud Cluster classici

È possibile utilizzare i profili di fiducia per ODF per limitare l'accesso dei pod in esecuzione nel cluster ad altre risorse dell'account o del cluster. Per ulteriori informazioni sui profili attendibili, consultare Creazione di profili attendibili.

Abilitazione del componente aggiuntivo OpenShift Data Foundation

  1. Accedi al tuo account. Se applicabile, specifica il gruppo di risorse appropriato. Imposta il contesto per il tuo cluster.

  2. Abilita il componente aggiuntivo nel tuo cluster. Esaminare il Riferimento parametro.

    Comando di esempio:

    ibmcloud oc cluster addon enable openshift-data-foundation -c CLUSTER_NAME --version 4.X.X
    
  3. Verificare che lo stato del componente aggiuntivo sia normal e che lo stato sia ready.

    ibmcloud oc cluster addon ls --cluster CLUSTER-ID
    
  4. Verificare che il pod dell'agent di metriche sia distribuito e che lo stato sia Running.

    kubectl get pods -n kube-system | grep ibm-storage-metrics-agent
    

    Output di esempio:

    ibm-storage-metrics-agent-644cd95b5b-rh2gd        2/2     Running   0          7h42m
    

Impostazione dei profili di fiducia per ODF

  1. Seguire la procedura per creare un profilo attendibile. In Condizioni per il profilo, assicurarsi di specificare il seguente accesso.

    • Consenti accesso quando Spazio dei nomi è uguale a kube-system
    • Satellite Satellite - Amministratore Satellite Link, Lettore
    • Ruoli Kubernetes Service- Manager, Editor
    • Ruoli del servizio di fatturazione - Lettore, Operatore
  2. Dopo aver creato il tuo profilo attendibile, copia l'ID della pagina Profili attendibili nella console.

  3. Decidi se vuoi utilizzare il ID profilo o un Chiave API nel segreto Kubernetes utilizzato dal componente aggiuntivo. Puoi creare il segreto utilizzando l'ID o la chiave API per il profilo attendibile. Salva il seguente testo e immetti le credenziali. Puoi seguire la procedura per creare il segreto manualmente oppure puoi utilizzare lo script della shell per creare automaticamente il segreto nel tuo cluster.

    Credenziali di esempio con identità pod:

    IBMCLOUD_AUTHTYPE=pod-identity
    IBMCLOUD_PROFILEID=<TRUSTED-PROFILE-ID>
    

    Credenziali di esempio con una chiave API.

    IBMCLOUD_AUTHTYPE=iam
    IBMCLOUD_APIKEY=<API-KEY>
    
  4. Codifica le credenziali in base64.

    echo -n "IBMCLOUD_AUTHTYPE=<IAM-OR-POD-IDENTITY>
    IBMCLOUD_APIKEY=<API-KEY>" | base64
    
  5. Crea un segreto nel tuo cluster contenente le credenziali per il profilo attendibile. Salvare il seguente YAML in un file denominato ibm-cloud-credentials.yaml. Nel campo ibm-credentials.env:, immetti la chiave API con codifica base64 o l'ID del profilo attendibile.

    apiVersion: v1
    data:
      ibm-credentials.env: # Trusted profile ID
    kind: Secret
    metadata:
      name: ibm-cloud-credentials
      namespace: kube-system
    type: Opaque
    
  6. Accedi al tuo account. Se applicabile, specifica il gruppo di risorse appropriato. Imposta il contesto per il tuo cluster.

  7. Crea il segreto nel tuo cluster.

    kubectl apply -f ibm-cloud-credentials.yaml
    
  8. Riavviare i pod dell'agente.

    kubectl delete pod <ibm-storage-metrics-agent> -n kube-system>
    

Creazione automatica di una parola segreta utilizzando uno script Shell

  1. Seguire la procedura per creare un profilo attendibile. In Condizioni per il profilo, assicurarsi di specificare il seguente accesso.

    • Consenti accesso quando Spazio dei nomi è uguale a kube-system
    • Satellite Satellite - Amministratore Satellite Link, Lettore
    • Ruoli Kubernetes Service- Manager, Editor
    • Ruoli del servizio di fatturazione - Lettore, Operatore
  2. Salvare il seguente script in un file denominato generate-secret.sh.

    IBMCLOUD_AUTHTYPE=
    SECRET=
    error() {
        if [[ $? != 0 ]]; then
            echo "$1"; exit 1
        fi
    }
    #validate_arguments validates the arguments provided to the script
    validate_arguments() {
        if [[ "$#" -eq 1 ]]; then
        if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
            usage; exit 1
        fi
        fi
            #number of arguments provided to the script must be 2
        if [[ "$#" -ne 2 ]]; then
            echo "Invalid number of arguments provided"
            usage; exit 1
        fi
        #1st argument must be 'iam' or 'pod-identity'
        if [[ "$1" != "iam" ]] && [[ "$1" != "pod-identity" ]]; then
            echo "Provide a valid auth-type"
            usage; exit 1
        fi
        IBMCLOUD_AUTHTYPE=$1
        SECRET=$2
    }
    #usage - prints the usage for execution of script
    usage() {
        echo "USAGE:
        bash generate-secret.sh <auth-type> <apikey/profile-id>
        auth-type: auth-type should be either iam or pod-identity. Provide iam to use api
    key, pod-identity to use trusted profile"
    }
    #main
    main() {
        validate_arguments "$@"
        auth_type="IBMCLOUD_AUTHTYPE=$IBMCLOUD_AUTHTYPE"
        secret=
        if [[ "$IBMCLOUD_AUTHTYPE" == "iam" ]]; then
            secret="IBMCLOUD_APIKEY=$SECRET"
        else
            secret="IBMCLOUD_PROFILEID=$SECRET"
        fi
        encodedValue=$(echo -e "$auth_type\n$secret" | base64)
        #on certain os, base64 encoding introduces newline, removing the same here.
        encodedValue=${encodedValue//$'\n'/}
        #fetch the agent pod name
        agentPodName=$(kubectl get pods -n kube-system | grep ibm-storage-metrics-agent | awk '{print $1}')
        error "$(date +"%b %d %G %H:%M:%S"):  Unable to fetch ODF agent pod."
        if [[ "$agentPodName" == "" ]]; then
            echo "$(date +"%b %d %G %H:%M:%S"):  Error - ibm-storage-metrics-agent pod
    not found"
            exit 1
        fi
        echo "apiVersion: v1
    data:
    ibm-credentials.env: $encodedValue
    kind: Secret
    metadata:
    name: ibm-cloud-credentials
    namespace: kube-system
    type: Opaque" > ibm-cloud-credentials.yaml
        #create the k8s secret
        kubectl apply -f ibm-cloud-credentials.yaml &> /dev/null
        error "$(date +"%b %d %G %H:%M:%S"):  Error creating ibm-cloud-credentials
    secret."
        echo "$(date +"%b %d %G %H:%M:%S"):  Created ibm-cloud-credentials secret"
        #restart the ODF agent pod
        echo "$(date +"%b %d %G %H:%M:%S"):  Restarting $agentPodName pod"
        kubectl delete pod "$agentPodName" -n kube-system &> /dev/null
        error "$(date +"%b %d %G %H:%M:%S"):  Error restarting $agentPodName pod in
    kube-system namespace."
        agentPodStatus=
        for i in {1..12}
        do
            sleep 5
            agentPodStatus=$(kubectl get pods -n kube-system | grep ibm-storage-metrics-agent | awk '{print $3}')
            if [[ "$agentPodStatus" == "Running" ]]; then
                echo "$(date +"%b %d %G %H:%M:%S"):  $i: ODF billing agent is now using
    ibm-cloud-credentials secret"
                rm ibm-cloud-credentials.yaml
                error "Error deleting ibm-cloud-credentials.yaml."
                exit 0
            fi
        done
        error "$(date +"%b %d %G %H:%M:%S"):  Error - ibm-storage-metrics-agent is in
    $agentPodStatus state"
    }
    main "$@"
    
  3. Eseguire lo script generate-secret.sh e specificare iam o pod-identity come IBMCLOUD_AUTHTYPE e PROFILE-ID o API-KEY.

    Comando di esempio per eseguire generate-secret.sh utilizzando pod-identity con il tuo ID profilo attendibile.

    sh ./generate-secret.sh pod-identity PROFILE-ID
    

    Comando di esempio per eseguire generate-secret.sh utilizzando iam con una chiave API.

    sh ./generate-secret.sh iam API-KEY
    
  4. Riavviare i pod dell'agente.

    oc delete pod <ibm-storage-metrics-agent> -n kube-sysem
    
  5. Ottenere i log del pod dell'agent per verificare che il driver stia utilizzando le credenziali corrette ricercando il secret type nell'output. Ad esempio,"secret-used":"ibm-cloud-credentials","type":"pod-identity".

    oc logs ibm-storage-metrics-agent-xxx -c storage-secret-sidecar -n kube-system