Aggiunta di una CA affidabile a Red Hat OpenShift on IBM Cloud
Cloud virtuale privato 4.19 e successivamente Nodi worker RHCOS Nodi worker RHEL
Scoprite come aggiungere un'autorità di certificazione (CA) affidabile al vostro cluster Red Hat® OpenShift® on IBM Cloud®. Potrebbe essere necessario aggiungere una CA affidabile quando si estraggono le immagini da un registro self-hosted che utilizza un certificato firmato da una CA personalizzata.
Aggiunta di una CA affidabile al cluster
Per aggiungere una CA affidabile al cluster Red Hat OpenShift on IBM Cloud, si crea una configmap contenente il certificato della CA e si distribuisce un daemonset che installa il certificato su tutti i nodi worker.
Prima di iniziare, assicuratevi di avere pronto il file del certificato CA. Il certificato deve essere in formato PEM.
-
Creare la configmap
openshift-config-user-ca-bundlecon il certificato CA. Sostituire<path-to-your-ca-cert>con il percorso del file del certificato CA.kubectl create cm openshift-config-user-ca-bundle -n kube-system --from-file=openshift-config-user-ca-bundle.crt=<path-to-your-ca-cert> -
Creare lo script che installa la CA affidabile su ogni nodo.
cat > openshift-config-user-ca-script.sh <<EOF #!/bin/bash set -e # Exit on any error set -x # Enable debug output if ! diff /tmp/openshift-config-user-ca-bundle/openshift-config-user-ca-bundle.crt /host/etc/pki/ca-trust/source/anchors ; then cp /tmp/openshift-config-user-ca-bundle/openshift-config-user-ca-bundle.crt /host/etc/pki/ca-trust/source/anchors chroot /host update-ca-trust extract if chroot /host systemctl is-enabled coreos-update-ca-trust.service; then chroot /host systemctl restart coreos-update-ca-trust.service fi chroot /host systemctl restart crio.service; fi # Keep container running to maintain daemonset pod sleep inf EOF kubectl delete cm -n kube-system openshift-config-user-ca-script --ignore-not-found kubectl create cm -n kube-system --from-file openshift-config-user-ca-script.sh openshift-config-user-ca-script -
Creare il daemonset che esegue lo script su tutti i nodi.
OCP_REGISTRY_ENDPOINT=$(kubectl get pod -n kube-system -l k8s-app=kube-apiserver-proxy -o json | jq -r '.items[0].spec.containers[0].image | select( . != null )' | awk -F/ '{ print $1 }') if [[ -z "${OCP_REGISTRY_ENDPOINT}" ]]; then OCP_REGISTRY_ENDPOINT=$(kubectl get pod -n kube-system -l app=ibm-master-proxy-static -o json | jq -r '.items[0].spec.containers[0].image | select( . != null )' | awk -F/ '{ print $1 }') fi OCP_VERSION=$(oc version -o json | jq -r .openshiftVersion) kubectl apply -f - <<EOF --- apiVersion: apps/v1 kind: DaemonSet metadata: name: update-openshift-config-user-ca-bundle namespace: kube-system labels: app: update-openshift-config-user-ca-bundle spec: selector: matchLabels: app: update-openshift-config-user-ca-bundle template: metadata: labels: app: update-openshift-config-user-ca-bundle spec: containers: - command: ["/bin/bash", "-c", "/tmp/openshift-config-user-ca-script/openshift-config-user-ca-script.sh"] image: ${OCP_REGISTRY_ENDPOINT}/armada-master/ocp-release-${OCP_VERSION}-x86_64:cli imagePullPolicy: IfNotPresent name: update-openshift-config-user-ca-bundle resources: requests: cpu: 1m memory: 1Mi securityContext: privileged: true volumeMounts: - name: host-volume mountPath: /host - name: openshift-config-user-ca-bundle mountPath: /tmp/openshift-config-user-ca-bundle - name: openshift-config-user-ca-script mountPath: /tmp/openshift-config-user-ca-script hostIPC: true hostNetwork: true hostPID: true tolerations: - operator: Exists volumes: - name: host-volume hostPath: path: / type: Directory - name: openshift-config-user-ca-bundle configMap: name: openshift-config-user-ca-bundle - name: openshift-config-user-ca-script configMap: name: openshift-config-user-ca-script defaultMode: 0755 EOF kubectl rollout status ds -n kube-system update-openshift-config-user-ca-bundle -
Verificate che la CA affidabile sia stata installata controllando i log di daemonset.
oc logs -n kube-system -l app=update-openshift-config-user-ca-bundle --tail=-1
Al termine del daemonset, la CA affidabile è installata su tutti i nodi worker e il cluster può estrarre le immagini dai registri che utilizzano i certificati firmati dalla CA personalizzata.