安装docker
#拷贝另一台work节点的二进制文件 到/usr/bin/下
- name: copy docker to /usr/bin
copy: src={{ item }} dest=/usr/bin/{{ item }} mode=755
with_items:
- docker
- dockerd
- docker-init
- docker-proxy
- containerd
- containerd-shim
- containerd-shim-runc-v2
- ctr
- runc
#创建docker目录 /etc/docker
- name: make config dir "/etc/docker"
file: dest=/etc/docker mode=755 state=directory
#拷贝另一台work节点的daemon.json文件到/etc/docker/daemon.json
- name: copy config file docker to /etc/docker
template: src=daemon.json dest=/etc/docker/daemon.json
#拷贝另一台work节点的docker.service文件到/usr/lib/systemd/system/docker.service
- name: copy docker.service to /usr/lib/systemd/system
copy: src=docker.service dest=/usr/lib/systemd/system/docker.service
#拷贝另一台work节点的containerd.service文件到/usr/lib/systemd/system/containerd.service
- name: copy containerd.service to /usr/lib/systemd/system
copy: src=containerd.service dest=/usr/lib/systemd/system/containerd.service
#拷贝另一台work节点的docker.socket文件到/usr/lib/systemd/system/docker.socket
- name: copy docker.socket to /usr/lib/systemd/system
copy: src=docker.socket dest=/usr/lib/systemd/system/docker.socket
#启动并检查服务状态 systemctl daemon-reload
- name: systemctl daemon-reload
command: systemctl daemon-reload
#重启docker systemctl restart docker
- name: systemctl daemon-reload
command: systemctl restart docker
#检查docker状态 systemctl status docker
- name: check docker service started ok
command: systemctl status docker
安装kubelet和kube-proxy
---
#拷贝另一台work节点的kubelet二进制文件到/usr/bin/下并赋予755权限
- name: cp kubelet to /usr/bin
copy: src=kubelet dest=/usr/bin/ mode=755
#拷贝另一台work节点的kube-proxy二进制文件到/usr/bin/下并赋予755权限
- name: copy kube-proxy to /usr/bin
copy: src=kube-proxy dest=/usr/bin/ mode=755
#创建/etc/kubernetes/ssl文件夹并赋755权限
- name: make dir /etc/kubernetes/ssl
file: dest=/etc/kubernetes/ssl mode=755 state=directory
#创建/var/run/kubernetes文件夹并赋755权限
- name: make dir /var/run/kubernetes
file: dest=/var/run/kubernetes mode=755 state=directory
#创建/opt/log/kubernetes文件夹并赋755权限
- name: make log dir "/opt/log/kubernetes"
file: dest={{kube_log_dir}} mode=755 state=directory
#拷贝另一台work节点的kubelet配置文件到/etc/kubernetes/kubelet下,并修改kubelet文件中hostname-override为本机地址
- name: copy config file kubelet to /etc/kubernetes
template: src=kubelet dest=/etc/kubernetes/kubelet
#拷贝另一台work节点proxy配置文件到/etc/kubernetes/proxy下,并修改proxy文件中hostname-override为本机地址
- name: copy config file proxy to /etc/kubernetes
template: src=proxy dest=/etc/kubernetes/proxy
#拷贝另一台work节点kubelet.config文件到/etc/kubernetes/kubelet.config
- name: copy config file kubelet.config to /etc/kubernetes
template: src=kubelet.config dest=/etc/kubernetes/kubelet.config
#拷贝另一台work节点kubelet.service文件到/usr/lib/systemd/system/kubelet.service
- name: copy kubelet.service to /usr/lib/systemd/system
copy: src=kubelet.service dest=/usr/lib/systemd/system/kubelet.service
#拷贝另一台work节点kube-proxy.service文件到/usr/lib/systemd/system/kube-proxy.service
- name: copy kube-proxy.service to /usr/lib/systemd/system
copy: src=kube-proxy.service dest=/usr/lib/systemd/system/kube-proxy.service
#创建/opt/kubernetes文件夹并赋755权限
- name: make dir /opt/kubernetes
file: dest={{ kube_dir }} mode=755 state=directory
#拷贝另一台work节点kubeconfig文件到/etc/kubernetes/ssl/下
- name: copy kubeconfig
template: src=kubeconfig dest=/etc/kubernetes/ssl/
#拷贝另一台work节点ca.crt文件到/etc/kubernetes/ssl/下
- name: copy ca.crt
copy: src={{ssl_tmp_dir}}/yunxing/ca.crt dest=/etc/kubernetes/ssl/
#拷贝另一台work节点client.key文件到/etc/kubernetes/ssl/下
- name: copy client.key
copy: src={{ssl_tmp_dir}}/yunxing/client.key dest=/etc/kubernetes/ssl/
#拷贝另一台work节点client.crt 到/etc/kubernetes/ssl/下
- name: copy client.crt
copy: src={{ssl_tmp_dir}}/yunxing/client.crt dest=/etc/kubernetes/ssl/
#重载系统配置systemctl daemon-reload
- name: systemctl daemon-reload
command: systemctl daemon-reload
#重启kubelet systemctl restart kubelet
- name: start kubelet service
service: name=kubelet state=restarted enabled=yes
#重启kube-proxy systemctl restart kube-proxy
- name: start kube-proxy service
service: name=kube-proxy state=restarted enabled=yes
#查看kubelet状态 systemctl status kubelet
- name: check kubelet service started ok
command: systemctl status kubelet
#查看kube-proxy状态 systemctl status kube-proxy
- name: check kube-proxy service started ok
command: systemctl status kube-proxy