You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

6.0 KiB

创建一个只读用户

创建证书

mkdir temp
cd temp
USER=viewer
openssl genrsa -out ${USER}.key 2048
openssl req -new -key ${USER}.key -out ${USER}.csr -subj "/CN=${USER}"
openssl x509 -req -in ${USER}.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out ${USER}.crt -days 365

创建用户

kubectl create clusterrolebinding kubernetes-viewer --clusterrole=view --user=${USER}

修改配置

cp -a ~/.kube/config ./config
vim config

config示例, 替换其中的${USER}为你的用户名,替换client-certificate-dataclient-key-data为对应值

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeE1Ea3hNekE1TWprek4xb1hEVE14TURreE1UQTVNamt6TjFvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTW4wCmZlaUZuR1pvVjZEVGpabk5zME5UN2ZaRzd4UDQrOVF1eDd6MnRCZ0swVkVzRFhVUEx6VE4wLzNVdXdWaDFYeGwKRmJFNEQrcUJYVjFwLzU1TVBUcGRQWjBQdzVUZlN5NFp6bm1vOTY5cHorNW9OVmtjQnVIMFJFbzB6NjcxNDFYZQphcXFIZnNVcWx4QWJvWUxsV3FoWkp2Sm9JZlBFYXFObE5xUitaaFhmWkhXY0pCRC9OQTB2dXNtVmszVzRTV3VECnF2QUt1MHBVT0RKTnpTcTFpWWx4WG1JUEszNEZQQmVhYnAyb2gxWVMrbVVmNUZMcnM5T05hSUkwSEMyQ3VKRDgKcGtIOTJaakNhT3RrSTVZajcxcEZ0YytQcGQwN0d2OS9DTUxpbGgxSGlwbVBEM2lwMkFUSlFSb01tSnFrcjgvRQpxMjBYbUlkNFh4YXphd1gxR0o4Q0F3RUFBYU5aTUZjd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZQNndyYlBTc2xyWUhxUGMxU25vbTJWdk4rV3hNQlVHQTFVZEVRUU8KTUF5Q0NtdDFZbVZ5Ym1WMFpYTXdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBRkRSaTR5ZXNHKzlTWk10cy9lcAoxcXdIdnBQOUpraHRXbnBlTndaRzlzcU1BSW9TeHcvK01CNXh4RXRnSzhqTk00NzFvWmxVV3IzZ01vTGNmUUVMCmtvVHNTNTgwV1ZXd1pOODd1QnBqV3I0dWdEWmJoalBBM0hRcVdJdTNMYmd1WUJJdmlVOTFoZU5UKzlFYk9qSlgKVXFwamlnbmw1QVZkSThhYmxNcHZEUnBDZ0lFQjRVQnN4R21BU3BZaTJtSmVqSVNUbTR4U1lGdnZVcC80Q1JzaQpBNUZ4b1FvSjN5MUJHam45a0ZCQ0E0UzFFUlFPMWRFZUhDRVZwQnlRRFhIa0pGb0VZZHBtSTNEYjgvMmlUSTNDCkFSUzBPdGVVejd6Y2tGYzNsbnVxUUtzUnE5V0JQWXdtWlN5ZFZ0dmo2NVZEcVhycWwvVWZOWjFSdTlwU25kQlUKL09rPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://10.0.1.43:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: ${USER}
  name: ${USER}@kubernetes
current-context: ${USER}@kubernetes
kind: Config
preferences: {}
users:
- name: intbee
  user:
    # data from result of command: cat ${USER}.crt | base64 --wrap=0
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNyVENDQVpVQ0ZIRDQwd25lbzJCR2RKUGZjWEdwMjV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