接着etcd的集群,现在用原有环境基础,增加master集群haproxy负载,机器受限 还是用1.5,1.6做master,把haproxy安装在1.5上
一般生产的时候,haproxy master etcd node 还是要分开集群
首先安装haproxy
yum install haproxy -y
yum install gcc -y
内核调优,修改系统文件
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
配置日志文件,添加三行
vim /etc/rsyslog.conf
$ModLoad imudp
$UDPServerRun 514
local3.* /var/log/haproxy.log
增加修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
global
maxconn 4096
log 127.0.0.1 local3 info
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
nbproc 1
pidfile /var/run/haproxy .pid
ulimit -n 65535
stats socket /var/lib/haproxy/stats
defaults
log global
mode http
maxconn 20480
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
option abortonclose
stats refresh 30
retries 3
balance roundrobin
cookie SRV
timeout check 2000ms
timeout connect 5000ms
timeout server 50000ms
timeout client 50000ms
listen admin_status
bind 0.0.0.0:6553
mode http
log 127.0.0.1 local3 info
stats enable
stats refresh 5s
stats realm Haproxy\ Statistics
stats uri /admin ?stats
stats auth admin:123456
stats hide-version
frontend web_service
bind 0.0.0.0:80
mode http
log global
option httplog
option httpclose
option forwardfor
default_backend external_servers
backend external_servers
mode http
balance roundrobin
option httpchk GET /index .html
server web1 192.168.1.5:8080 cookie web1 check inter 2000 rise 2 fall 3 weight 1
server web2 192.168.1.6:8080 cookie web2 check inter 2000 rise 2 fall 3 weight 1
|
其中注意修改
bind 0.0.0.0:80 #这个端口是用来做代理的前端口,通过该端口可以直达被代理的两台master机器,配置中采用轮询负载。
最后两行配置是定义被代理的2台master服务
启动haproxy服务
service rsyslog restart #重启系统日志服务
haproxy -f /etc/haproxy/haproxy.cfg #启动haproxy服务
echo "/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg" >> /etc/rc.local #加入到开机启动
安装master组件并修改相应配置
yum -y install kubernetes-master
修改master配置
vi /etc/kubernetes/apiserver
1
2
3
4
5
6
7
8
9
10
11
12
13
|
KUBE_API_ADDRESS= "--insecure-bind-address=0.0.0.0"
KUBE_API_PORT= "--port=8080"
KUBELET_PORT= "--kubelet-port=10250"
KUBE_ETCD_SERVERS= "--etcd-servers=http://192.168.1.5:2379,192.168.1.6:2379"
KUBE_SERVICE_ADDRESSES= "--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL= "--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS= ""
|
vi /etc/kubernetes/config
1
2
3
4
5
6
7
|
KUBE_LOGTOSTDERR= "--logtostderr=true"
KUBE_LOG_LEVEL= "--v=0"
KUBE_ALLOW_PRIV= "--allow-privileged=true"
KUBE_MASTER= "--master=http://192.168.1.5:80"
|
KUBE_MASTER="--master=http://192.168.1.5:80" 这一项就是填写haproxy代理的页面地址,端口是可以在haproxy配置中自定义的
vi /etc/kubernetes/controller-manager
KUBE_CONTROLLER_MANAGER_ARGS="--leader-elect=true"
vi /etc/kubernetes/scheduler
KUBE_SCHEDULER_ARGS="--leader-elect=true"
##"--leader-elect=true"这一项必须在两个文件中添加,用于master集群可用节点选举
下面就要修改node节点的配置了
vi /etc/kubernetes/kubelet
1
2
3
4
5
6
7
8
|
KUBELET_ADDRESS= "--address=0.0.0.0"
KUBELET_HOSTNAME= "--hostname-override=192.168.1.5"
KUBELET_API_SERVER="--api-servers=
KUBELET_POD_INFRA_CONTAINER= "--pod-infra-container-image=192.168.1.5:5000/pod-infrastructure:latest"
KUBELET_ARGS= "--cluster-dns=10.254.10.20 --cluster-domain=atomic.io"
|
注意凡是用到api-servers地址的都必须修改为haproxy代理地址http://192.168.1.5:80
kubernetes-dashboard.yaml 文件里有用到,一定注意修改
修改完配置后重启各服务即可通过浏览器访问测试
192.168.1.5:80
测试中停掉一台master服务,通过页面依旧正常访问
for SERVICES in kube-apiserver kube-controller-manager kube-scheduler; do systemctl stop $SERVICES;done
在服务器上操作会出现下面问题
[root@k8s-master heapster]# kubectl get pods -o wide -n kube-system
The connection to the server localhost:8080 was refused - did you specify the right host or port?
kubectl 命令默认访问本机的8080端口,当master服务停了后,命令需要用-s 指定访问源地址也就是代理页面地址。
[root@k8s-master heapster]# kubectl get pods -o wide -n kube-system -s 192.168.1.5:80
NAME READY STATUS RESTARTS AGE IP NODE
heapster-3919175978-cfpqw 1/1 Running 0 7m 172.17.79.3 192.168.1.5
kubernetes-dashboard-1872927757-ft8pk 1/1 Running 0 7m 172.17.88.2 k8s-node-1
monitoring-grafana-3994812335-8cbnt 1/1 Running 0 7m 172.17.88.3 k8s-node-1
monitoring-influxdb-265709471-q3wlt 1/1 Running 0 7m 172.17.79.4 192.168.1.5
也可以用命令声明下,alias kubectl="kubectl -s 192.168.1.5:80" 就不用每次都加了
到此就完成了2个etcd,2个master,2个node,各个集群都在两个机器上了。
haproxy做前端分发最好用两台机器做主备,加上keepalived即可
本文转自super李导51CTO博客,原文链接:http://blog.51cto.com/superleedo/2056041 ,如需转载请自行联系原作者