kubernetes集群环境搭建(5)
目录
一、kubernetes集群环境搭建
1.1.1 安装部署主控节点服务controller-manager(控制器)
1 .安装部署controller-manager(控制器)
主机 | 角色 | ip |
---|---|---|
hdss-21 | controller-manager | 10.0.0.21 |
hdss-22 | controller-manager | 10.0.0.22 |
- 创建启动脚本(因为这些都在kubernetes的安装包,所以不需要下载)
#21
[root@hdss-21.host.com ~]# cd /opt/kubernetes/server/bin/
[root@hdss-21.host.com /opt/kubernetes/server/bin]#
[root@hdss-21.host.com /opt/kubernetes/server/bin]# ll
total 884640
-rwxr-xr-x 1 root root 43534816 Aug 5 2019 apiextensions-apiserver
drwxr-xr-x 2 root root 124 Jun 13 21:49 certs
-rwxr-xr-x 1 root root 100548640 Aug 5 2019 cloud-controller-manager
drwxr-xr-x 2 root root 24 Jun 13 22:18 config
-rwxr-xr-x 1 root root 200648416 Aug 5 2019 hyperkube
-rwxr-xr-x 1 root root 40182208 Aug 5 2019 kubeadm
-rwxr-xr-x 1 root root 164501920 Aug 5 2019 kube-apiserver
-rwxr-xr-x 1 root root 1090 Jun 14 07:09 kube-apiserver.sh
-rwxr-xr-x 1 root root 116397088 Aug 5 2019 kube-controller-manager #这里
-rwxr-xr-x 1 root root 42985504 Aug 5 2019 kubectl
-rwxr-xr-x 1 root root 119616640 Aug 5 2019 kubelet
-rwxr-xr-x 1 root root 36987488 Aug 5 2019 kube-proxy
-rwxr-xr-x 1 root root 38786144 Aug 5 2019 kube-scheduler
-rwxr-xr-x 1 root root 1648224 Aug 5 2019 mounter
[root@hdss-21.host.com /opt/kubernetes/server/bin]# vim /opt/kubernetes/server/bin/kube-controller-manager.sh
[root@hdss-21.host.com /opt/kubernetes/server/bin]# cat /opt/kubernetes/server/bin/kube-controller-manager.sh
#!/bin/sh
./kube-controller-manager
--cluster-cidr 172.7.0.0/16
--leader-elect true
--log-dir /data/logs/kubernetes/kube-controller-manager
--master http://127.0.0.1:8080
--service-account-private-key-file ./cert/ca-key.pem
--service-cluster-ip-range 192.168.0.0/16
--root-ca-file ./certs/ca.pem
--v 2
[root@hdss-21.host.com /opt/kubernetes/server/bin]# chmod +x /opt/kubernetes/server/bin/kube-controller-manager.sh
[root@hdss-21.host.com /opt/kubernetes/server/bin]# ll /opt/kubernetes/server/bin/kube-controller-manager.sh
-rwxr-xr-x 1 root root 333 Jun 14 23:45 /opt/kubernetes/server/bin/kube-controller-manager.sh
- supervisor使controller-manager后端运行
创建日志文件
[root@hdss-21.host.com /opt/kubernetes/server/bin]# mkdir -p /data/logs/kubernetes/kube-controller-manager
[root@hdss-21.host.com /opt/kubernetes/server/bin]# ll -ld /data/logs/kubernetes/kube-controller-manager
drwxr-xr-x 2 root root 6 Jun 14 23:50 /data/logs/kubernetes/kube-controller-manager
#创建后台管理文件
[root@hdss-21.host.com /opt/kubernetes/server/bin]# vim /etc/supervisord.d/kube-conntroller-manager.ini
[root@hdss-21.host.com /opt/kubernetes/server/bin]# cat /etc/supervisord.d/kube-conntroller-manager.ini
[program:kube-controller-manager-21] #主机22要改成22
command=/opt/kubernetes/server/bin/kube-controller-manager.sh ; the program (relative uses PATH, can take args)
numprocs=1 ; number of processes copies to start (def 1)
directory=/opt/kubernetes/server/bin ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=30 ; number of secs prog must stay running (def. 1)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
user=root ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/kubernetes/kube-controller-manager/controller.stdout.log ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4 ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
[root@hdss-21.host.com /opt/kubernetes/server/bin]# supervisorctl update
kube-controller-manager-21: added process group
[root@hdss-21.host.com /opt/kubernetes/server/bin]# supervisorctl status
etcd-server-21 RUNNING pid 1677, uptime 1 day, 0:42:10
kube-apiserver-21 RUNNING pid 1655, uptime 1 day, 0:42:13
kube-controller-manager-21 STARTING
2.1.1 安装部署主控节点服务kube-scheduler(调度器)
- 安装部署服务kube-scheduler
主机 | 角色 | ip |
---|---|---|
hdss-21 | scheduler | 10.0.0.21 |
hdss-22 | scheduler | 10.0.0.22 |
- 创建启动脚本
[root@hdss-21.host.com /opt/kubernetes/server/bin]# vim /opt/kubernetes/server/bin/kube-scheduler.sh
[root@hdss-21.host.com /opt/kubernetes/server/bin]# cat /opt/kubernetes/server/bin/kube-scheduler.sh
#!/bin/sh
./kube-scheduler
--leader-elect
--log-dir /data/logs/kubernetes/kube-scheduler
--master http://127.0.0.1:8080
--v 2
[root@hdss-21.host.com /opt/kubernetes/server/bin]# chmod +x /opt/kubernetes/server/bin/kube-scheduler.sh
[root@hdss-21.host.com /opt/kubernetes/server/bin]# ll /opt/kubernetes/server/bin/kube-scheduler.sh
-rwxr-xr-x 1 root root 143 Jun 14 23:54 /opt/kubernetes/server/bin/kube-scheduler.sh
- supervisor使scheduler后端运行
创建日志文件
[root@hdss-21.host.com /opt/kubernetes/server/bin]# mkdir -p /data/logs/kubernetes/kube-scheduler
[root@hdss-21.host.com /opt/kubernetes/server/bin]# ll -ld /data/logs/kubernetes/kube-scheduler
drwxr-xr-x 2 root root 6 Jun 15 00:00 /data/logs/kubernetes/kube-scheduler
创建配置文件
[root@hdss-21.host.com /opt/kubernetes/server/bin]# vim /etc/supervisord.d/kube-scheduler.ini
[root@hdss-21.host.com /opt/kubernetes/server/bin]# cat /etc/supervisord.d/kube-scheduler.ini
[program:kube-scheduler-21] #主机22要改成22
command=/opt/kubernetes/server/bin/kube-scheduler.sh ; the program (relative uses PATH, can take args)
numprocs=1 ; number of processes copies to start (def 1)
directory=/opt/kubernetes/server/bin ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=30 ; number of secs prog must stay running (def. 1)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
user=root ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/kubernetes/kube-scheduler/scheduler.stdout.log ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4 ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
#22 同上