我正在嘗試為我的 kubernetes 集群使用作業流身份。我已經在一個新的命名空間上創建了服務帳戶。我的問題是,當我嘗試在 pod 部署 YML 上添加服務帳戶名稱時,我無法指定名稱空間。
以下是我的 pod spect 檔案:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-scheduler
spec:
replicas: 1
selector:
matchLabels:
app: test-scheduler
template:
metadata:
labels:
app: test-scheduler
spec:
serviceAccountName: test-na/test-k8-sa
nodeSelector:
iam.gke.io/gke-metadata-server-enabled: "true"
containers:
- name: test-scheduler
image: gcr.io/PROJECT_ID/IMAGE:TAG
ports:
- name: scheduler-port
containerPort: 8002
protocol: TCP
env:
- name: NAMESPACE
value: test-scheduler
- name: CONTAINER_NAME
value: test-scheduler
---
apiVersion: v1
kind: Service
metadata:
name: test-scheduler
spec:
selector:
app: test-scheduler
ports:
- port: 8002
protocol: TCP
targetPort: scheduler-port
當我使用 github 操作部署此代碼時,我收到此錯誤:
The Deployment "test-scheduler" is invalid: spec.template.spec.serviceAccountName: Invalid value: "test-na/test-k8-sa": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.',
當我在這樣的檔案中洗掉命名空間時:
serviceAccountName: test-k8-sa
它在默認名稱空間上搜索服務帳戶并失敗。
我的問題是在 kubernetes 中使用服務帳戶指定自定義命名空間的正確方法是什么?
我可以開始使用默認值,但我傾向于保留名稱空間。我看到了一些對服務帳戶檔案的參考,但我真的不明白如何使用它們。
順便說一句,我正在使用本指南https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#gcloud_3
uj5u.com熱心網友回復:
...I have created the service account on a new namespace. My issue is that I am not able to specify the name space when I am trying to add the service account name on the pod deployment YML.
要將創建的服務帳戶分配給您的部署,您可以在與服務帳戶相同的命名空間中創建部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-scheduler
namespace: test-na # <-- add this line with the namespace where the service account resides
spec:
...
template:
...
spec:
serviceAccountName: test-k8-sa
...
uj5u.com熱心網友回復:
您可以默認創建一個服務帳戶并將其附加到 Role 和Biding到另一個命名空間
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: reader-default
namespace: <Namespace - 2>
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-reader
subjects:
- kind: ServiceAccount
name: default-service-account
namespace: <ANOTHER NAMESPACE OR DEFAULT>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/485721.html
