ansible 部署 containerd

准备工作

创建数据目录

# mkdir -pv  files

hosts

[ubuntu]
172.168.174.106 ansible_ssh_port=22  ansible_ssh_user=root hostname=k8s-master-01

下载软件包

wget https://github.com/containerd/containerd/releases/download/v1.7.17/containerd-1.7.17-linux-amd64.tar.gz
wget https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.amd64
wget https://github.com/containernetworking/plugins/releases/download/v1.5.0/cni-plugins-linux-amd64-v1.5.0.tgz
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.30.0/crictl-v1.30.0-linux-amd64.tar.gz

install-containerd.yaml

- name: Install CNI plugins, Containerd, and configure runc
  hosts: all
  gather_facts: no
  vars:
    cni_version: 1.5.0
    containerd_version: 1.7.17
    crictl_version: 1.30.0
    files_dir: "./files"

  tasks:
    - name: Ensure necessary directories exist
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
      loop:
        - /opt/cni/bin
        - /etc/containerd
        - /usr/local/bin

    - name: Copy installation files to remote host
      ansible.builtin.copy:
        src: "{{ files_dir }}/{{ item.src }}"
        dest: "{{ item.dest }}"
        mode: "{{ item.mode | default('0640') }}"
      with_items:
        - { src: "cni-plugins-linux-amd64-v{{ cni_version }}.tgz", dest: "/tmp", mode: '0640' }
        - { src: "containerd-{{ containerd_version }}-linux-amd64.tar.gz", dest: "/tmp", mode: '0640' }
        - { src: "crictl-v{{ crictl_version }}-linux-amd64.tar.gz", dest: "/tmp", mode: '0640' }
        - { src: "runc.amd64", dest: "/usr/local/bin/runc", mode: '0755' }
        - { src: "containerd.service", dest: "/lib/systemd/system/containerd.service", mode: '0644' }
        - { src: "containerd-config.toml", dest: "/etc/containerd/config.toml", mode: '0644' }
        - { src: "crictl.yaml", dest: "/etc/crictl.yaml", mode: '0644' }

    - name: Unpack installation files
      ansible.builtin.unarchive:
        src: "/tmp/{{ item.src }}"
        dest: "{{ item.dest }}"
        remote_src: yes
      with_items:
        - { src: "cni-plugins-linux-amd64-v{{ cni_version }}.tgz", dest: "/opt/cni/bin" }
        - { src: "containerd-{{ containerd_version }}-linux-amd64.tar.gz", dest: "/usr/local" }
        - { src: "crictl-v{{ crictl_version }}-linux-amd64.tar.gz", dest: "/usr/local/bin" }

    - name: Start the containerd service
      ansible.builtin.systemd:
        name: containerd
        state: started
        enabled: yes
      notify: containerd status

    - name: Clean up installation files
      ansible.builtin.file:
        path: "/tmp/{{ item }}"
        state: absent
      loop:
        - "cni-plugins-linux-amd64-v{{ cni_version }}.tgz"
        - "containerd-{{ containerd_version }}-linux-amd64.tar.gz"
        - "crictl-v{{ crictl_version }}-linux-amd64.tar.gz"

  handlers:
    - name: containerd status
      ansible.builtin.service:
        name: containerd
        state: restarted
        enabled: yes

运行 playbook

# ansible-playbook -i hosts install-containerd.yaml 

PLAY [Install CNI plugins, Containerd, and configure runc] ******************************************************************************************************************************************************

TASK [Ensure necessary directories exist] ***********************************************************************************************************************************************************************
changed: [192.168.174.106] => (item=/opt/cni/bin)
changed: [192.168.174.106] => (item=/etc/containerd)
ok: [192.168.174.106] => (item=/usr/local/bin)

TASK [Copy installation files to remote host] *******************************************************************************************************************************************************************
changed: [192.168.174.106] => (item={'src': 'cni-plugins-linux-amd64-v1.5.0.tgz', 'dest': '/tmp', 'mode': '0640'})
changed: [192.168.174.106] => (item={'src': 'containerd-1.7.17-linux-amd64.tar.gz', 'dest': '/tmp', 'mode': '0640'})
changed: [192.168.174.106] => (item={'src': 'crictl-v1.30.0-linux-amd64.tar.gz', 'dest': '/tmp', 'mode': '0640'})
changed: [192.168.174.106] => (item={'src': 'runc.amd64', 'dest': '/usr/local/bin/runc', 'mode': '0755'})
changed: [192.168.174.106] => (item={'src': 'containerd.service', 'dest': '/lib/systemd/system/containerd.service', 'mode': '0644'})
changed: [192.168.174.106] => (item={'src': 'containerd-config.toml', 'dest': '/etc/containerd/config.toml', 'mode': '0644'})
changed: [192.168.174.106] => (item={'src': 'crictl.yaml', 'dest': '/etc/crictl.yaml', 'mode': '0644'})

TASK [Unpack installation files] ********************************************************************************************************************************************************************************
changed: [192.168.174.106] => (item={'src': 'cni-plugins-linux-amd64-v1.5.0.tgz', 'dest': '/opt/cni/bin'})
changed: [192.168.174.106] => (item={'src': 'containerd-1.7.17-linux-amd64.tar.gz', 'dest': '/usr/local'})
changed: [192.168.174.106] => (item={'src': 'crictl-v1.30.0-linux-amd64.tar.gz', 'dest': '/usr/local/bin'})

TASK [Start the containerd service] *****************************************************************************************************************************************************************************
changed: [192.168.174.106]

TASK [Clean up installation files] ******************************************************************************************************************************************************************************
changed: [192.168.174.106] => (item=cni-plugins-linux-amd64-v1.5.0.tgz)
changed: [192.168.174.106] => (item=containerd-1.7.17-linux-amd64.tar.gz)
changed: [192.168.174.106] => (item=crictl-v1.30.0-linux-amd64.tar.gz)

RUNNING HANDLER [containerd status] *****************************************************************************************************************************************************************************
changed: [192.168.174.106]

PLAY RECAP ******************************************************************************************************************************************************************************************************
192.168.174.106            : ok=6    changed=6    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

config.toml

disabled_plugins = []
imports = []
oom_score = 0
plugin_dir = ""
required_plugins = []
root = "/var/lib/containerd"
state = "/run/containerd"
temp = ""
version = 2

[cgroup]
  path = ""

[debug]
  address = ""
  format = ""
  gid = 0
  level = ""
  uid = 0

[grpc]
  address = "/run/containerd/containerd.sock"
  gid = 0
  max_recv_message_size = 16777216
  max_send_message_size = 16777216
  tcp_address = ""
  tcp_tls_ca = ""
  tcp_tls_cert = ""
  tcp_tls_key = ""
  uid = 0

[metrics]
  address = ""
  grpc_histogram = false

[plugins]

  [plugins."io.containerd.gc.v1.scheduler"]
    deletion_threshold = 0
    mutation_threshold = 100
    pause_threshold = 0.02
    schedule_delay = "0s"
    startup_delay = "100ms"

  [plugins."io.containerd.grpc.v1.cri"]
    cdi_spec_dirs = ["/etc/cdi", "/var/run/cdi"]
    device_ownership_from_security_context = false
    disable_apparmor = false
    disable_cgroup = false
    disable_hugetlb_controller = true
    disable_proc_mount = false
    disable_tcp_service = true
    drain_exec_sync_io_timeout = "0s"
    enable_cdi = false
    enable_selinux = false
    enable_tls_streaming = false
    enable_unprivileged_icmp = false
    enable_unprivileged_ports = false
    ignore_deprecation_warnings = []
    ignore_image_defined_volumes = false
    image_pull_progress_timeout = "5m0s"
    image_pull_with_sync_fs = false
    max_concurrent_downloads = 3
    max_container_log_line_size = 16384
    netns_mounts_under_state_dir = false
    restrict_oom_score_adj = false
    sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
    selinux_category_range = 1024
    stats_collect_period = 10
    stream_idle_timeout = "4h0m0s"
    stream_server_address = "127.0.0.1"
    stream_server_port = "0"
    systemd_cgroup = false
    tolerate_missing_hugetlb_controller = true
    unset_seccomp_profile = ""

    [plugins."io.containerd.grpc.v1.cri".cni]
      bin_dir = "/opt/cni/bin"
      conf_dir = "/etc/cni/net.d"
      conf_template = ""
      ip_pref = ""
      max_conf_num = 1
      setup_serially = false

    [plugins."io.containerd.grpc.v1.cri".containerd]
      default_runtime_name = "runc"
      disable_snapshot_annotations = true
      discard_unpacked_layers = false
      ignore_blockio_not_enabled_errors = false
      ignore_rdt_not_enabled_errors = false
      no_pivot = false
      snapshotter = "overlayfs"

      [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime]
        base_runtime_spec = ""
        cni_conf_dir = ""
        cni_max_conf_num = 0
        container_annotations = []
        pod_annotations = []
        privileged_without_host_devices = false
        privileged_without_host_devices_all_devices_allowed = false
        runtime_engine = ""
        runtime_path = ""
        runtime_root = ""
        runtime_type = ""
        sandbox_mode = ""
        snapshotter = ""

        [plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.options]

      [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]

        [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
          base_runtime_spec = ""
          cni_conf_dir = ""
          cni_max_conf_num = 0
          container_annotations = []
          pod_annotations = []
          privileged_without_host_devices = false
          privileged_without_host_devices_all_devices_allowed = false
          runtime_engine = ""
          runtime_path = ""
          runtime_root = ""
          runtime_type = "io.containerd.runc.v2"
          sandbox_mode = "podsandbox"
          snapshotter = ""

          [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
            BinaryName = ""
            CriuImagePath = ""
            CriuPath = ""
            CriuWorkPath = ""
            IoGid = 0
            IoUid = 0
            NoNewKeyring = false
            NoPivotRoot = false
            Root = ""
            ShimCgroup = ""
            SystemdCgroup = true

      [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime]
        base_runtime_spec = ""
        cni_conf_dir = ""
        cni_max_conf_num = 0
        container_annotations = []
        pod_annotations = []
        privileged_without_host_devices = false
        privileged_without_host_devices_all_devices_allowed = false
        runtime_engine = ""
        runtime_path = ""
        runtime_root = ""
        runtime_type = ""
        sandbox_mode = ""
        snapshotter = ""

        [plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime.options]

    [plugins."io.containerd.grpc.v1.cri".image_decryption]
      key_model = "node"

    [plugins."io.containerd.grpc.v1.cri".registry]
      config_path = ""

      [plugins."io.containerd.grpc.v1.cri".registry.auths]

      [plugins."io.containerd.grpc.v1.cri".registry.configs]

      [plugins."io.containerd.grpc.v1.cri".registry.headers]

      [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
          endpoint = ["https://registry.cn-hangzhou.aliyuncs.com", "https://registry.docker-cn.com", "https://docker.mirrors.ustc.edu.cn"]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.k8s.io"]
          endpoint = ["https://registry.cn-hangzhou.aliyuncs.com/google_containers"]

    [plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]
      tls_cert_file = ""
      tls_key_file = ""

  [plugins."io.containerd.internal.v1.opt"]
    path = "/opt/containerd"

  [plugins."io.containerd.internal.v1.restart"]
    interval = "10s"

  [plugins."io.containerd.internal.v1.tracing"]
    sampling_ratio = 1.0
    service_name = "containerd"

  [plugins."io.containerd.metadata.v1.bolt"]
    content_sharing_policy = "shared"

  [plugins."io.containerd.monitor.v1.cgroups"]
    no_prometheus = false

  [plugins."io.containerd.nri.v1.nri"]
    disable = true
    disable_connections = false
    plugin_config_path = "/etc/nri/conf.d"
    plugin_path = "/opt/nri/plugins"
    plugin_registration_timeout = "5s"
    plugin_request_timeout = "2s"
    socket_path = "/var/run/nri/nri.sock"

  [plugins."io.containerd.runtime.v1.linux"]
    no_shim = false
    runtime = "runc"
    runtime_root = ""
    shim = "containerd-shim"
    shim_debug = false

  [plugins."io.containerd.runtime.v2.task"]
    platforms = ["linux/amd64"]
    sched_core = false

  [plugins."io.containerd.service.v1.diff-service"]
    default = ["walking"]

  [plugins."io.containerd.service.v1.tasks-service"]
    blockio_config_file = ""
    rdt_config_file = ""

  [plugins."io.containerd.snapshotter.v1.aufs"]
    root_path = ""

  [plugins."io.containerd.snapshotter.v1.blockfile"]
    fs_type = ""
    mount_options = []
    root_path = ""
    scratch_file = ""

  [plugins."io.containerd.snapshotter.v1.btrfs"]
    root_path = ""

  [plugins."io.containerd.snapshotter.v1.devmapper"]
    async_remove = false
    base_image_size = ""
    discard_blocks = false
    fs_options = ""
    fs_type = ""
    pool_name = ""
    root_path = ""

  [plugins."io.containerd.snapshotter.v1.native"]
    root_path = ""

  [plugins."io.containerd.snapshotter.v1.overlayfs"]
    mount_options = []
    root_path = ""
    sync_remove = false
    upperdir_label = false

  [plugins."io.containerd.snapshotter.v1.zfs"]
    root_path = ""

  [plugins."io.containerd.tracing.processor.v1.otlp"]
    endpoint = ""
    insecure = false
    protocol = ""

  [plugins."io.containerd.transfer.v1.local"]
    config_path = ""
    max_concurrent_downloads = 3
    max_concurrent_uploaded_layers = 3

    [[plugins."io.containerd.transfer.v1.local".unpack_config]]
      differ = ""
      platform = "linux/amd64"
      snapshotter = "overlayfs"

[proxy_plugins]

[stream_processors]

  [stream_processors."io.containerd.ocicrypt.decoder.v1.tar"]
    accepts = ["application/vnd.oci.image.layer.v1.tar+encrypted"]
    args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
    env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
    path = "ctd-decoder"
    returns = "application/vnd.oci.image.layer.v1.tar"

  [stream_processors."io.containerd.ocicrypt.decoder.v1.tar.gzip"]
    accepts = ["application/vnd.oci.image.layer.v1.tar+gzip+encrypted"]
    args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]
    env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]
    path = "ctd-decoder"
    returns = "application/vnd.oci.image.layer.v1.tar+gzip"


[timeouts]
  "io.containerd.timeout.bolt.open" = "0s"
  "io.containerd.timeout.metrics.shimstats" = "2s"
  "io.containerd.timeout.shim.cleanup" = "5s"
  "io.containerd.timeout.shim.load" = "5s"
  "io.containerd.timeout.shim.shutdown" = "3s"
  "io.containerd.timeout.task.state" = "2s"

[ttrpc]
  address = ""
  gid = 0
  uid = 0

参考文档

https://github.com/containerd/containerd/blob/main/docs/getting-started.md

posted @ 2024-05-31 18:41  小吉猫  阅读(38)  评论(0编辑  收藏  举报