zsyzhou 发表于 2019-1-1 08:21:26

k8s

  接着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


增加修改配置文件
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                                        #定义haproxy的监控界面
bind    0.0.0.0:6553
mode    http
log    127.0.0.1    local3 info
stats    enable
stats    refresh    5s                                          #监控页面自动刷新时间5s
stats    realm    Haproxy\    Statistics                #登录监控页面提示符
stats    uri    /admin?stats                                  #监控页面URL路径
stats    auth    admin:123456                           #监控页面的账户密码
stats    hide-version                                           #隐藏haproxy版本
frontend    web_service                                     #定义前端服务器
bind    0.0.0.0:80
mode    http
log    global
option    httplog
option    httpclose
option    forwardfor
#acl    inside_src src 192.168.1.0/24                  #定义acl
#use_backend    inside_servers if inside_src      #判断acl的源地址,把请求转发到inside_servers组
default_backend    external_servers                        #默认服务器组

backend    external_servers
mode    http
balance    roundrobin                                          #轮询真实服务器
option    httpchk    GET    /index.html                #检查index文件,判断服务器是否健康
##定义后端真实服务器,向cookie中插入web1信息,check进行健康检查,检查时间间隔为2000ms,##连续两次健康则认为是正常开启的,连续三次检查失败则认为宕机,服务器权重1
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
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
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

KUBELET_ADDRESS="--address=0.0.0.0"

KUBELET_HOSTNAME="--hostname-override=192.168.1.5"
KUBELET_API_SERVER="--api-servers=   #修改成了haproxy代理页面地址
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


在服务器上操作会出现下面问题

  # 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 指定访问源地址也就是代理页面地址。
  # 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即可















页: [1]
查看完整版本: k8s