K8S 二进制安装文档( k8s 1.17.3 docker 19.03.4)之二-docker安装和keepalive+haproxy配置

二、docker 安装

2.1安装依赖包

yum install -y yum-utils   device-mapper-persistent-data   lvm2

2.2配置docker安装源

yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo

2.3查看docker 安装版本

[root@k8smaster01 ~]# yum list docker-ce --showduplicates | sort -r  * updates: mirrors.aliyun.com Loading mirror speeds from cached hostfile Loaded plugins: fastestmirror  * extras: mirror.bit.edu.cn docker-ce.x86_64            3:19.03.8-3.el7                     docker-ce-stable docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable

2.4安装19.03.4 版本

yum install docker-ce-19.03.4 docker-ce-cli-19.03.4 containerd.io -y

2.5启动docker

[root@k8smaster01 ~]# systemctl start docker

[root@k8smaster01 ~]# systemctl enable docker

2.6补全命令

安装bash-completion

[root@k8smaster01 ~]# yum -y install bash-completion

加载bash-completion

root@k8smaster01 ~]# source /etc/profile.d/bash_completion.sh

2.7配置docker镜像加速,因为docker网站是在国外,主要镜像加速是ailiyun镜像

tee /etc/docker/daemon.json <<-'EOF'

{

  "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"]

}

EOF

[root@k8smaster01 ~]# systemctl daemon-reload

[root@k8smaster01 ~]# systemctl restart docker

2.8 测试docker安装成功

[root@k8smaster01 ~]# docker –version

[root@k8smaster01 ~]# docker run hello-world

[root@k8smaster01 ~]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES 8cf2072c66d8        hello-world         "/hello"            16 seconds ago      Exited (0) 15 seconds ago

三、Keepalived安装+Haproxy(3台master )

               (for kube-apiserver)

3.1 安装keepalived(k8smaster01,k8smaster02,k8smaster03)

[root@k8smaster01 ~]# yum -y install keepalived

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

3.2 配置keepalived


(k8smaster01)

[root@k8smaster01 ~]# more /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

   router_id k8smaster01

}

vrrp_instance VI_1 {

    state MASTER

    interface ens192

    virtual_router_id 50

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        10.111.104.172

    }

}


(k8smaster02)

[root@k8smaster02 ~]# more /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

   router_id k8smaster02

}

vrrp_instance VI_1 {

    state BACKUP

    interface ens192

    virtual_router_id 50

    priority 90

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        10.111.104.172

    }

}


(k8smaster03)

[root@k8smaster03 ~]# more /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

   router_id k8smaster03

}

vrrp_instance VI_1 {

    state BACKUP

    interface ens192

    virtual_router_id 50

    priority 80

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        10.111.104.172/18

    }

}

3.3、启动keepalived(k8smaster01-03)


[root@k8smaster01 ~]# systemctl start keepalived

[root@k8smaster01 ~]# systemctl enable keepalived

3.4、keep-alived VIP查看

[root@k8smaster01 ~]# ip addr

..........

2: ens192:  mtu 1500 qdisc mq state UP group default qlen 1000

    link/ether 00:50:56:82:42:2a brd ff:ff:ff:ff:ff:ff

    inet 10.111.69.240/18 brd 10.111.127.255 scope global noprefixroute dynamic ens192

       valid_lft 14089sec preferred_lft 14089sec

    inet 10.111.104.172/18 scope global ens192

       valid_lft forever preferred_lft forever

3.5 验证 VIP

重启k8smaster0,能够正常ping VIP

[root@k8smaster01 ~]#  reboot

[root@k8snode01 ~]#ping 10.111.104.172 

3.6安装haproxy(k8smaster01,k8smaster02,k8smaster03)

yum install -y haproxy

3.7 配置haproxy

(K8smaster01)

vim /etc/haproxy/haproxy.cfg

global

    log /dev/log local0

    log /dev/log local1 notice

    chroot /var/lib/haproxy

    stats socket /var/run/haproxy-admin.sock mode 660 level admin

    stats timeout 30s

    user haproxy

    group haproxy

    daemon

    nbproc 1

defaults

    log global

    timeout connect 5000

    timeout client 10m

    timeout server 10m

listen admin_stats

    bind 0.0.0.0:10080

    mode http

    log 127.0.0.1 local0 err

    stats refresh 30s

    stats uri /status

    stats realm welcome login\ Haproxy

    stats auth root:root123

    stats hide-version

    stats admin if TRUE

listen kube-master

    bind 0.0.0.0:8443

    mode tcp

    option tcplog

    balance source

    server 10.111.69.240 10.111.69.240:6443 check inter 2000 fall 2 rise 2 weight 1

    server 10.111.83.165 10.111.83.165:6443 check inter 2000 fall 2 rise 2 weight 1

    server 10.111.127.129 10.111.127.129:6443 check inter 2000 fall 2 rise 2 weight 1

3.8 同步haproxy.cfg 到k8smaster02、k8smaster03

​​​​​​​scp /etc/haproxy/haproxy.cfg k8smaster03://etc/haproxy/

scp /etc/haproxy/haproxy.cfg k8smaster02://etc/haproxy/

3.9 启动haproxy

systemctl restart haproxy

systemctl enable haproxy

3.10 验证haproxy 状态

通过访问http://10.111.104.172:10080/status  登录名stats auth root:root123

你可能感兴趣的:(K8S 二进制安装文档( k8s 1.17.3 docker 19.03.4)之二-docker安装和keepalive+haproxy配置)