您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何配置Kubernetes集群安全,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
這兩天在梳理Kubernetes集群的安全配置,涉及到各個組件的配置,最終決定畫一個圖來展現,應該會更清晰。
涉及以下配置:
其他各個組件作為client,訪問kube-apiserver時,各個組件的配置,參考圖中黑色線條對應的配置:
- **kube-apiserver** ```
--secure-port=443 --client_ca_file=/var/run/kubernetes/dd_ca.crt --tls-private-key-file=/var/run/kubernetes/dd_server.key ```
kube-controller-manager
``` --kubeconfig=/etc/kubernetes/cmkubeconfig apiVersion: v1 kind: Config users - name: controllermanager user: client-certificate: /var/run/kubernetes/dd_cs_client.crt client-key: /var/run/kubernetes/dd_cs_client.key clusters: - name: local cluster: certificate-authority: /var/run/kubernetes/dd_ca.crt contexts: - context: cluster: local user: controllermanager name: my-context current-context: my-context ```
kube-scheduler kube-scheduler訪問apiserver的安全配置同kube-controller-manager。
kubelet
--kubeconfig=/var/lib/kubelet/kubeconfig apiVersion: v1 kind: Config users: - name: kubelet user: client-certificats: /home/dd_kubelet_client.crt client-key: /home/dd_kubelet_client.key clusters: - name: local cluster: certificate-authority: /home/dd_ca.crt contexts: - context: cluster: local user: kubelet name: my-context current-context: my-context
kube-proxy
--kubeconfig=/var/lib/kubeproxy/proxykubeconfig apiVersion: v1 kind: Config users: - name: kubeproxy user: client-certificate: /home/dd_kubelet_client.crt client-key: /home/dd_kubelet_client.key clusters: - name: local cluster: certificate-authority: /home/dd_ca.crt contexts: - context: cluster: local user: kubeproxy name: my-context current-context: my-context
kube-apiserver作為client,訪問kubelet server時的配置,參考圖中綠色線條對應的配置:
kube-apiserver
--kubelet-https --kubelet-certificate-authority=/var/run/kubelet/kubelet-ca.crt --kubelet-client-certificate=/var/run/kubelet/apiserver-kubelet.crt --kubelet-client-key=/var/run/kubelet/apiserver-kubelet.key
kubelet
--client-ca-file=/var/run/kubelet/kubelet_ca.crt --tls-private-key-file=/var/run/kubelet/server.key --tls-cert-file string=/var/run/kubelet/server.crt
Pod訪問kube-apiserver,是通過ServiceAccount來提供Token的, 涉及的配置見粉紅色線條對應的內容。
每個namespace都有一個default
ServiceAccount。如果Pod.Spec.serivceAccountName未設置,這默認用default
ServiceAccount。上圖中的配置中,給Pod指明了一個自定義的Pod.Spec.serivceAccountName:build-rebot
, automountServiceAccountToken: true
表示自動將該ServiceAccount中的Secret定義的token,ca.crt,namespace掛載到Pod每個container內的以下對應目錄:
ServiceAccount Admission Make Sure Secret Volume Mounted:
Pod.Spec
/var/run/secrets/kubernetes.io/serviceaccount/token /var/run/secrets/kubernetes.io/serviceaccount/ca.crt /var/run/secrets/kubernetes.io/serviceaccount/namespace ```
- **kube-controller-manager** ``` --root-ca-file=/var/run/kubernetes/dd_ca.crt --service-account-private-key-file=/var/run/kubernetes/dd_server.key ```
這樣Pod內的應用就能通過以下兩種方式訪問apiserver了:
- 添加kubectl proxy container,示例見[kubectl-container](https://github.com/kubernetes/kubernetes/tree/master/examples/kubectl-container/) - use the Go client library, and create a client using the rest.InClusterConfig() and kubernetes.NewForConfig() functions. They handle locating and authenticating to the apiserver. [example](https://github.com/kubernetes/client-go/blob/master/examples/in-cluster/main.go)
4. kube-apiserver作為client,通過TLS訪問etcd對應的配置見圖中藍色線條對應的內容。
- **kube-apiserver** ``` --kubelet-https --kubelet-certificate-authority=/var/run/kubelet/etcd-ca.crt --kubelet-client-certificate=/var/run/kubelet/etcd-kubelet.crt --kubelet-client-key=/var/run/kubelet/etcd-kubelet.key ``` - **etcd** ``` --client-cert-auth --trusted-ca-file=/etc/ssl/etcd/etcd-ca.crt --cert-file=/etc/ssl/etcd/server.crt --key-file=/etc/ssl/etcd/server.key ```
apiserver的Authentication Config:
其中token-auth-file
對應文件內容格式為:
``` token1,user1,uid1,”group1,group2,group3" token2,user2,uid2,”group1,group2" ```
basic-auth-file
對應文件內容格式為:
``` password1,user1,uid1,”group1,group2,group3" password2,user2,uid2,”group1,group2,group3" ```
kube-apiserver 以下三個flag,分別表示enable apiserver的x509 client certs, static token, static password三種認證方式。
--client-ca-file=/var/run/kubernetes/dd_ca.crt --token-auth-file=SOMEFILE --basic-auth-file=SOMEFILE
apiserver的Authorization Config:
kube-apiserver 當前我們的環境中,使用默認值AlwaysAllow
,如果有需要,后續會考慮enable RBAC
。
--authorization-mode=AlwaysAllow
apiserver的Admission Control Config:
kube-apiserver 使用官方推薦的,v1.6+之后的配置為:
--admission-control=NamespaceLifecycle, LimitRanger, ServiceAccount, PersistentVolumeLabel, DefaultStorageClass, ResourceQuota, DefaultTolerationSeconds
關于“如何配置Kubernetes集群安全”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。