上面的那一堆都是准备工作,下面开始正式部署kubernetes了,
在master节点进行部署。
# wget https://dl.k8s.io/v1.8.6/kubernetes-server-linux-amd64.tar.gz
# tar -xzvf kubernetes-server-linux-amd64.tar.gz
# cp -r kubernetes/server/bin/{kube-apiserver,kube-controller-manager,kube-scheduler,kubectl,kube-proxy,kubelet} /usr/local/bin/
cat > kube-apiserver.service << EOF
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
After=etcd.service
[Service]
ExecStart=/usr/local/bin/kube-apiserver \\
--logtostderr=true \\
--admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,NodeRestriction \\
--advertise-address=192.168.161.161 \\
--bind-address=192.168.161.161 \\
--insecure-bind-address=127.0.0.1 \\
--authorization-mode=Node,RBAC \\
--runtime-config=rbac.authorization.k8s.io/v1alpha1 \\
--kubelet-https=true \\
--enable-bootstrap-token-auth \\
--token-auth-file=/etc/kubernetes/token.csv \\
--service-cluster-ip-range=10.254.0.0/16 \\
--service-node-port-range=8400-10000 \\
--tls-cert-file=/etc/kubernetes/ssl/kubernetes.pem \\
--tls-private-key-file=/etc/kubernetes/ssl/kubernetes-key.pem \\
--client-ca-file=/etc/kubernetes/ssl/ca.pem \\
--service-account-key-file=/etc/kubernetes/ssl/ca-key.pem \\
--etcd-cafile=/etc/kubernetes/ssl/ca.pem \\
--etcd-certfile=/etc/kubernetes/ssl/kubernetes.pem \\
--etcd-keyfile=/etc/kubernetes/ssl/kubernetes-key.pem \\
--etcd-servers=https://192.168.161.161:2379,https://192.168.161.162:2379,https://192.168.161.163:2379 \\
--enable-swagger-ui=true \\
--allow-privileged=true \\
--apiserver-count=3 \\
--audit-log-maxage=30 \\
--audit-log-maxbackup=3 \\
--audit-log-maxsize=100 \\
--audit-log-path=/var/lib/audit.log \\
--event-ttl=1h \\
--v=2
Restart=on-failure
RestartSec=5
Type=notify
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
注意 更换成自己的IP
–authorization-mode=RBAC 指定在安全端口使用 RBAC 授权模式,拒绝未通过授权的请求;
kube-scheduler、kube-controller-manager 一般和 kube-apiserver 部署在同一台机器上,它们使用非安全端口和 kube-apiserver通信;
kubelet、kube-proxy、kubectl 部署在其它 Node 节点上,如果通过安全端口访问 kube-apiserver,则必须先通过 TLS 证书认证,再通过 RBAC 授权;
kube-proxy、kubectl 通过在使用的证书里指定相关的 User、Group 来达到通过 RBAC 授权的目的;
如果使用了 kubelet TLS Boostrap 机制,则不能再指定 –kubelet-certificate-authority、–kubelet-client-certificate 和 –kubelet-client-key 选项,否则后续 kube-apiserver 校验 kubelet 证书时出现 ”x509: certificate signed by unknown authority“ 错误;
–admission-control 值必须包含 ServiceAccount,否则部署集群插件时会失败;
–bind-address 不能为 127.0.0.1;
–runtime-config配置为rbac.authorization.k8s.io/v1beta1,表示运行时的apiVersion;
–service-cluster-ip-range 指定 Service Cluster IP 地址段,该地址段不能路由可达;
–service-node-port-range 指定 NodePort 的端口范围;
缺省情况下 kubernetes 对象保存在 etcd /registry 路径下,可以通过 –etcd-prefix 参数进行调整;
# cp kube-apiserver.service /etc/systemd/system/
# systemctl daemon-reload
# systemctl enable kube-apiserver
# systemctl start kube-apiserver
# systemctl status kube-apiserver
kube-apiserver.service - Kubernetes API Server
Loaded: loaded (/etc/systemd/system/kube-apiserver.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2018-03-19 16:26:03 CST; 19s ago
Docs: https://github.com/GoogleCloudPlatform/kubernetes
Main PID: 5948 (kube-apiserver)
CGroup: /system.slice/kube-apiserver.service
└─5948 /usr/local/bin/kube-apiserver --logtostderr=true --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,NodeRestriction --advertise-address=192....
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.901059 5948 wrap.go:42] POST /api/v1/namespaces: (11.166039ms) 409 [[kube-apiserver/v1.8.6 (linux/amd64) kubernetes/6260bb0] 192...161.161:60460]
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.914750 5948 wrap.go:42] POST /apis/rbac.authorization.k8s.io/v1beta1/namespaces/kube-system/rolebindings: (5.722228ms) 201 [[kub...161.161:60460]
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.915229 5948 storage_rbac.go:287] created rolebinding.rbac.authorization.k8s.io/system:controller:token-cleaner in kube-system
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.929618 5948 wrap.go:42] GET /apis/rbac.authorization.k8s.io/v1beta1/namespaces/kube-public/rolebindings/system:controller:bootst...161.161:60460]
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.935152 5948 wrap.go:42] POST /api/v1/namespaces: (4.882855ms) 409 [[kube-apiserver/v1.8.6 (linux/amd64) kubernetes/6260bb0] 192....161.161:60460]
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.965294 5948 wrap.go:42] POST /apis/rbac.authorization.k8s.io/v1beta1/namespaces/kube-public/rolebindings: (17.302393ms) 201 [[ku...161.161:60460]
3月 19 16:26:05 master1 kube-apiserver[5948]: I0319 16:26:05.965805 5948 storage_rbac.go:287] created rolebinding.rbac.authorization.k8s.io/system:controller:bootstrap-signer in kube-public
3月 19 16:26:13 master1 kube-apiserver[5948]: I0319 16:26:13.776733 5948 wrap.go:42] GET /api/v1/namespaces/default: (2.511793ms) 200 [[kube-apiserver/v1.8.6 (linux/amd64) kubernetes/6260bb...161.161:60460]
3月 19 16:26:13 master1 kube-apiserver[5948]: I0319 16:26:13.780367 5948 wrap.go:42] GET /api/v1/namespaces/default/services/kubernetes: (2.593409ms) 200 [[kube-apiserver/v1.8.6 (linux/amd6...161.161:60460]
3月 19 16:26:13 master1 kube-apiserver[5948]: I0319 16:26:13.784057 5948 wrap.go:42] GET /api/v1/namespaces/default/endpoints/kubernetes: (2.67392ms) 200 [[kube-apiserver/v1.8.6 (linux/amd6...161.161:60460]
Hint: Some lines were ellipsized, use -l to show in full.
cat > kube-controller-manager.service << EOF
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
ExecStart=/usr/local/bin/kube-controller-manager \\
--logtostderr=true \\
--address=127.0.0.1 \\
--master=http://127.0.0.1:8080 \\
--allocate-node-cidrs=true \\
--service-cluster-ip-range=10.254.0.0/16 \\
--cluster-cidr=172.30.0.0/16 \\
--cluster-name=kubernetes \\
--cluster-signing-cert-file=/etc/kubernetes/ssl/ca.pem \\
--cluster-signing-key-file=/etc/kubernetes/ssl/ca-key.pem \\
--service-account-private-key-file=/etc/kubernetes/ssl/ca-key.pem \\
--root-ca-file=/etc/kubernetes/ssl/ca.pem \\
--leader-elect=true \\
--v=2
Restart=on-failure
LimitNOFILE=65536
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
–address 值必须为 127.0.0.1,因为当前 kube-apiserver 期望 scheduler 和 controller-manager 在同一台机器;
–master=http://{MASTER_IP}:8080:使用非安全 8080 端口与 kube-apiserver 通信;
–cluster-cidr 指定 Cluster 中 Pod 的 CIDR 范围,该网段在各 Node 间必须路由可达(flanneld保证);
–service-cluster-ip-range 参数指定 Cluster 中 Service 的CIDR范围,该网络在各 Node 间必须路由不可达,必须和 kube-apiserver 中的参数一致;
–cluster-signing-* 指定的证书和私钥文件用来签名为 TLS BootStrap 创建的证书和私钥;
–root-ca-file 用来对 kube-apiserver 证书进行校验,指定该参数后,才会在Pod 容器的 ServiceAccount 中放置该 CA 证书文件;
–leader-elect=true 部署多台机器组成的 master 集群时选举产生一处于工作状态的 kube-controller-manager 进程;
# cp kube-controller-manager.service /etc/systemd/system/
# systemctl daemon-reload
# systemctl enable kube-controller-manager
# systemctl start kube-controller-manager
cat > kube-scheduler.service << EOF
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service]
ExecStart=/usr/local/bin/kube-scheduler \\
--logtostderr=true \\
--address=127.0.0.1 \\
--master=http://127.0.0.1:8080 \\
--leader-elect=true \\
--v=2
Restart=on-failure
LimitNOFILE=65536
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
–address 值必须为 127.0.0.1,因为当前 kube-apiserver 期望 scheduler 和 controller-manager 在同一台机器;
–master=http://{MASTER_IP}:8080:使用非安全 8080 端口与 kube-apiserver 通信;
–leader-elect=true 部署多台机器组成的 master 集群时选举产生一处于工作状态的 kube-controller-manager 进程;
# cp kube-scheduler.service /etc/systemd/system/
# systemctl daemon-reload
# systemctl enable kube-scheduler
# systemctl start kube-scheduler
[root@master1 ~]# kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health": "true"}
etcd-2 Healthy {"health": "true"}
etcd-1 Healthy {"health": "true"}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。