怎么搭建一個集成了containerd的k8s集群

這篇文章主要講解了“怎么搭建一個集成了containerd的k8s集群”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么搭建一個集成了containerd的k8s集群”吧!

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名申請、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、路橋網(wǎng)站維護、網(wǎng)站推廣。

概念介紹

  • cri (Container runtime interface)

    • cri is a containerd plugin implementation of Kubernetes container runtime interface (CRI).

    • cri是 kubernetes的容器運行時接口的容器插件實現(xiàn)。

<!--more-->

  • containerd

    • containerd is an industry-standard container runtime with an emphasis on simplicity, robustness and portability.

    • containerd完全支持運行容器的的CRI運行時規(guī)范。

    • cri在containerd1.1以上的版本的原生插件。它內(nèi)置于containerd并默認啟用。

  • cri-o

    • OCI-based implementation of Kubernetes Container Runtime Interface.

    • kubernetes為了兼容cri和oci孵化了項目cri-o。為了架設(shè)在cri和oci之間的一座橋梁。由此cri-o既兼容cri插件實現(xiàn)又兼容oci的容器運行時標準。

  • oci (Open Container Initiative)

    • oci是由多家公司成立的項目,并由linux基金會進行管理,致力于container runtime 的標準的制定和runc的開發(fā)等工作。

  • runc

    • runc is a CLI tool for spawning and running containers according to the OCI specification.

    • runc,是對于OCI標準的一個參考實現(xiàn),是一個可以用于創(chuàng)建和運行容器的CLI(command-line interface)工具。

概述

由于docker嵌入了太多自身內(nèi)容,為了減輕容器負擔(dān)。此次選用containerd作為kubernetes的容器實現(xiàn)方案。

環(huán)境準備

下載containerd二進制包。我這里已經(jīng)編譯并打包了好了,內(nèi)含containerd、runc、crictl、ctr等。

  • runc版本: 1.0.1-dev

  • containerd版本: v1.2.4

安裝

安裝containerd

  • 解壓二進制包并生成默認文件

    tar -C /usr/local/bin -xzf containerd-v1.2.4.tar.gz
    chmod a+x /usr/local/bin/*
    containerd config default > /etc/containerd/config.toml

    生成的默認配置文件注意 [grpc]address 字段默認為 /run/containerd/containerd.sock

    配置文件其他參數(shù)含義參照github地址: https://github.com/containerd/containerd/blob/master/docs/man/containerd-config.toml.5.md

  • /etc/systemd/system 目錄下編寫文件 containerd.service內(nèi)容如下

    [Unit]
    Description=containerd container runtime
    Documentation=https://containerd.io
    After=network.target
    
    [Service]
    ExecStartPre=/sbin/modprobe overlay
    ExecStart=/usr/local/bin/containerd
    Restart=always
    RestartSec=5
    Delegate=yes
    KillMode=process
    OOMScoreAdjust=-999
    LimitNOFILE=1048576
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNPROC=infinity
    LimitCORE=infinity
    
    [Install]
    WantedBy=multi-user.target

  • 啟動containerd

    systemctl enable containerd
    systemctl restart containerd
    systemctl status containerd

    看containerd啟動狀態(tài)如果是running就沒有問題。下面我們測試拉取一下hub的鏡像。

  • 測試containerd

    ctr images pull docker.io/library/nginx:alpine

    看到輸出done,說明containerd運行一切正常。

使用crictl連接containerd

下一步我們使用crictl連接containerd。

  • 修改crictl的配置文件,在 /etc/crictl.yaml 寫入以下內(nèi)容:

    runtime-endpoint: unix:///run/containerd/containerd.sock
    image-endpoint: unix:///run/containerd/containerd.sock
    timeout: 10
    debug: false

    這里注意runtime-endpoint 和image-endpoint 必須與/etc/containerd/config.toml中配置保持一致。

  • 驗證一下cri插件是否可用

    crictl  pull nginx:alpine
    crictl  rmi  nginx:alpine
    crictl  images

    其中 crictl images 會列出所有的cri容器鏡像。

    到此我們的cri + containerd已經(jīng)完成整合了。下一步我們需要修改kubeadm配置進行安裝。

導(dǎo)入kubenetes離線鏡像包

這里我們就需要導(dǎo)入k8s的離線鏡像包了。這里需要注意一下,kubernetes是調(diào)用的cri接口,所以導(dǎo)入時也需要從cri插件導(dǎo)入鏡像。

  • cri導(dǎo)入鏡像命令(cri導(dǎo)入鏡像):

     ctr cri load  images.tar

  • containerd導(dǎo)入鏡像命令(containerd導(dǎo)入鏡像):

     ctr images import images.tar

修改kubelet配置和kubeadm安裝時配置

  • 在 kubelet配置文件 10-kubeadm.conf 的[Service] 結(jié)點加入以下配置:

    Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock"

  • 在kubeadm配置文件 kubeadm.yaml 中加入

    apiVersion: kubeadm.k8s.io/v1beta1
    kind: InitConfiguration
    nodeRegistration:
      criSocket: /run/containerd/containerd.sock
      name: containerd

    到此containerd和kubernetes的集成就完成了。下面可以直接安裝即可。

感謝各位的閱讀,以上就是“怎么搭建一個集成了containerd的k8s集群”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么搭建一個集成了containerd的k8s集群這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

本文題目:怎么搭建一個集成了containerd的k8s集群
當前鏈接:http://bm7419.com/article40/goisho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、響應(yīng)式網(wǎng)站、網(wǎng)站設(shè)計公司品牌網(wǎng)站建設(shè)、面包屑導(dǎo)航、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司