前面手动安装了kubernets,但是过程比较繁琐,也不容易重复,今天有时间写了一个使用saltstack来安装kubernets。
1.已知问题:
用于加入node接天的token需要手动修改
环境:
centos7.2 2c+4g+40 saltmaster
centos7.2 2c+4g+40 saltminion k8s-master
centos7 2c +2g saltminion k8s-node1
本环境默认已经修改了主机名和关闭了防火墙,安装好saltminion,如果不知道怎么做可以看看cobbler,系统初始化安装的时候全部搞定。
saltstack安装master思路:
1.安装docker并启动,注意docker版本,官网明确表示最多到17.03
2.同步kubernetsyum源
3.安装kubernets
4.修改配置文件
5.启动kubernets
6.初始化kubernets
7.将节点加入集群
8.测试

k8smaster节点:
[root@saltmater prod]# cat k8s_master/install_k8s_master.sls
dock_relay_pkg:
pkg.installed:

  • names:
    • yum-utils
    • device-mapper-persistent-data
    • lvm2
    • wget
    • net-tools
      dock_v17selinux_file:
      file.managed:
  • name: /opt/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
  • source: salt://k8s_master/files/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
  • user: root
  • group: root
  • mode: 644
  • unless: test -f /opt/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
    docker_v17ce_file:
    file.managed:
  • name: /opt/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
  • source: salt://k8s_master/files/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
  • user: root
  • group: root
  • mode: 644
  • unless: test -f /opt/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
    install_docker_v17:
    cmd.run:
  • name: cd /opt && yum localinstall docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm -y
  • require:
    • file: dock_v17selinux_file
    • file: docker_v17ce_file
      service.running:
  • name: docker
  • enable: True
  • require:
    • cmd: install_docker_v17
      kubernetes_repo:
      file.managed:
  • name: /root/ku_repo.sh
  • source: salt://k8s_master/files/ku_repo.sh
  • user: root
  • group: root
  • mode: 755
  • unless: test -f /root/ku_repo.sh
    cmd.run:
  • name: /bin/bash /root/ku_repo.sh
  • reuqire:
    • file: kubernetes_repo
      kubelet_install:
      pkg.installed:
  • names:
    • kubelet
    • kubeadm
    • kubectl
  • require:
    • cmd: kubernetes_repo
      config_file_modify:
      file.managed:
  • name: /opt/k8s_config_modify.sh
  • source: salt://k8s_master/files/k8s_config_modify.sh
  • user: root
  • group: root
  • mode: 755
    cmd.run:
  • name: /bin/bash -x /opt/k8s_config_modify.sh
  • require:
    • pkg: kubelet_install
    • file: config_file_modify

k8s_node节点:

cat k8s_node/install_k8s_node.sls
dock_node_pkg:
pkg.installed:

  • names:
    • yum-utils
    • device-mapper-persistent-data
    • lvm2
    • wget
    • net-tools
      dock_selinux_file:
      file.managed:
  • name: /opt/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
  • source: salt://k8s_node/files/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
  • user: root
  • group: root
  • mode: 644
  • unless: test -f /opt/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
    docker_ce_file:
    file.managed:
  • name: /opt/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
  • source: salt://k8s_node/files/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
  • user: root
  • group: root
  • mode: 644
  • unless: test -f /opt/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
    install_docker:
    cmd.run:
  • name: cd /opt && yum localinstall docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm -y
  • require:
    • file: dock_selinux_file
    • file: docker_ce_file
      service.running:
  • name: docker
  • enable: True
  • require:
    • cmd: install_docker
      kubernetes_repo_yum:
      file.managed:
  • name: /root/ku_repo.sh
  • source: salt://k8s_node/files/ku_repo.sh
  • user: root
  • group: root
  • mode: 755
  • unless: test -f /root/ku_repo.sh
    cmd.run:
  • name: /bin/bash /root/ku_repo.sh
  • reuqire:
    • file: kubernetes_repo_yum
      pkg.installed:
  • names:
    • kubelet
    • kubeadm
    • kubectl
  • require:
    • cmd: kubernetes_repo_yum
      config_node_modify:
      file.managed:
  • name: /opt/k8s_node_modify.sh
  • source: salt://k8s_node/files/k8s_node_modify.sh
  • user: root
  • group: root
  • mode: 755
    cmd.run:
  • name: /bin/bash -x /opt/k8s_node_modify.sh
  • require:

    • pkg: kubernetes_repo_yum
    • file: config_node_modify

      部署2个nginx服务做测试:
      kubectl run nginx --image=nginx --replicas=2 --labels="run=load-tomct-example" --port=8089
      查看服务是否启动:
      saltsatck自动化安装kubernets v1.10.1
      saltsatck自动化安装kubernets v1.10.1_第1张图片

saltsatck自动化安装kubernets v1.10.1
saltsatck自动化安装kubernets v1.10.1_第2张图片
saltsatck自动化安装kubernets v1.10.1_第3张图片
saltsatck自动化安装kubernets v1.10.1_第4张图片