From d936bc22b08d4e15546ab7f15bc2ff8467698163 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Mon, 30 Sep 2024 17:49:20 +0800 Subject: [PATCH] add set-containerd-proxy.yaml --- set-contained-proxy.yaml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 set-contained-proxy.yaml diff --git a/set-contained-proxy.yaml b/set-contained-proxy.yaml new file mode 100644 index 0000000..43682d0 --- /dev/null +++ b/set-contained-proxy.yaml @@ -0,0 +1,39 @@ +- name: Configure HTTP proxy for containerd + hosts: all + become: yes + user: root + tasks: + - name: Check if kubelet service is running + shell: systemctl is-active kubelet + register: kubelet_status + ignore_errors: yes + + - name: Create directory for containerd service override + file: + path: /etc/systemd/system/containerd.service.d + state: directory + when: kubelet_status.stdout == "active" + + - name: Create or edit http-proxy.conf for containerd + blockinfile: + path: /etc/systemd/system/containerd.service.d/http-proxy.conf + create: yes + block: | + [Service] + Environment="HTTP_PROXY=http://192.168.1.38:7890" + Environment="HTTPS_PROXY=http://192.168.1.38:7890" + Environment="NO_PROXY=localhost" + when: kubelet_status.stdout == "active" + + - name: Reload systemd daemon + command: systemctl daemon-reload + when: kubelet_status.stdout == "active" + + - name: Restart containerd and kubelet services + systemd: + name: "{{ item }}" + state: restarted + loop: + - containerd + - kubelet + when: kubelet_status.stdout == "active"