其他分享
首页 > 其他分享> > ansible-playbook部署docker的方法

ansible-playbook部署docker的方法

作者:互联网

一、部署docker方法

1、yum

2、二进制

以二进制批量部署docker

二、Playbook配置文件

[root@k8s-master2 ~]# mkdir docker-deploy

[root@k8s-master2 ~]# cd docker-deploy/

[root@k8s-master2 docker-deploy]# ls

[root@k8s-master2 docker-deploy]# mkdir files

[root@k8s-master2 docker-deploy]# cd files/

root@k8s-master2 files]# ls

docker docker-18.09.6.tgz docker.service

[root@k8s-master2 docker-deploy]# more deploy.yaml

---

- hosts: webservers

  vars:

  remoter_user: root

  gather_facts: false

  

  tasks:

  - name: 分发解压包

    unarchive: src=/files/docker-18.09.6.tgz dest=/tmp

  - name: 移动二进制文件

    shell: mv /tmp/docker/* /usr/bin

  - name: 分发service文件

    copy: src=files/docker.service dest/usr/lib/systemd/system

  - name: 启动设置开机启动

    systemd: name=docker state=restarted enabled=yes

  - name: docker 启动状态

    shell: docker info

    register: docker

  - debug: var=docker.stdout_lines 

三、systemd管理服务

[root@k8s-master2 files]# more docker.service

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service containerd.service

Wants=network-online.target

[Service]

Type=notify

ExecStart=/usr/bin/dockerd

ExecReload=/bin/kill -s HUP $MAINPID

TimeoutSec=0

RestartSec=2

Restart=always

StartLimitBurst=3

StartLimitInterval=60s

LimitNOFILE=infinity

LimitNPROC=infinity

LimitCORE=infinity

TasksMax=infinity

Delegate=yes

KillMode=process

[Install]

WantedBy=multi-user.target

四、验证节点服务器docker启动

[root@k8s-master2 docker-deploy]# ansible-playbook deploy.yaml
在这里插入图片描述
在这里插入图片描述
[root@k8s-node2 ~]# docker --version

Docker version 18.09.6, build 481bc77

标签:master2,name,deploy,ansible,playbook,docker,k8s,root
来源: https://blog.csdn.net/songxi_bo/article/details/122860120