美文网首页Sonar
记录k8s搭建过程中使用的playbook

记录k8s搭建过程中使用的playbook

作者: 无处安放的躁动 | 来源:发表于2019-04-12 17:50 被阅读0次

    k8s搭建过程中使用的playbook

    由于多台机器,每次都需要多次安装,使用ansible简单批量操作

    k8s搭建过程使用ansible批量处理的playbook

    前提

    cat /etc/hosts
    192.168.122.80   k8sMaster
    192.168.122.82   k8sworker2
    192.168.122.81   k8sworker1
    
    /etc/ansible/roles/k8s/tasks/ConfigurationK8s.yml
    cat /etc/ansible/hosts
    [k8s]
    k8sMaster
    k8sworker2
    k8sworker1
    

    案例

    ---
    - name: k8s configure
      hosts: k8s
      remote_user: root
      vars:
          k8sfile: /opt/kubernetes-starter/config.properties
          k8smaster: 192.168.122.80
          k8sworker1: 192.168.122.81
          k8sworker2: 192.168.122.82
      tasks:
        - name : copy config file to k8s 
          copy:
            src: /etc/ansible/shell/config/k8s.conf
            dest: /etc/sysctl.d/k8s.conf
    
        - name : 执行刷新/etc/sysctl.d/k8s.conf命令
          command: 'sysctl -p /etc/sysctl.d/k8s.conf'
    
        - name : 修改hosts
          shell :  'echo -e "192.168.122.80 k8sMaster \n192.168.122.82 k8sworker1 \n192.168.122.82 k8sworker2" >>/etc/hosts'
    
        - name: copy K8S 安装文件
          copy:
            src: /etc/ansible/shell/kubernetes-bins.tar.gz
            dest: /opt
    
        - name: 解压/etc/ansible/shell/kubernetes-bins.tar.gz文件
          shell: 'cd /opt/ &&  tar -xf /opt/kubernetes-bins.tar.gz'
    
        - name: yum 安装git
          yum: name=git state=latest
    
        - name: git clone https://github.com/liuyi01/kubernetes-starter.git
          shell: 'cd /opt && git clone https://github.com/liuyi01/kubernetes-starter.git'
        - name : 修改配置文件1
          shell: 'sed -i "2cBIN_PATH=/opt\/kubernetes-bins"  {{k8sfile}} '
        - name : 修改配置文件2
          shell: "sed -i \"5cNODE_IP=`hostname -I|awk '{print $1}'`\" {{k8sfile}} "
        - name : 修改配置文件3
          shell: 'sed -i "10cETCD_ENDPOINTS=http://{{k8smaster}}:2379" {{k8sfile}}'
        - name: 修改配置文件4
          shell: 'sed -i "13cMASTER_IP={{k8smaster}}" {{k8sfile}}'
         - name : 启动配置
           shell: "cd /opt/kubernetes-starter && ./gen-config.sh simple"
    

    相关文章

      网友评论

        本文标题:记录k8s搭建过程中使用的playbook

        本文链接:https://www.haomeiwen.com/subject/sepqsqtx.html