码迷,mamicode.com
首页 > Web开发 > 详细

saltsatck自动化安装kubernets v1.10.1

时间:2018-04-19 10:36:27      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:kubernets saltstack

前面手动安装了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

标签:kubernets saltstack

原文地址:http://blog.51cto.com/mrdeng/2105178

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!