11.4. 创建应用程序以使用此 secret
运行以下命令来创建 OpenShift 项目:
$ oc new-project my-application
运行以下命令,注解 default 服务帐户以使用 STS 角色:
$ oc annotate -n my-application serviceaccount default \ eks.amazonaws.com/role-arn=$ROLE_ARN
运行以下命令,创建 secret 供应商类以访问我们的 secret:
$ cat << EOF | oc apply -f - apiVersion: secrets-store.csi.x-k8s.io/v1 kind: SecretProviderClass metadata: name: my-application-aws-secrets spec: provider: aws parameters: objects: | - objectName: "MySecret" objectType: "secretsmanager" EOF
使用以下命令中的 secret 创建部署:
$ cat << EOF | oc apply -f - apiVersion: v1 kind: Pod metadata: name: my-application labels: app: my-application spec: volumes: - name: secrets-store-inline csi: driver: secrets-store.csi.k8s.io readOnly: true volumeAttributes: secretProviderClass: "my-application-aws-secrets" containers: - name: my-application-deployment image: k8s.gcr.io/e2e-test-images/busybox:1.29 command: - "/bin/sleep" - "10000" volumeMounts: - name: secrets-store-inline mountPath: "/mnt/secrets-store" readOnly: true EOF
运行以下命令验证 pod 是否挂载了 secret:
$ oc exec -it my-application -- cat /mnt/secrets-store/MySecret