2017-08-21 17:44:43 +08:00
<!DOCTYPE HTML>
< html lang = "zh-cn" >
< head >
< meta charset = "UTF-8" >
< meta content = "text/html; charset=utf-8" http-equiv = "Content-Type" >
< title > 3.3.1 管理集群中的TLS · Kubernetes Handbook< / title >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" / >
< meta name = "description" content = "" >
< meta name = "generator" content = "GitBook 3.2.2" >
< meta name = "author" content = "Jimmy Song" >
< link rel = "stylesheet" href = "../gitbook/style.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-splitter/splitter.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-page-toc-button/plugin.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-image-captions/image-captions.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-search-plus/search.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-highlight/website.css" >
< link rel = "stylesheet" href = "../gitbook/gitbook-plugin-fontsettings/website.css" >
< meta name = "HandheldFriendly" content = "true" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1, user-scalable=no" >
< meta name = "apple-mobile-web-app-capable" content = "yes" >
< meta name = "apple-mobile-web-app-status-bar-style" content = "black" >
< link rel = "apple-touch-icon-precomposed" sizes = "152x152" href = "../gitbook/images/apple-touch-icon-precomposed-152.png" >
< link rel = "shortcut icon" href = "../gitbook/images/favicon.ico" type = "image/x-icon" >
2017-08-21 18:44:34 +08:00
< link rel = "next" href = "kubelet-authentication-authorization.html" / >
2017-08-21 17:44:43 +08:00
< link rel = "prev" href = "cluster-management.html" / >
< / head >
< body >
< div class = "book" >
< div class = "book-summary" >
< div id = "book-search-input" role = "search" >
< input type = "text" placeholder = "輸入並搜尋" / >
< / div >
< nav role = "navigation" >
< ul class = "summary" >
< li class = "chapter " data-level = "1.1" data-path = "../" >
< a href = "../" >
1. 前言
< / a >
< / li >
< li class = "chapter " data-level = "1.2" data-path = "../concepts/" >
< a href = "../concepts/" >
2. 概念原理
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.2.1" data-path = "../concepts/concepts.html" >
< a href = "../concepts/concepts.html" >
2.1 设计理念
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2" data-path = "../concepts/objects.html" >
< a href = "../concepts/objects.html" >
2.2 主要概念
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.2.2.1" data-path = "../concepts/pod-overview.html" >
< a href = "../concepts/pod-overview.html" >
2.2.1 Pod
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.2.2.1.1" data-path = "../concepts/pod.html" >
< a href = "../concepts/pod.html" >
2.2.1.1 Pod解析
< / a >
2017-08-31 23:28:33 +08:00
< / li >
< li class = "chapter " data-level = "1.2.2.1.2" data-path = "../concepts/init-containers.html" >
< a href = "../concepts/init-containers.html" >
2.2.1.2 Init容器
< / a >
2017-08-21 17:44:43 +08:00
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.2.2.2" data-path = "../concepts/node.html" >
< a href = "../concepts/node.html" >
2.2.2 Node
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.3" data-path = "../concepts/namespace.html" >
< a href = "../concepts/namespace.html" >
2.2.3 Namespace
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.4" data-path = "../concepts/service.html" >
< a href = "../concepts/service.html" >
2.2.4 Service
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.5" data-path = "../concepts/volume.html" >
< a href = "../concepts/volume.html" >
2.2.5 Volume和Persistent Volume
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.6" data-path = "../concepts/deployment.html" >
< a href = "../concepts/deployment.html" >
2.2.6 Deployment
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.7" data-path = "../concepts/secret.html" >
< a href = "../concepts/secret.html" >
2.2.7 Secret
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.8" data-path = "../concepts/statefulset.html" >
< a href = "../concepts/statefulset.html" >
2.2.8 StatefulSet
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.9" data-path = "../concepts/daemonset.html" >
< a href = "../concepts/daemonset.html" >
2.2.9 DaemonSet
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.10" data-path = "../concepts/serviceaccount.html" >
< a href = "../concepts/serviceaccount.html" >
2.2.10 ServiceAccount
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.11" data-path = "../concepts/replicaset.html" >
< a href = "../concepts/replicaset.html" >
2.2.11 ReplicationController和ReplicaSet
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.12" data-path = "../concepts/job.html" >
< a href = "../concepts/job.html" >
2.2.12 Job
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.13" data-path = "../concepts/cronjob.html" >
< a href = "../concepts/cronjob.html" >
2.2.13 CronJob
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.14" data-path = "../concepts/ingress.html" >
< a href = "../concepts/ingress.html" >
2.2.14 Ingress
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.15" data-path = "../concepts/configmap.html" >
< a href = "../concepts/configmap.html" >
2.2.15 ConfigMap
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.16" data-path = "../concepts/horizontal-pod-autoscaling.html" >
< a href = "../concepts/horizontal-pod-autoscaling.html" >
2.2.16 Horizontal Pod Autoscaling
< / a >
< / li >
< li class = "chapter " data-level = "1.2.2.17" data-path = "../concepts/label.html" >
< a href = "../concepts/label.html" >
2.2.17 Label
< / a >
< / li >
< / ul >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.3" data-path = "./" >
< a href = "./" >
3. 用户指南
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.3.1" data-path = "resource-configuration.html" >
< a href = "resource-configuration.html" >
3.1 资源配置
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.3.1.1" data-path = "configure-liveness-readiness-probes.html" >
< a href = "configure-liveness-readiness-probes.html" >
3.1.1 配置Pod的liveness和readiness探针
< / a >
< / li >
< li class = "chapter " data-level = "1.3.1.2" data-path = "configure-pod-service-account.html" >
< a href = "configure-pod-service-account.html" >
3.1.2 配置Pod的Service Account
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.3.2" data-path = "command-usage.html" >
< a href = "command-usage.html" >
3.2 命令使用
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.3.2.1" data-path = "using-kubectl.html" >
< a href = "using-kubectl.html" >
3.2.1 使用kubectl
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.3.3" data-path = "cluster-management.html" >
< a href = "cluster-management.html" >
3.3 集群管理
< / a >
< ul class = "articles" >
< li class = "chapter active" data-level = "1.3.3.1" data-path = "managing-tls-in-a-cluster.html" >
< a href = "managing-tls-in-a-cluster.html" >
3.3.1 管理集群中的TLS
< / a >
2017-08-21 18:44:34 +08:00
< / li >
< li class = "chapter " data-level = "1.3.3.2" data-path = "kubelet-authentication-authorization.html" >
< a href = "kubelet-authentication-authorization.html" >
3.3.2 kubelet的认证授权
< / a >
< / li >
< li class = "chapter " data-level = "1.3.3.3" data-path = "tls-bootstrapping.html" >
< a href = "tls-bootstrapping.html" >
3.3.3 TLS bootstrap
< / a >
2017-08-31 14:23:44 +08:00
< / li >
< li class = "chapter " data-level = "1.3.3.4" data-path = "kubectl-user-authentication-authorization.html" >
< a href = "kubectl-user-authentication-authorization.html" >
3.3.4 kubectl的用户认证授权
< / a >
< / li >
< li class = "chapter " data-level = "1.3.3.5" data-path = "rbac.html" >
< a href = "rbac.html" >
3.3.5 RBAC——基于角色的访问控制
< / a >
2017-08-21 17:44:43 +08:00
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.3.4" data-path = "access-kubernetes-cluster.html" >
< a href = "access-kubernetes-cluster.html" >
3.4 访问 Kubernetes 集群
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.3.4.1" data-path = "access-cluster.html" >
< a href = "access-cluster.html" >
3.4.1 访问集群
< / a >
< / li >
< li class = "chapter " data-level = "1.3.4.2" data-path = "authenticate-across-clusters-kubeconfig.html" >
< a href = "authenticate-across-clusters-kubeconfig.html" >
3.4.2 使用 kubeconfig 文件配置跨集群认证
< / a >
< / li >
< li class = "chapter " data-level = "1.3.4.3" data-path = "connecting-to-applications-port-forward.html" >
< a href = "connecting-to-applications-port-forward.html" >
3.4.3 通过端口转发访问集群中的应用程序
< / a >
< / li >
< li class = "chapter " data-level = "1.3.4.4" data-path = "service-access-application-cluster.html" >
< a href = "service-access-application-cluster.html" >
3.4.4 使用 service 访问群集中的应用程序
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.3.5" data-path = "application-development-deployment-flow.html" >
< a href = "application-development-deployment-flow.html" >
3.5 在kubernetes中开发部署应用
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.3.5.1" data-path = "deploy-applications-in-kubernetes.html" >
< a href = "deploy-applications-in-kubernetes.html" >
3.5.1 适用于kubernetes的应用开发部署流程
< / a >
2017-08-21 18:44:34 +08:00
< / li >
< li class = "chapter " data-level = "1.3.5.2" data-path = "migrating-hadoop-yarn-to-kubernetes.html" >
< a href = "migrating-hadoop-yarn-to-kubernetes.html" >
3.5.2 迁移传统应用到kubernetes中——以Hadoop YARN为例
< / a >
2017-08-21 17:44:43 +08:00
< / li >
< / ul >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.4" data-path = "../practice/" >
< a href = "../practice/" >
4. 最佳实践
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.1" data-path = "../practice/install-kbernetes1.6-on-centos.html" >
< a href = "../practice/install-kbernetes1.6-on-centos.html" >
4.1 在CentOS上部署kubernetes1.6集群
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.1.1" data-path = "../practice/create-tls-and-secret-key.html" >
< a href = "../practice/create-tls-and-secret-key.html" >
4.1.1 创建TLS证书和秘钥
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.2" data-path = "../practice/create-kubeconfig.html" >
< a href = "../practice/create-kubeconfig.html" >
4.1.2 创建kubeconfig文件
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.3" data-path = "../practice/etcd-cluster-installation.html" >
< a href = "../practice/etcd-cluster-installation.html" >
4.1.3 创建高可用etcd集群
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.4" data-path = "../practice/kubectl-installation.html" >
< a href = "../practice/kubectl-installation.html" >
4.1.4 安装kubectl命令行工具
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.5" data-path = "../practice/master-installation.html" >
< a href = "../practice/master-installation.html" >
4.1.5 部署master节点
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.6" data-path = "../practice/node-installation.html" >
< a href = "../practice/node-installation.html" >
4.1.6 部署node节点
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.7" data-path = "../practice/kubedns-addon-installation.html" >
< a href = "../practice/kubedns-addon-installation.html" >
4.1.7 安装kubedns插件
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.8" data-path = "../practice/dashboard-addon-installation.html" >
< a href = "../practice/dashboard-addon-installation.html" >
4.1.8 安装dashboard插件
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.9" data-path = "../practice/heapster-addon-installation.html" >
< a href = "../practice/heapster-addon-installation.html" >
4.1.9 安装heapster插件
< / a >
< / li >
< li class = "chapter " data-level = "1.4.1.10" data-path = "../practice/efk-addon-installation.html" >
< a href = "../practice/efk-addon-installation.html" >
4.1.10 安装EFK插件
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.4.2" data-path = "../practice/service-discovery-and-loadbalancing.html" >
< a href = "../practice/service-discovery-and-loadbalancing.html" >
4.2 服务发现与负载均衡
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.2.1" data-path = "../practice/traefik-ingress-installation.html" >
< a href = "../practice/traefik-ingress-installation.html" >
4.2.1 安装Traefik ingress
< / a >
< / li >
< li class = "chapter " data-level = "1.4.2.2" data-path = "../practice/distributed-load-test.html" >
< a href = "../practice/distributed-load-test.html" >
4.2.2 分布式负载测试
< / a >
< / li >
< li class = "chapter " data-level = "1.4.2.3" data-path = "../practice/network-and-cluster-perfermance-test.html" >
< a href = "../practice/network-and-cluster-perfermance-test.html" >
4.2.3 网络和集群性能测试
< / a >
< / li >
< li class = "chapter " data-level = "1.4.2.4" data-path = "../practice/edge-node-configuration.html" >
< a href = "../practice/edge-node-configuration.html" >
4.2.4 边缘节点配置
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.4.3" data-path = "../practice/operation.html" >
< a href = "../practice/operation.html" >
4.3 运维管理
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.3.1" data-path = "../practice/service-rolling-update.html" >
< a href = "../practice/service-rolling-update.html" >
4.3.1 服务滚动升级
< / a >
< / li >
< li class = "chapter " data-level = "1.4.3.2" data-path = "../practice/app-log-collection.html" >
< a href = "../practice/app-log-collection.html" >
4.3.2 应用日志收集
< / a >
< / li >
< li class = "chapter " data-level = "1.4.3.3" data-path = "../practice/configuration-best-practice.html" >
< a href = "../practice/configuration-best-practice.html" >
4.3.3 配置最佳实践
< / a >
< / li >
< li class = "chapter " data-level = "1.4.3.4" data-path = "../practice/monitor.html" >
< a href = "../practice/monitor.html" >
4.3.4 集群及应用监控
< / a >
< / li >
< li class = "chapter " data-level = "1.4.3.5" data-path = "../practice/jenkins-ci-cd.html" >
< a href = "../practice/jenkins-ci-cd.html" >
4.3.5 使用Jenkins进行持续构建与发布
< / a >
< / li >
< li class = "chapter " data-level = "1.4.3.6" data-path = "../practice/data-persistence-problem.html" >
< a href = "../practice/data-persistence-problem.html" >
4.3.6 数据持久化问题
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.4.4" data-path = "../practice/storage.html" >
< a href = "../practice/storage.html" >
4.4 存储管理
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.4.1" data-path = "../practice/glusterfs.html" >
< a href = "../practice/glusterfs.html" >
4.4.1 GlusterFS
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.4.1.1" data-path = "../practice/using-glusterfs-for-persistent-storage.html" >
< a href = "../practice/using-glusterfs-for-persistent-storage.html" >
4.4.1.1 使用GlusterFS做持久化存储
< / a >
< / li >
< li class = "chapter " data-level = "1.4.4.1.2" data-path = "../practice/storage-for-containers-using-glusterfs-with-openshift.html" >
< a href = "../practice/storage-for-containers-using-glusterfs-with-openshift.html" >
4.4.1.2 在OpenShift中使用GlusterFS做持久化存储
< / a >
2017-09-01 21:04:51 +08:00
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.4.4.2" data-path = "../practice/cephfs.html" >
< a href = "../practice/cephfs.html" >
4.4.2 CephFS
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.4.4.2.1" data-path = "../practice/using-ceph-for-persistent-storage.html" >
< a href = "../practice/using-ceph-for-persistent-storage.html" >
4.4.2.1 使用Ceph做持久化存储
< / a >
2017-08-21 17:44:43 +08:00
< / li >
< / ul >
< / li >
< / ul >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.5" data-path = "../usecases/" >
< a href = "../usecases/" >
5. 领域应用
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.5.1" data-path = "../usecases/microservices.html" >
< a href = "../usecases/microservices.html" >
5.1 微服务架构
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.5.1.1" data-path = "../usecases/istio.html" >
< a href = "../usecases/istio.html" >
5.1.1 Istio
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.5.1.1.1" data-path = "../usecases/istio-installation.html" >
< a href = "../usecases/istio-installation.html" >
5.1.1.1 安装istio
< / a >
< / li >
< li class = "chapter " data-level = "1.5.1.1.2" data-path = "../usecases/configuring-request-routing.html" >
< a href = "../usecases/configuring-request-routing.html" >
5.1.1.2 配置请求的路由规则
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.5.1.2" data-path = "../usecases/linkerd.html" >
< a href = "../usecases/linkerd.html" >
5.1.2 Linkerd
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.5.1.2.1" data-path = "../usecases/linkerd-user-guide.html" >
< a href = "../usecases/linkerd-user-guide.html" >
5.1.2.1 Linkerd 使用指南
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.5.1.3" data-path = "../usecases/service-discovery-in-microservices.html" >
< a href = "../usecases/service-discovery-in-microservices.html" >
5.1.3 微服务中的服务发现
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.5.2" data-path = "../usecases/big-data.html" >
< a href = "../usecases/big-data.html" >
5.2 大数据
< / a >
< ul class = "articles" >
2017-08-30 14:20:52 +08:00
< li class = "chapter " data-level = "1.5.2.1" data-path = "../usecases/spark-standalone-on-kubernetes.html" >
2017-08-21 17:44:43 +08:00
2017-08-30 14:20:52 +08:00
< a href = "../usecases/spark-standalone-on-kubernetes.html" >
2017-08-21 17:44:43 +08:00
2017-08-30 14:20:52 +08:00
5.2.1 Spark standalone on Kubernetes
2017-08-21 17:44:43 +08:00
< / a >
2017-08-31 14:23:44 +08:00
< / li >
< li class = "chapter " data-level = "1.5.2.2" data-path = "../usecases/support-spark-natively-in-kubernetes.html" >
< a href = "../usecases/support-spark-natively-in-kubernetes.html" >
5.2.2 运行支持kubernetes原生调度的Spark程序
< / a >
2017-08-21 17:44:43 +08:00
< / li >
< / ul >
2017-08-30 16:52:33 +08:00
< / li >
< li class = "chapter " data-level = "1.5.3" data-path = "../usecases/serverless.html" >
< a href = "../usecases/serverless.html" >
5.3 Serverless架构
< / a >
2017-08-21 17:44:43 +08:00
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.6" data-path = "../develop/" >
< a href = "../develop/" >
6. 开发指南
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.6.1" data-path = "../develop/developing-environment.html" >
< a href = "../develop/developing-environment.html" >
6.1 开发环境搭建
< / a >
< / li >
< li class = "chapter " data-level = "1.6.2" data-path = "../develop/testing.html" >
< a href = "../develop/testing.html" >
6.2 单元测试和集成测试
< / a >
< / li >
< li class = "chapter " data-level = "1.6.3" data-path = "../develop/client-go-sample.html" >
< a href = "../develop/client-go-sample.html" >
6.3 client-go示例
< / a >
< / li >
< li class = "chapter " data-level = "1.6.4" data-path = "../develop/contribute.html" >
< a href = "../develop/contribute.html" >
6.4 社区贡献
< / a >
< / li >
< / ul >
< / li >
< li class = "chapter " data-level = "1.7" data-path = "../appendix/" >
< a href = "../appendix/" >
7. 附录
< / a >
< ul class = "articles" >
< li class = "chapter " data-level = "1.7.1" data-path = "../appendix/docker-best-practice.html" >
< a href = "../appendix/docker-best-practice.html" >
7.1 Docker最佳实践
< / a >
< / li >
< li class = "chapter " data-level = "1.7.2" data-path = "../appendix/issues.html" >
< a href = "../appendix/issues.html" >
7.2 问题记录
< / a >
< / li >
< li class = "chapter " data-level = "1.7.3" data-path = "../appendix/tricks.html" >
< a href = "../appendix/tricks.html" >
7.3 使用技巧
< / a >
< / li >
< / ul >
< / li >
< li class = "divider" > < / li >
< li >
< a href = "https://www.gitbook.com" target = "blank" class = "gitbook-link" >
本書使用 GitBook 釋出
< / a >
< / li >
< / ul >
< / nav >
< / div >
< div class = "book-body" >
< div class = "body-inner" >
< div class = "book-header" role = "navigation" >
<!-- Title -->
< h1 >
< i class = "fa fa-circle-o-notch fa-spin" > < / i >
< a href = ".." > 3.3.1 管理集群中的TLS< / a >
< / h1 >
< / div >
< div class = "page-wrapper" tabindex = "-1" role = "main" >
< div class = "page-inner" >
< div class = "search-plus" id = "book-search-results" >
< div class = "search-noresults" >
< section class = "normal markdown-section" >
< h1 id = "管理集群中的tls" > 管 理 集 群 中 的 TLS< / h1 >
< p > 在 本 书 的 最 佳 实 践 部 分 , 我 们 在 CentOS上 部 署 了 kuberentes集 群 , 其 中 最 开 始 有 重 要 的 一 步 就 是 创 建 TLS认 证 的 , 查 看 < a href = "../practice/create-tls-and-secret-key.html" > 创 建 TLS证 书 和 秘 钥 < / a > 。 很 多 人 在 进 行 到 这 一 步 是 都 会 遇 到 各 种 各 样 千 奇 百 怪 的 问 题 , 这 一 步 是 创 建 集 群 的 基 础 , 我 们 有 必 要 详 细 了 解 一 下 背 后 的 流 程 和 原 理 。 < / p >
< h2 id = "概览" > 概 览 < / h2 >
< p > 每 个 Kubernetes集 群 都 有 一 个 集 群 根 证 书 颁 发 机 构 ( CA) 。 集 群 中 的 组 件 通 常 使 用 CA来 验 证 API server的 证 书 , 由 API服 务 器 验 证 kubelet客 户 端 证 书 等 。 为 了 支 持 这 一 点 , CA证 书 包 被 分 发 到 集 群 中 的 每 个 节 点 , 并 作 为 一 个 sercret附 加 分 发 到 默 认 service account上 。 或 者 , 你 的 workload可 以 使 用 此 CA建 立 信 任 。 你 的 应 用 程 序 可 以 使 用 类 似 于 < a href = "https://github.com/ietf-wg-acme/acme/" target = "_blank" > ACME草 案 < / a > 的 协 议 , 使 用 < code > certificates.k8s.io< / code > API请 求 证 书 签 名 。 < / p >
< h2 id = "集群中的tls信任" > 集 群 中 的 TLS信 任 < / h2 >
< p > 让 Pod中 运 行 的 应 用 程 序 信 任 集 群 根 CA通 常 需 要 一 些 额 外 的 应 用 程 序 配 置 。 您 将 需 要 将 CA证 书 包 添 加 到 TLS客 户 端 或 服 务 器 信 任 的 CA证 书 列 表 中 。 例 如 , 您 可 以 使 用 golang TLS配 置 通 过 解 析 证 书 链 并 将 解 析 的 证 书 添 加 到 < a href = "https://godoc.org/crypto/tls#Config" target = "_blank" > < code > tls.Config< / code > < / a > 结 构 中 的 < code > Certificates< / code > 字 段 中 , CA证 书 捆 绑 包 将 使 用 默 认 服 务 账 户 自 动 加 载 到 pod中 , 路 径 为 < code > /var/run/secrets/kubernetes.io/serviceaccount/ca.crt< / code > 。 如 果 您 没 有 使 用 默 认 服 务 账 户 , 请 请 求 集 群 管 理 员 构 建 包 含 您 有 权 访 问 使 用 的 证 书 包 的 configmap。 < / p >
< h2 id = "请求认证" > 请 求 认 证 < / h2 >
< p > 以 下 部 分 演 示 如 何 为 通 过 DNS访 问 的 Kubernetes服 务 创 建 TLS证 书 。 < / p >
< h3 id = "步骤0-下载安装ssl" > 步 骤 0. 下 载 安 装 SSL< / h3 >
< p > 下 载 cfssl工 具 : < a href = "https://pkg.cfssl.org/" target = "_blank" > https://pkg.cfssl.org/< / a > .< / p >
< h3 id = "步骤1-创建证书签名请求" > 步 骤 1. 创 建 证 书 签 名 请 求 < / h3 >
< p > 通 过 运 行 以 下 命 令 生 成 私 钥 和 证 书 签 名 请 求 ( 或 CSR) : < / p >
< pre > < code class = "lang-Bash" > $ cat < < EOF | cfssl genkey - | cfssljson -bare server
{
< span class = "hljs-string" > " hosts" < / span > : [
< span class = "hljs-string" > " my-svc.my-namespace.svc.cluster.local" < / span > ,
< span class = "hljs-string" > " my-pod.my-namespace.pod.cluster.local" < / span > ,
< span class = "hljs-string" > " 172.168.0.24" < / span > ,
< span class = "hljs-string" > " 10.0.34.2" < / span >
],
< span class = "hljs-string" > " CN" < / span > : < span class = "hljs-string" > " my-pod.my-namespace.pod.cluster.local" < / span > ,
< span class = "hljs-string" > " key" < / span > : {
< span class = "hljs-string" > " algo" < / span > : < span class = "hljs-string" > " ecdsa" < / span > ,
< span class = "hljs-string" > " size" < / span > : 256
}
}
EOF
< / code > < / pre >
2017-08-21 18:44:34 +08:00
< p > < code > 172.168.0.24< / code > 是 service 的 cluster IP, < code > my-svc.my-namespace.svc.cluster.local< / code > 是 service 的 DNS 名 称 , < code > 10.0.34.2< / code > 是 Pod 的 IP, < code > my-pod.my-namespace.pod.cluster.local< / code > 是 pod 的 DNS 名 称 , 你 可 以 看 到 以 下 输 出 : < / p >
2017-08-21 17:44:43 +08:00
< pre > < code > 2017/03/21 06:48:17 [INFO] generate received request
2017/03/21 06:48:17 [INFO] received CSR
2017/03/21 06:48:17 [INFO] generating key: ecdsa-256
2017/03/21 06:48:17 [INFO] encoded CSR
< / code > < / pre > < p > 此 命 令 生 成 两 个 文 件 ; 它 生 成 包 含 PEM编 码 的 < a href = "https://tools.ietf.org/html/rfc2986" target = "_blank" > pkcs #10< / a > 认 证 请 求 的 < code > server.csr< / code > , 以 及 包 含 仍 然 要 创 建 的 证 书 的 PEM编 码 密 钥 的 < code > server-key.pem< / code > 。 < / p >
< h3 id = "步骤2-创建证书签名请求对象以发送到kubernetes-api" > 步 骤 2. 创 建 证 书 签 名 请 求 对 象 以 发 送 到 Kubernetes API< / h3 >
< p > 使 用 以 下 命 令 创 建 CSR yaml文 件 , 并 发 送 到 API server: < / p >
< pre > < code class = "lang-bash" > $ cat < < EOF | kubectl create < span class = "hljs-_" > -f< / span > -
apiVersion: certificates.k8s.io/v1beta1
kind: CertificateSigningRequest
metadata:
name: my-svc.my-namespace
spec:
groups:
- system:authenticated
request: $(cat server.csr | base64 | tr < span class = "hljs-_" > -d< / span > < span class = "hljs-string" > ' \n' < / span > )
usages:
- digital signature
- key encipherment
- server auth
EOF
< / code > < / pre >
< p > 请 注 意 , 在 步 骤 1中 创 建 的 < code > server.csr< / code > 文 件 是 base64编 码 并 存 储 在 < code > .spec.request< / code > 字 段 中 。 我 们 还 要 求 提 供 “ 数 字 签 名 ” , “ 密 钥 加 密 ” 和 “ 服 务 器 身 份 验 证 ” 密 钥 用 途 的 证 书 。 我 们 < a href = "https://godoc.org/k8s.io/client-go/pkg/apis/certificates/v1beta1#KeyUsage" target = "_blank" > 这 里 < / a > 支 持 列 出 的 所 有 关 键 用 途 和 扩 展 的 关 键 用 途 , 以 便 您 可 以 使 用 相 同 的 API请 求 客 户 端 证 书 和 其 他 证 书 。 < / p >
< p > 在 API server中 可 以 看 到 这 些 CSR处 于 pending状 态 。 执 行 下 面 的 命 令 你 将 可 以 看 到 : < / p >
< pre > < code class = "lang-bash" > $ kubectl describe csr my-svc.my-namespace
Name: my-svc.my-namespace
Labels: < none>
Annotations: < none>
CreationTimestamp: Tue, 21 Mar 2017 07:03:51 -0700
Requesting User: yourname@example.com
Status: Pending
Subject:
Common Name: my-svc.my-namespace.svc.cluster.local
Serial Number:
Subject Alternative Names:
DNS Names: my-svc.my-namespace.svc.cluster.local
IP Addresses: 172.168.0.24
10.0.34.2
Events: < none>
< / code > < / pre >
< h3 id = "步骤3-获取证书签名请求" > 步 骤 3. 获 取 证 书 签 名 请 求 < / h3 >
< p > 批 准 证 书 签 名 请 求 是 通 过 自 动 批 准 过 程 完 成 的 , 或 由 集 群 管 理 员 一 次 完 成 。 有 关 这 方 面 涉 及 的 更 多 信 息 , 请 参 见 下 文 。 < / p >
< h3 id = "步骤4-下载签名并使用" > 步 骤 4. 下 载 签 名 并 使 用 < / h3 >
< p > 一 旦 CSR被 签 署 并 获 得 批 准 , 您 应 该 看 到 以 下 内 容 : < / p >
< pre > < code class = "lang-bash" > $ kubectl get csr
NAME AGE REQUESTOR CONDITION
my-svc.my-namespace 10m yourname@example.com Approved,Issued
< / code > < / pre >
2017-08-21 18:44:34 +08:00
< p > 你 可 以 通 过 运 行 以 下 命 令 下 载 颁 发 的 证 书 并 将 其 保 存 到 < code > server.crt< / code > 文 件 中 : < / p >
2017-08-21 17:44:43 +08:00
< pre > < code class = "lang-bash" > $ kubectl get csr my-svc.my-namespace -o jsonpath=< span class = "hljs-string" > ' {.status.certificate}' < / span > \
| base64 < span class = "hljs-_" > -d< / span > > server.crt
< / code > < / pre >
< p > 现 在 你 可 以 用 < code > server.crt< / code > 和 < code > server-key.pem< / code > 来 做 为 keypair来 启 动 HTTPS server。 < / p >
2017-08-21 18:44:34 +08:00
< h2 id = "批准证书签名请求" > 批 准 证 书 签 名 请 求 < / h2 >
< p > Kubernetes 管 理 员 ( 具 有 适 当 权 限 ) 可 以 使 用 < code > kubectl certificate approve< / code > 和 < code > kubectl certificate deny< / code > 命 令 手 动 批 准 ( 或 拒 绝 ) 证 书 签 名 请 求 。 但 是 , 如 果 您 打 算 大 量 使 用 此 API, 则 可 以 考 虑 编 写 自 动 化 的 证 书 控 制 器 。 < / p >
< p > 如 果 上 述 机 器 或 人 类 使 用 kubectl, 批 准 者 的 作 用 是 验 证 CSR 满 足 如 下 两 个 要 求 : < / p >
< ol >
< li > CSR 的 主 体 控 制 用 于 签 署 CSR 的 私 钥 。 这 解 决 了 伪 装 成 授 权 主 体 的 第 三 方 的 威 胁 。 在 上 述 示 例 中 , 此 步 骤 将 验 证 该 pod 控 制 了 用 于 生 成 CSR 的 私 钥 。 < / li >
< li > CSR 的 主 体 被 授 权 在 请 求 的 上 下 文 中 执 行 。 这 解 决 了 我 们 加 入 群 集 的 我 们 不 期 望 的 主 体 的 威 胁 。 在 上 述 示 例 中 , 此 步 骤 将 是 验 证 该 pod 是 否 被 允 许 加 入 到 所 请 求 的 服 务 中 。 < / li >
< / ol >
< p > 当 且 仅 当 满 足 这 两 个 要 求 时 , 审 批 者 应 该 批 准 CSR, 否 则 拒 绝 CSR。 < / p >
2017-08-21 17:44:43 +08:00
< h2 id = "给集群管理员的一个建议" > 给 集 群 管 理 员 的 一 个 建 议 < / h2 >
< p > 本 教 程 假 设 将 signer设 置 为 服 务 证 书 API。 Kubernetes controller manager提 供 了 一 个 signer的 默 认 实 现 。 要 启 用 它 , 请 将 < code > --cluster-signature-cert-file< / code > 和 < code > — cluster-signing-key-file< / code > 参 数 传 递 给 controller manager, 并 配 置 具 有 证 书 颁 发 机 构 的 密 钥 对 的 路 径 。 < / p >
< footer class = "page-footer-ex" > < span class = "page-footer-ex-copyright" > for GitBook< / span >                       < span class = "page-footer-ex-footer-update" > update
2017-08-21 18:44:34 +08:00
2017-08-21 18:23:34
2017-08-21 17:44:43 +08:00
< / span > < / footer >
< / section >
< / div >
< div class = "search-results" >
< div class = "has-results" >
< h1 class = "search-results-title" > < span class = 'search-results-count' > < / span > results matching "< span class = 'search-query' > < / span > "< / h1 >
< ul class = "search-results-list" > < / ul >
< / div >
< div class = "no-results" >
< h1 class = "search-results-title" > No results matching "< span class = 'search-query' > < / span > "< / h1 >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< a href = "cluster-management.html" class = "navigation navigation-prev " aria-label = "Previous page: 3.3 集群管理" >
< i class = "fa fa-angle-left" > < / i >
< / a >
2017-08-21 18:44:34 +08:00
< a href = "kubelet-authentication-authorization.html" class = "navigation navigation-next " aria-label = "Next page: 3.3.2 kubelet的认证授权" >
2017-08-21 17:44:43 +08:00
< i class = "fa fa-angle-right" > < / i >
< / a >
< / div >
< script >
var gitbook = gitbook || [];
gitbook.push(function() {
2017-09-01 21:04:51 +08:00
gitbook.page.hasChanged({"page":{"title":"3.3.1 管理集群中的TLS","level":"1.3.3.1","depth":3,"next":{"title":"3.3.2 kubelet的认证授权","level":"1.3.3.2","depth":3,"path":"guide/kubelet-authentication-authorization.md","ref":"guide/kubelet-authentication-authorization.md","articles":[]},"previous":{"title":"3.3 集群管理","level":"1.3.3","depth":2,"path":"guide/cluster-management.md","ref":"guide/cluster-management.md","articles":[{"title":"3.3.1 管理集群中的TLS","level":"1.3.3.1","depth":3,"path":"guide/managing-tls-in-a-cluster.md","ref":"guide/managing-tls-in-a-cluster.md","articles":[]},{"title":"3.3.2 kubelet的认证授权","level":"1.3.3.2","depth":3,"path":"guide/kubelet-authentication-authorization.md","ref":"guide/kubelet-authentication-authorization.md","articles":[]},{"title":"3.3.3 TLS bootstrap","level":"1.3.3.3","depth":3,"path":"guide/tls-bootstrapping.md","ref":"guide/tls-bootstrapping.md","articles":[]},{"title":"3.3.4 kubectl的用户认证授权","level":"1.3.3.4","depth":3,"path":"guide/kubectl-user-authentication-authorization.md","ref":"guide/kubectl-user-authentication-authorization.md","articles":[]},{"title":"3.3.5 RBAC——基于角色的访问控制","level":"1.3.3.5","depth":3,"path":"guide/rbac.md","ref":"guide/rbac.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["github","codesnippet","splitter","page-toc-button","image-captions","page-footer-ex","editlink","-lunr","-search","search-plus"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/rootsongjc/kubernetes-handbook"},"editlink":{"label":"编辑本页","multilingual":false,"base":"https://github.com/rootsongjc/kubernetes-handbook/blob/master/"},"page-footer-ex":{"copyright":"for GitBook","update_format":"YYYY-MM-DD HH:mm:ss","update_label":"update"},"splitter":{},"codesnippet":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"page-toc-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{},"image-captions":{"variable_name":"_pictures"}},"page-footer-ex":{"copyright":"Jimmy Song","update_label":"最后更新:","update_format":"YYYY-MM-DD HH:mm:ss"},"theme":"default","author":"Jimmy Song","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[{"backlink":"concepts/index.html#fig1.2.1","level":"1.2","list_caption":"Figure: Borg架构","alt":"Borg架构","nro":1,"url":"../images/borg.png","index":1,"caption_template":"Figure: _CAPTION_","label":"Borg架构","attributes":{},"skip":false,"key":"1.2.1"},{"backlink":"concepts/index.html#fig1.2.2","level":"1.2","list_caption":"Figure: Kubernetes架构","alt":"Kubernetes架构","nro":2,"url":"../images/architecture.png","index":2,"caption_template":"Figure: _CAPTION_","label":"Kubernetes架构","attributes":{},"skip":false,"key":"1.2.2"},{"backlink":"concepts/index.html#fig1.2.3","level":"1.2","list_caption":"Figure: kubernetes整体架构示意图","alt":"kubernetes整体架构示意图","nro":3,"url":"../images/kubernetes-whole-arch.png","index":3,"caption_template":"Figure: _CAPTION_","label":"kubernetes整体架构示意图","attributes":{},"skip":false,"key":"1.2.3"},{"backlink":"concepts/index.html#fig1.2.4","level":"1.2","list_caption":"Figure: Kubernetes master架构示意图","alt":"Kubernetes master架构示意图","nro":4,"url":"../images/kubernetes-master-arch.png","in
2017-08-21 17:44:43 +08:00
});
< / script >
< / div >
< script src = "../gitbook/gitbook.js" > < / script >
< script src = "../gitbook/theme.js" > < / script >
< script src = "../gitbook/gitbook-plugin-github/plugin.js" > < / script >
< script src = "../gitbook/gitbook-plugin-splitter/splitter.js" > < / script >
< script src = "../gitbook/gitbook-plugin-page-toc-button/plugin.js" > < / script >
< script src = "../gitbook/gitbook-plugin-editlink/plugin.js" > < / script >
< script src = "../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js" > < / script >
< script src = "../gitbook/gitbook-plugin-search-plus/search.js" > < / script >
< script src = "../gitbook/gitbook-plugin-sharing/buttons.js" > < / script >
< script src = "../gitbook/gitbook-plugin-fontsettings/fontsettings.js" > < / script >
< / body >
< / html >