Kubernetes|Kubernetes学习二(Kubernetes集群搭建之部署kubernetes server)

目录
1、解压缩文件
2、部署kube-apiserver组件 创建TLS Bootstrapping Token
【Kubernetes|Kubernetes学习二(Kubernetes集群搭建之部署kubernetes server)】3、创建Apiserver配置文件
4、创建apiserver systemd文件
5、启动服务
6、部署kube-scheduler组件 创建kube-scheduler配置文件
7、部署kube-controller-manager组件 创建kube-controller-manager配置文件
8、验证kubeserver服务
1、解压缩文件

tar -zxvf kubernetes-server-linux-amd64.tar.gz cd kubernetes/server/bin/ cp kube-scheduler kube-apiserver kube-controller-manager kubectl /k8s/kubernetes/bin/

2、部署kube-apiserver组件 创建TLS Bootstrapping Token
[root@elasticsearch01 bin]# head -c 16 /dev/urandom | od -An -t x | tr -d ' ' f2c50331f07be89278acdaf341ff1ecc vim /k8s/kubernetes/cfg/token.csv f2c50331f07be89278acdaf341ff1ecc,kubelet-bootstrap,10001,"system:kubelet-bootstrap"

3、创建Apiserver配置文件
KUBE_APISERVER_OPTS="--logtostderr=true \ --v=4 \ --etcd-servers=https://192.168.10.200:2379,https://192.168.10.201:2379,https://192.168.10.202:2379 \ --bind-address=192.168.10.200 \ --secure-port=6443 \ --advertise-address=192.168.10.200 \ --allow-privileged=true \ --service-cluster-ip-range=10.254.0.0/16 \ --enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,NodeRestriction \ --authorization-mode=RBAC,Node \ --enable-bootstrap-token-auth \ --token-auth-file=/k8s/kubernetes/cfg/token.csv \ --service-node-port-range=30000-50000 \ --tls-cert-file=/k8s/kubernetes/ssl/server.pem\ --tls-private-key-file=/k8s/kubernetes/ssl/server-key.pem \ --client-ca-file=/k8s/kubernetes/ssl/ca.pem \ --service-account-key-file=/k8s/kubernetes/ssl/ca-key.pem \ --etcd-cafile=/k8s/etcd/ssl/ca.pem \ --etcd-certfile=/k8s/etcd/ssl/server.pem \ --etcd-keyfile=/k8s/etcd/ssl/server-key.pem"

4、创建apiserver systemd文件
vim /usr/lib/systemd/system/kube-apiserver.service [Unit] Description=Kubernetes API Server Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/k8s/kubernetes/cfg/kube-apiserver ExecStart=/k8s/kubernetes/bin/kube-apiserver $KUBE_APISERVER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target

5、启动服务
systemctl daemon-reload systemctl enable kube-apiserver systemctl start kube-apiserver [root@k8s-master1 ~]# systemctl status kube-apiserver ● kube-apiserver.service - Kubernetes API Server Loaded: loaded (/usr/lib/systemd/system/kube-apiserver.service; enabled; vendor preset: disabled) Active: active (running) since 三 2019-03-13 14:24:39 CST; 17min ago Docs: https://github.com/kubernetes/kubernetes Main PID: 2351 (kube-apiserver) CGroup: /system.slice/kube-apiserver.service └─2351 /k8s/kubernetes/bin/kube-apiserver --logtostderr=true --v=4 --etcd-servers=https://192.168.10.200:2379,https://192.168.10.201:2379,https:/...3月 13 14:41:49 k8s-master1 kube-apiserver[2351]: I0313 14:41:49.8494222351 wrap.go:47] GET /api/v1/namespaces/kube-system/endpoints/kube-contr...1:55958] 3月 13 14:41:49 k8s-master1 kube-apiserver[2351]: I0313 14:41:49.8617522351 wrap.go:47] PUT /api/v1/namespaces/kube-system/endpoints/kube-contr...1:55958] 3月 13 14:41:49 k8s-master1 kube-apiserver[2351]: I0313 14:41:49.8828872351 wrap.go:47] GET /api/v1/namespaces/kube-system/endpoints/kube-sched...1:51944] 3月 13 14:41:49 k8s-master1 kube-apiserver[2351]: I0313 14:41:49.9931192351 wrap.go:47] PUT /api/v1/namespaces/kube-system/endpoints/kube-sched...1:51944] 3月 13 14:41:51 k8s-master1 kube-apiserver[2351]: I0313 14:41:51.6063882351 wrap.go:47] GET /apis/batch/v1/jobs: (9.175259ms) 200 [kube-control...1:55958] 3月 13 14:41:51 k8s-master1 kube-apiserver[2351]: I0313 14:41:51.6216442351 wrap.go:47] GET /apis/batch/v1beta1/cronjobs: (8.903237ms) 200 [kub...1:55958] 3月 13 14:41:51 k8s-master1 kube-apiserver[2351]: I0313 14:41:51.8687282351 wrap.go:47] GET /api/v1/namespaces/kube-system/endpoints/kube-contr...1:55958] 3月 13 14:41:51 k8s-master1 kube-apiserver[2351]: I0313 14:41:51.8808532351 wrap.go:47] PUT /api/v1/namespaces/kube-system/endpoints/kube-contr...1:55958] 3月 13 14:41:52 k8s-master1 kube-apiserver[2351]: I0313 14:41:52.0024392351 wrap.go:47] GET /api/v1/namespaces/kube-system/endpoints/kube-sched...1:51944] 3月 13 14:41:52 k8s-master1 kube-apiserver[2351]: I0313 14:41:52.0158912351 wrap.go:47] PUT /api/v1/namespaces/kube-system/endpoints/kube-sched...1:51944] Hint: Some lines were ellipsized, use -l to show in full. [root@k8s-master1 ~]# ps -ef |grep kube-apiserver root235117 14:24 ?00:01:16 /k8s/kubernetes/bin/kube-apiserver --logtostderr=true --v=4 --etcd-servers=https://192.168.10.200:2379,https:// 192.168.10.201:2379,https://192.168.10.202:2379 --bind-address=192.168.10.200 --secure-port=6443 --advertise-address=192.168.10.200 --allow-privileged=true --service-cluster-ip-range=10.254.0.0/16 --enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,NodeRestriction --authorization-mode=RBAC,Node --enable-bootstrap-token-auth --token-auth-file=/k8s/kubernetes/cfg/token.csv --service-node-port-range=30000-50000 --tls-cert-file=/k8s/kubernetes/ssl/server.pem --tls-private-key-file=/k8s/kubernetes/ssl/server-key.pem --client-ca-file=/k8s/kubernetes/ssl/ca.pem --service-account-key-file=/k8s/kubernetes/ssl/ca-key.pem --etcd-cafile=/k8s/etcd/ssl/ca.pem --etcd-certfile=/k8s/etcd/ssl/server.pem --etcd-keyfile=/k8s/etcd/ssl/server-key.pemroot257122210 14:42 pts/000:00:00 grep --color=auto kube-apiserver [root@k8s-master1 ~]# netstat -tulpn |grep kube-apiserve tcp00 192.168.10.200:64430.0.0.0:*LISTEN2351/kube-apiserver tcp00 127.0.0.1:80800.0.0.0:*LISTEN2351/kube-apiserver

6、部署kube-scheduler组件 创建kube-scheduler配置文件
vim/k8s/kubernetes/cfg/kube-scheduler KUBE_SCHEDULER_OPTS="--logtostderr=true --v=4 --master=127.0.0.1:8080 --leader-elect"

参数备注: –address:在 127.0.0.1:10251 端口接收 http /metrics 请求;kube-scheduler 目前还不支持接收 https 请求; –kubeconfig:指定 kubeconfig 文件路径,kube-scheduler 使用它连接和验证 kube-apiserver; –leader-elect=true:集群运行模式,启用选举功能;被选为 leader 的节点负责处理工作,其它节点为阻塞状态;
创建kube-scheduler systemd文件
vim /usr/lib/systemd/system/kube-scheduler.service [Unit] Description=Kubernetes Scheduler Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/k8s/kubernetes/cfg/kube-scheduler ExecStart=/k8s/kubernetes/bin/kube-scheduler $KUBE_SCHEDULER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target

启动服务
systemctl daemon-reload systemctl enable kube-scheduler.service systemctl start kube-scheduler.service [root@k8s-master1 ~]# systemctl status kube-scheduler.service ● kube-scheduler.service - Kubernetes Scheduler Loaded: loaded (/usr/lib/systemd/system/kube-scheduler.service; enabled; vendor preset: disabled) Active: active (running) since 三 2019-03-13 14:27:32 CST; 17min ago Docs: https://github.com/kubernetes/kubernetes Main PID: 2409 (kube-scheduler) CGroup: /system.slice/kube-scheduler.service └─2409 /k8s/kubernetes/bin/kube-scheduler --logtostderr=true --v=4 --master=127.0.0.1:8080 --leader-elect3月 13 14:37:17 k8s-master1 kube-scheduler[2409]: I0313 14:37:17.8662952409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:38:01 k8s-master1 kube-scheduler[2409]: I0313 14:38:01.8682722409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:39:02 k8s-master1 kube-scheduler[2409]: I0313 14:39:02.8823792409 reflector.go:357] k8s.io/kubernetes/cmd/kube-scheduler/app/server.g...received 3月 13 14:40:43 k8s-master1 kube-scheduler[2409]: I0313 14:40:43.8645202409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:41:08 k8s-master1 kube-scheduler[2409]: I0313 14:41:08.8677762409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:41:40 k8s-master1 kube-scheduler[2409]: I0313 14:41:40.8668662409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:42:15 k8s-master1 kube-scheduler[2409]: I0313 14:42:15.8662862409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:44:02 k8s-master1 kube-scheduler[2409]: I0313 14:44:02.8686292409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:44:22 k8s-master1 kube-scheduler[2409]: I0313 14:44:22.8659372409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received 3月 13 14:44:58 k8s-master1 kube-scheduler[2409]: I0313 14:44:58.8697542409 reflector.go:357] k8s.io/client-go/informers/factory.go:132: Watch ...received Hint: Some lines were ellipsized, use -l to show in full.

7、部署kube-controller-manager组件 创建kube-controller-manager配置文件
vim /k8s/kubernetes/cfg/kube-controller-manager KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=true \ --v=4 \ --master=127.0.0.1:8080 \ --leader-elect=true \ --address=127.0.0.1 \ --service-cluster-ip-range=10.254.0.0/16 \ --cluster-name=kubernetes \ --cluster-signing-cert-file=/k8s/kubernetes/ssl/ca.pem \ --cluster-signing-key-file=/k8s/kubernetes/ssl/ca-key.pem\ --root-ca-file=/k8s/kubernetes/ssl/ca.pem \ --service-account-private-key-file=/k8s/kubernetes/ssl/ca-key.pem"

创建kube-controller-manager systemd文件
vim /usr/lib/systemd/system/kube-controller-manager.service [Unit] Description=Kubernetes Controller Manager Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/k8s/kubernetes/cfg/kube-controller-manager ExecStart=/k8s/kubernetes/bin/kube-controller-manager $KUBE_CONTROLLER_MANAGER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target

启动服务
systemctl daemon-reload systemctl enable kube-controller-manager systemctl start kube-controller-manager [root@k8s-master1 ~]# systemctl status kube-controller-manager ● kube-controller-manager.service - Kubernetes Controller Manager Loaded: loaded (/usr/lib/systemd/system/kube-controller-manager.service; enabled; vendor preset: disabled) Active: active (running) since 三 2019-03-13 14:28:54 CST; 19min ago Docs: https://github.com/kubernetes/kubernetes Main PID: 2461 (kube-controller) CGroup: /system.slice/kube-controller-manager.service └─2461 /k8s/kubernetes/bin/kube-controller-manager --logtostderr=true --v=4 --master=127.0.0.1:8080 --leader-elect=true --address=127.0.0.1 --ser...3月 13 14:48:02 k8s-master1 kube-controller-manager[2461]: I0313 14:48:02.8082412461 cronjob_controller.go:122] Found 0 groups 3月 13 14:48:04 k8s-master1 kube-controller-manager[2461]: I0313 14:48:04.0281912461 resource_quota_controller.go:422] no resource updates from ...ta sync 3月 13 14:48:06 k8s-master1 kube-controller-manager[2461]: I0313 14:48:06.1144872461 reflector.go:357] k8s.io/client-go/informers/factory.go:132...eceived 3月 13 14:48:12 k8s-master1 kube-controller-manager[2461]: I0313 14:48:12.8158892461 cronjob_controller.go:111] Found 0 jobs 3月 13 14:48:12 k8s-master1 kube-controller-manager[2461]: I0313 14:48:12.8249302461 cronjob_controller.go:119] Found 0 cronjobs 3月 13 14:48:12 k8s-master1 kube-controller-manager[2461]: I0313 14:48:12.8249662461 cronjob_controller.go:122] Found 0 groups 3月 13 14:48:14 k8s-master1 kube-controller-manager[2461]: I0313 14:48:14.8802552461 reflector.go:215] k8s.io/client-go/informers/factory.go:132... resync 3月 13 14:48:15 k8s-master1 kube-controller-manager[2461]: I0313 14:48:15.1838442461 pv_controller_base.go:408] resyncing PV controller 3月 13 14:48:20 k8s-master1 kube-controller-manager[2461]: I0313 14:48:20.5994952461 gc_controller.go:144] GC'ing orphaned 3月 13 14:48:20 k8s-master1 kube-controller-manager[2461]: I0313 14:48:20.6055332461 gc_controller.go:173] GC'ing unscheduled pods which are terminating. Hint: Some lines were ellipsized, use -l to show in full.

8、验证kubeserver服务
设置环境变量
vim /etc/profile PATH=/k8s/kubernetes/bin:$PATH source /etc/profile

查看master服务状态
[root@k8s-master1 ~]# kubectl get cs,nodes NAMESTATUSMESSAGEERROR componentstatus/schedulerHealthyok componentstatus/controller-managerHealthyok componentstatus/etcd-0Healthy{"health":"true"} componentstatus/etcd-2Healthy{"health":"true"} componentstatus/etcd-1Healthy{"health":"true"}

参考:https://www.kubernetes.org.cn/5025.html

    推荐阅读