• ansible安装二进制kubernetes-1.14.1


    主机信息:

    主机IP 主机名 角色
    10.10.3.181 k8s-m1  kube-apiserver,kube-controller-manager,kube-scheduler,etcd
    10.10.3.182 k8s-n1 kubelet,kube-proxy,etcd
    10.10.3.183 k8s-n2 kubelet,kube-proxy,etcd
    10.10.3.184 k8s-n3 kubelet,kube-proxy

    安装配置ansible

    安装

    yum install ansible -y

    配置

    $ vim /etc/ansible/ansible.cfg
    ...
    #去掉这个配置的#号
    host_key_checking = False
    ... #安装自己的情况修改 $ vim
    /etc/ansible/hosts [kubemaster] 10.10.3.181 hostname=k8s-m1 etcd01ip=10.10.3.181 etcd02ip=10.10.3.182 etcd03ip=10.10.3.183 [kubenode] 10.10.3.182 hostname=k8s-n1 10.10.3.183 hostname=k8s-n2 10.10.3.184 hostname=k8s-n3 [allnode] 10.10.3.181 10.10.3.182 10.10.3.183 10.10.3.184 [allnode:vars] ansible_ssh_user=root ansible_ssh_pass=123 ansible_ssh_port=22 [etcd] 10.10.3.181 etcdname=etcd01 etcd01ip=10.10.3.181 etcd02ip=10.10.3.182 etcd03ip=10.10.3.183 10.10.3.182 etcdname=etcd02 10.10.3.183 etcdname=etcd03

    配置免密钥

    1.生产密钥

    ssh-keygen -t rsa

    2.分发密钥

    ansible allnode -m  authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub')}}'"

    安装kubernetes

    修改主机名

    $ ansible allnode -m hostname -a 'name={{ hostname }}'

    git clone

    $ git clone https://github.com/jaxzhai/kubernetes-ansible.git

    修改kubernetes-ansible/group_vars/all.yaml参数

    1、修改ETCD_URL。修改成自己规划的IP即可

    2、修改ETCD_ENDPOINTS。修改成自己规划的IP即可

    3、修改IFACE。既网卡的名称

    开始运行安装

     1、setup.yaml

    这里我们选择升级到最新内核

    ansible-playbook setup.yaml  -e kernel=ture

    2、ca.yaml

    创建我们所需要的所有证书

    ansible-playbook ca.yaml

    3、kubectl.yaml

    创建kubectl,如果手动下载的话加上download=false标签。自己下载kubernetes-server-linux-amd64.tar.gz到role/kubectl/files目录下

    ansible-playbook kubectl.yaml -e download=false

    4、etcd.yaml

    ansible-playbook etcd.yaml

    查看状态

    $ ETCDCTL_API=3  etcdctl -w table --cacert=/etc/kubernetes/pki/ca.pem --cert=/etc/kubernetes/pki/etcd.pem --key=/etc/kubernetes/pki/etcd-key.pem --endpoints=https://10.10.3.181:2379,https://10.10.3.182:2379,https://10.10.3.183:2379 endpoint status
    +--------------------------+------------------+---------+---------+-----------+-----------+------------+
    |         ENDPOINT         |        ID        | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
    +--------------------------+------------------+---------+---------+-----------+-----------+------------+
    | https://10.10.3.181:2379 | 29fd839438b13490 |  3.3.12 |   20 kB |     false |         2 |          8 |
    | https://10.10.3.182:2379 | 15e01ae39b43687d |  3.3.12 |   20 kB |     false |         2 |          8 |
    | https://10.10.3.183:2379 | deaefeb573250ff1 |  3.3.12 |   20 kB |      true |         2 |          8 |
    +--------------------------+------------------+---------+---------+-----------+-----------+------------+

    5、flannel.yaml

    ansible-playbook flannel.yaml

    查看结果

    $ ansible allnode -m shell -a "/usr/sbin/ip addr show flannel.1|grep -w inet"
    10.10.3.183 | CHANGED | rc=0 >>
        inet 172.30.216.0/32 scope global flannel.1
    
    10.10.3.184 | CHANGED | rc=0 >>
        inet 172.30.176.0/32 scope global flannel.1
    
    10.10.3.182 | CHANGED | rc=0 >>
        inet 172.30.240.0/32 scope global flannel.1
    
    10.10.3.181 | CHANGED | rc=0 >>
        inet 172.30.88.0/32 scope global flannel.1

    6、kube-api.yaml

    ansible-playbook kube-api.yaml

    查看

    $ systemctl status kube-apiserver |grep 'Active:'
    Active: active (running) since Tue 2019-04-16 14:25:01 CST; 55s ago

    查看日志

    $ journalctl -u kube-apiserver

    7、kube-controller-manager.yaml

    ansible-playbook kube-controller-manager.yaml

    查看

    $ systemctl status kube-controller-manager|grep Active
       Active: active (running) since Tue 2019-04-16 14:27:19 CST; 4min 20s ag

    查看日志

    $ journalctl -u kube-controller-manager

    8、kube-scheduler.yaml

    ansible-playbook kube-scheduler.yaml

    查看

    $ systemctl status kube-scheduler|grep Active
       Active: active (running) since Tue 2019-04-16 14:55:07 CST; 15s ago

    查看日志

    $ journalctl -u kube-scheduler

    9、docker.yaml

    ansible-playbook docker.yaml
    $ docker info
    Containers: 0
     Running: 0
     Paused: 0
     Stopped: 0
    Images: 0
    Server Version: 18.09.2
    Storage Driver: overlay2
     Backing Filesystem: xfs
     Supports d_type: true
     Native Overlay Diff: true
    Logging Driver: json-file
    Cgroup Driver: systemd
    ......

    10、kubelet.yaml

    ansible-playbook kubelet.yaml

    11、kube-proxy.yaml

    ansible-playbook kube-proxy.yaml

    这样就完成了简单的k8s集群搭建。这里只适合玩一玩。当初写这个的原因也是为了练习ansible。此方法不能作为生产集群。

  • 相关阅读:
    修改JavaScript脚本并离线编译后将数据同步到Web和Web app
    修改JavaScript脚本并离线编译后将数据同步到Web和Web app
    基于JavaScript离线编译工具环境搭建
    基于JavaScript离线编译工具环境搭建
    超赞!聊聊WEB APP、HYBRID APP与NATIVE APP的设计差异
    超赞!聊聊WEB APP、HYBRID APP与NATIVE APP的设计差异
    基于JavaScript的安卓Web App测试环境搭建
    运行cmake,报package 'minigui' not found
    提示找不到include/common.h 提示No package 'minigui' found
    error: 'va_list' from type 'struct __va_list_tag *'
  • 原文地址:https://www.cnblogs.com/xzkzzz/p/10710310.html
Copyright © 2020-2023  润新知