Kubernetes ServiceAccount的配置


開始配置Kubernetes集群的時候為了少出問題,都是在apiserver配置中去掉ServiceAccount采用非安全連接的方式,但在后面配置FEK日志的過程中,很多時候繞不開這個安全機制,但因為開始在centos上安裝是通過yum的方式,所以那些ca.crt,server.crt,kubecfg.key等文件都是沒有的。自己手工去建了好幾次最后都有一些問題。

本文是基於git-hub中make-ca-cert方式自己建立,方法如下:

先把github中kubernetes代碼都下栽到master本地。

# git clone https://github.com/kubernetes/kubernetes


修改make-ca-cert.sh,將第30行修改為kube(基於kube的組進行啟動)

# update the below line with the group that exists on Kubernetes Master.
/* Use the user group with which you are planning to run kubernetes services */
cert_group=${CERT_GROUP:-kube}

運行make-ca-cert.sh

# cd kubernetes/cluster/saltbase/salt/generate-cert/

bash make-ca-cert.sh "192.168.0.105" "IP:192.168.0.105,IP:10.254.0.1,DNS:kubernetes,DNS:kubernetes.default,DNS:kubernetes.default.svc,DNS:kubernetes.default.svc.cluster.local"

 


這里192.168.0.105是master節點的ip,這種方式有個問題是master的ip變化的化證書可能有問題。不知道是否支持主機名設置。

 運行完后發現在/srv/kubernetes目錄下已經把相關的key都生成了,把這些key考到所有的minion節點的相同目錄。

 

然后配置/etc/kubernetes/apiserver

KUBE_API_ARGS="--secure-port=443 --client-ca-file=/srv/kubernetes/ca.crt --tls-cert-file=/srv/kubernetes/server.cert --tls-private-key-file=/srv/kubernetes/server.key"

 

配置/etc/kubernetes/controller-manager

KUBE_CONTROLLER_MANAGER_ARGS="--root-ca-file=/srv/kubernetes/ca.crt --service-account-private-key-file=/srv/kubernetes/server.key"

 

啟動master和minion完成

On Master:
systemctl enable kube-apiserver
systemctl start kube-apiserver
systemctl enable kube-controller-manager
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kube-scheduler
systemctl enable flanneld
systemctl start flanneld
 
Minions:
systemctl enable kube-proxy
systemctl start kube-proxy
systemctl enable kubelet
systemctl start kubelet
systemctl enable flanneld
systemctl start flanneld
systemctl enable docker
systemctl start docker
 
啟動kube-apiserver的時候,如果是通過systemctl來啟動的,可以在/etc/log/messages中看到啟動日志
啟動日志如下:

May 24 08:07:09 k8s-master pulseaudio[3094]: [alsa-sink-Intel ICH] alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
May 24 08:07:09 k8s-master pulseaudio[3094]: [alsa-sink-Intel ICH] alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_intel8x0'. Please report this issue to the ALSA developers.
May 24 08:07:09 k8s-master pulseaudio[3094]: [alsa-sink-Intel ICH] alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
May 24 08:07:47 k8s-master systemd: Starting Kubernetes API Server...
May 24 08:07:47 k8s-master kube-apiserver: Flag --port has been deprecated, see --insecure-port instead.
May 24 08:07:47 k8s-master kube-apiserver: I0524 08:07:47.680379 4239 config.go:562] Will report 192.168.0.105 as public IP address.
May 24 08:07:47 k8s-master kube-apiserver: E0524 08:07:47.726082 4239 reflector.go:199] k8s.io/kubernetes/plugin/pkg/admission/resourcequota/resource_access.go:83: Failed to list *api.ResourceQuota: Get http://0.0.0.0:8080/api/v1/resourcequotas?resourceVersion=0: dial tcp 0.0.0.0:8080: getsockopt: connection refused
May 24 08:07:47 k8s-master kube-apiserver: E0524 08:07:47.726161 4239 reflector.go:199] k8s.io/kubernetes/plugin/pkg/admission/serviceaccount/admission.go:119: Failed to list *api.Secret: Get http://0.0.0.0:8080/api/v1/secrets?fieldSelector=type%3Dkubernetes.io%2Fservice-account-token&resourceVersion=0: dial tcp 0.0.0.0:8080: getsockopt: connection refused
May 24 08:07:47 k8s-master kube-apiserver: E0524 08:07:47.726207 4239 reflector.go:199] k8s.io/kubernetes/plugin/pkg/admission/serviceaccount/admission.go:103: Failed to list *api.ServiceAccount: Get http://0.0.0.0:8080/api/v1/serviceaccounts?resourceVersion=0: dial tcp 0.0.0.0:8080: getsockopt: connection refused
May 24 08:07:47 k8s-master kube-apiserver: [restful] 2017/05/24 08:07:47 log.go:30: [restful/swagger] listing is available at https://192.168.0.105:443/swaggerapi/
May 24 08:07:47 k8s-master kube-apiserver: [restful] 2017/05/24 08:07:47 log.go:30: [restful/swagger] https://192.168.0.105:443/swaggerui/ is mapped to folder /swagger-ui/
May 24 08:07:47 k8s-master kube-apiserver: E0524 08:07:47.902354 4239 reflector.go:199] pkg/controller/informers/factory.go:89: Failed to list *api.Namespace: Get http://0.0.0.0:8080/api/v1/namespaces?resourceVersion=0: dial tcp 0.0.0.0:8080: getsockopt: connection refused
May 24 08:07:47 k8s-master kube-apiserver: E0524 08:07:47.902419 4239 reflector.go:199] pkg/controller/informers/factory.go:89: Failed to list *api.LimitRange: Get http://0.0.0.0:8080/api/v1/limitranges?resourceVersion=0: dial tcp 0.0.0.0:8080: getsockopt: connection refused
May 24 08:07:47 k8s-master systemd: Started Kubernetes API Server.
May 24 08:07:47 k8s-master kube-apiserver: I0524 08:07:47.923462 4239 serve.go:95] Serving securely on 0.0.0.0:443
May 24 08:07:47 k8s-master kube-apiserver: I0524 08:07:47.923542 4239 serve.go:109] Serving insecurely on 0.0.0.0:8080

 

我對這個Failed to list *api.Secret的錯誤查了半天網上的材料想要消除,但后來看起來應該沒有太大影響.

如果通過systemctl 啟動不成功,可能嘗試命令行啟動.

APIServer和Controller Manager的命令行啟動方式

/usr/bin/kube-apiserver --logtostderr=true --v=0 --etcd-servers=http://k8s-master:2379 --address=192.168.0.105 --port=8080 --kubelet-port=10250 --allow-privileged=true --service-cluster-ip-range=10.254.0.0/16 --admission-control=ServiceAccount --insecure-bind-address=192.168.0.105 --client-ca-file=/srv/kubernetes/ca.crt --tls-cert-file=/srv/kubernetes/server.cert --tls-private-key-file=/srv/kubernetes/server.key --secure-port=443 
 
/usr/bin/kube-controller-manager --logtostderr=true --v=0 --master=http://k8s-master:8080 --root-ca-file=/srv/kubernetes/ca.crt --service-account-private-key-file=/srv/kubernetes/server.key
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM