[在k8s讨论论坛上交叉发布-道歉,如果认为这是错误的形式。]
问候!
通过Kubernetes The Hard Way建立了一个新的1.13.3群集,再加上TLS引导的其他配置,我正在努力获得kubelet 服务器证书的自动批准。客户端证书可以正常启动,并且kubelet-> apiserver通信正常运行,但是apiserver-> kubelet通信是当前的问题。
服务器证书正在申请中,但由于需要手动干预而被卡住,而且我无法像客户端CSR那样自动确定自动批准服务器CSR所需的RBAC规定。
以下是CSR(刚刚重新初始化集群后):
NAME AGE REQUESTOR CONDITION
csr-m7rjs 4s system:node:k8s-lab3-worker1 Pending
node-csr-aTpBsagYzYaZYJM6iGMN5AvqzVXATDj1BrmZs_dZCJA 5s system:bootstrap:ec5591 Approved,Issued
此时,很明显apiserver-> kubelet通信(通过kubectl exec
或logs
)失败。如果我手动批准证书,则一切正常。
同时发布客户端和服务器CSR的事实使我相信正确配置了kubelet(加上手动批准的事实)。
触发我的间谍意识的主要因素是,当apiserver首次启动时,我看到:
Feb 6 00:14:13 k8s-lab3-controller1[3495]: I0206 00:14:13.697030 3495 storage_rbac.go:187] created clusterrole.rbac.authorization.k8s.io/system:certificates.k8s.io:certificatesigningrequests:nodeclient
Feb 6 00:14:13 k8s-lab3-controller1[3495]: I0206 00:14:13.706561 3495 storage_rbac.go:187] created clusterrole.rbac.authorization.k8s.io/system:certificates.k8s.io:certificatesigningrequests:selfnodeclient
用于客户端证书签名的群集角色由apiserver自动创建。但是不会自动创建certificatesigningrequests:selfnodeserver。这是否表明实际上没有实施或支持对服务器证书的自动批准?
好吧,我是手动创建的:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: system:certificates.k8s.io:certificatesigningrequests:selfnodeserver
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
rules:
- apiGroups: ["certificates.k8s.io"]
resources: ["certificatesigningrequests/selfnodeserver"]
verbs: ["create"]
然后将角色绑定到system:nodes组:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: auto-approve-server-renewals-for-nodes
subjects:
- kind: Group
name: system:nodes
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: system:certificates.k8s.io:certificatesigningrequests:selfnodeserver
apiGroup: rbac.authorization.k8s.io
并且可以肯定的是,system:nodes是与服务器CSR相关的组之一:
$ kubectl get csr csr-m7rjs -o template --template {{.spec.groups}}
[system:nodes system:authenticated]
我已经尝试了几个小时的从堆栈溢出进行复制和粘贴的黑带级别(大多数建议实际上适用于旧版本的Kubernetes)都没有用。我希望这里的大脑信任能够发现我做错了什么。
如果相关的话,这就是我启动apiserver的方式(再次是v1.13.3,所以我是):
/usr/local/bin/kube-apiserver \
--advertise-address=172.24.22.168 \
--allow-privileged=true \
--anonymous-auth=false \
--apiserver-count=3 \
--audit-log-maxage=30 \
--audit-log-maxbackup=10 \
--audit-log-maxsize=100 \
--audit-log-path=/var/log/audit.log \
--authorization-mode=Node,RBAC \
--bind-address=0.0.0.0 \
--client-ca-file=/etc/kubernetes/pki/ca.crt \
--enable-admission-plugins=Initializers,NamespaceLifecycle,NodeRestriction,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,AlwaysPullImages,DenyEscalatingExec,SecurityContextDeny,EventRateLimit \
--admission-control-config-file=/etc/kubernetes/admissionconfig.yaml \
--enable-bootstrap-token-auth=true \
--enable-swagger-ui=true \
--etcd-cafile=/etc/kubernetes/pki/ca.crt \
--etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt \
--etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key \
--etcd-servers=https://172.24.22.168:2379 \
--event-ttl=1h \
--encryption-provider-config=/etc/kubernetes/encryption-config.yaml \
--feature-gates=RotateKubeletServerCertificate=true \
--insecure-port=0 \
--kubelet-certificate-authority=/etc/kubernetes/pki/ca.crt \
--kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt \
--kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key \
--kubelet-https=true \
--profiling=false \
--repair-malformed-updates=false \
--runtime-config=api/all \
--service-account-lookup=true \
--service-account-key-file=/etc/kubernetes/pki/sa.crt \
--service-cluster-ip-range=10.32.0.0/24 \
--service-node-port-range=30000-32767 \
--tls-cert-file=/etc/kubernetes/pki/apiserver.crt \
--tls-cipher-suites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_GCM_SHA256 \
--tls-private-key-file=/etc/kubernetes/pki/apiserver.key \
--v=2
(鉴于RotateKubeletServerCertificate从1.12版本开始默认为true,我认为--feature-gates参数是多余的,但我碰巧将其保留了。)
非常感谢您可能提供的帮助。