简体   繁体   English

如何使用 Kubernetes 版本 1.24 为服务帐户创建密钥

[英]How to create a secret for service account using Kubernetes version 1.24

I am using Kubernetes version 1.24, I have created a secret for my service account manually, but when I run kubectl get serviceaccounts , it is showing that I do not have any secrets for that service account?我正在使用 Kubernetes 版本 1.24,我手动为我的服务帐户创建了一个密码,但是当我运行kubectl get serviceaccounts时,它显示我没有该服务帐户的任何密码?

When creating a secret manually, it needs to be manually added to the ServiceAccount .手动创建secret时,需要手动添加到ServiceAccount中。 You can use kubectl edit for this.您可以为此使用kubectl edit

If you are creating the secret manually you have to manually add the secret to the service account .如果您手动创建密钥,则必须手动将密钥添加到服务帐户

You can edit the existing service account using the command kubectl edit sa <name of sa> or else create the YAML and reapply the changes to configure those.您可以使用命令kubectl edit sa <name of sa>编辑现有服务帐户,或者创建 YAML 并重新应用更改来配置它们。

However, if you are creating the ServiceAccount it will auto-generate the secret token.但是,如果您正在创建ServiceAccount ,它将自动生成秘密令牌。

bash-4.2$ kubectl get sa
NAME      SECRETS   AGE
default   1         11d
bash-4.2$ kubectl create sa test  
serviceaccount/test created
bash-4.2$ kubectl get secret
NAME                  TYPE                                  DATA   AGE
default-token-dvgd8   kubernetes.io/service-account-token   3      11d
test-token-k6dpd      kubernetes.io/service-account-token   3      7s
bash-4.2$ kubectl get sa
NAME      SECRETS   AGE
default   1         11d
test      1         59s
bash-4.2$ 

Update更新

If you are on K8s version 1.24如果您使用的是 K8s 版本1.24

The serviceaccount won't create the secret automatically. serviceaccount不会自动创建密钥。

You have to create it manually.您必须手动创建它。

Example :示例

apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
  name: token-secret
  annotations:
    kubernetes.io/service-account.name: "<SA name>"

If you just want to create the token you can use the: kubectl create token <Name>如果您只想创建令牌,可以使用: kubectl create token <Name>

Read more about it: https://itnext.io/big-change-in-k8s-1-24-about-serviceaccounts-and-their-secrets-4b909a4af4e0阅读更多相关信息: https://itnext.io/big-change-in-k8s-1-24-about-serviceaccounts-and-their-secrets-4b909a4af4e0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM