題目:建立 service account (名稱: ithome),透過 cluster role (名稱: ithome-role) 授予此Service account權限能在叢集內list, get 及 watch Pods,其綁定物件 ClusterRoleBinding(名稱: ithome-role-binding),最後建立pod (名稱: ithome),使用image:nginx及service account(ithome)於預設的namespace
列出需建立的objects,被依賴的事物先建立,選擇以命令式的指令處理,這樣通常能加快完成時間,若需較豐富選項則輔以敘述式文件處理
kubectl create serviceaccount ithome
kubectl create clusterrole ithome-role --verb=get,list,watch --resource=pods
-h
取得指令說明kubectl create clusterrolebinding ithome-role-binding --clusterrole=ithome-role --serviceaccount=default:ithome
kubectl run ithome --image=nginx --dry-run=client -o yaml > ithome-pod.yaml
vi ithome-pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: ithome
name: ithome
spec:
serviceAccountName: ithome # 新增此欄位
containers:
- image: nginx
name: ithome
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
kubectl apply -f ithome-pod.yaml