Configurando perfis confiáveis para o complemento do OpenShift Data Foundation
Nuvem privada virtual Clusters clássicos
Você pode usar perfis confiáveis para ODF a fim de limitar o acesso que os pods em execução no seu cluster têm a outros recursos da sua conta ou do cluster. Para obter mais informações sobre perfis confiáveis, consulte Criando perfis confiáveis.
Ativando o complemento do OpenShift Data Foundation
-
Ative o complemento no seu cluster. Revise a Referência do parâmetro.
Exemplo de comando:
ibmcloud oc cluster addon enable openshift-data-foundation -c CLUSTER_NAME --version 4.X.X -
Verifique se o estado do complemento é
normale o status éready.ibmcloud oc cluster addon ls --cluster CLUSTER-ID -
Verifique se o pod do agente de métricas está implementado e o status é
Running.kubectl get pods -n kube-system | grep ibm-storage-metrics-agentSaída de exemplo:
ibm-storage-metrics-agent-644cd95b5b-rh2gd 2/2 Running 0 7h42m
Configuração de perfis confiáveis para ODF
-
Siga as etapas para criar um perfil confiável. Nas Condições para o perfil, certifique-se de especificar o acesso a seguir.
- Permitir acesso quando Namespace for igual a
kube-system - Satellite- Satellite Link Administrador, Leitor
- Kubernetes Service Funções-Gerenciador, Editor
- Funções de Serviço de Faturamento-Leitor, Operador.
- Permitir acesso quando Namespace for igual a
-
Depois de criar o perfil confiável, copie o ID da página Perfis confiáveis no console.
-
Decida se você deseja usar o ID do perfil ou uma Chave de API no segredo do Kubernetes usado pelo complemento. É possível criar o segredo usando o ID ou a chave de API para o perfil confiável. Salve o texto a seguir e insira suas credenciais. É possível seguir as etapas para criar o segredo manualmente ou usar o shell script para criar automaticamente o segredo no cluster.
Exemplo de credenciais com identidade de pod:
IBMCLOUD_AUTHTYPE=pod-identity IBMCLOUD_PROFILEID=<TRUSTED-PROFILE-ID>Exemplo de credenciais com uma chave de API.
IBMCLOUD_AUTHTYPE=iam IBMCLOUD_APIKEY=<API-KEY> -
Codifique as credenciais para base64.
echo -n "IBMCLOUD_AUTHTYPE=<IAM-OR-POD-IDENTITY> IBMCLOUD_APIKEY=<API-KEY>" | base64 -
Crie um segredo no cluster que contenha as credenciais para o perfil confiável. Salve o YAML a seguir em um arquivo chamado
ibm-cloud-credentials.yaml. No campoibm-credentials.env:, insira a chave de API codificada em base64 ou o ID do perfil confiável.apiVersion: v1 data: ibm-credentials.env: # Trusted profile ID kind: Secret metadata: name: ibm-cloud-credentials namespace: kube-system type: Opaque -
Crie o segredo em seu cluster.
kubectl apply -f ibm-cloud-credentials.yaml -
Reinicie os pods do agente..
kubectl delete pod <ibm-storage-metrics-agent> -n kube-system>
Criando automaticamente um segredo por meio do uso de um Shell script
-
Siga as etapas para criar um perfil confiável. Nas Condições para o perfil, certifique-se de especificar o acesso a seguir.
- Permitir acesso quando Namespace for igual a
kube-system - Satellite- Satellite Link Administrador, Leitor
- Kubernetes Service Funções-Gerenciador, Editor
- Funções de Serviço de Faturamento-Leitor, Operador.
- Permitir acesso quando Namespace for igual a
-
Salve o script a seguir em um arquivo chamado
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 "$@" -
Execute o script
generate-secret.she especifiqueiamoupod-identitycomo oIBMCLOUD_AUTHTYPEe seuPROFILE-IDouAPI-KEY.Exemplo de comando para executar
generate-secret.shusandopod-identitycom seu ID de perfil confiável.sh ./generate-secret.sh pod-identity PROFILE-IDExemplo de comando para executar
generate-secret.shusandoiamcom uma chave de API.sh ./generate-secret.sh iam API-KEY -
Reinicie os pods do agente..
oc delete pod <ibm-storage-metrics-agent> -n kube-sysem -
Obtenha os logs do pod do agente para verificar se o driver está usando as credenciais corretas, procurando por “
secret type” na saída. Por exemplo,"secret-used":"ibm-cloud-credentials","type":"pod-identity".oc logs ibm-storage-metrics-agent-xxx -c storage-secret-sidecar -n kube-system