<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          深入理解 K3s 鏡像重寫:從配置到實際應(yīng)用

          共 10283字,需瀏覽 21分鐘

           ·

          2024-04-10 15:52

          什么是 K3s 鏡像重寫?

          在 K3s 鏡像倉庫配置中,每個 Mirror 都可以配備一組 Rewrites。這些 Rewrites 能夠根據(jù)正則表達式對鏡像標簽進行調(diào)整,解決了當(dāng)鏡像倉庫中的組織或項目結(jié)構(gòu)與上游不一致的情況。

          例如,以下配置將透明地從 harbor.kingsd.top/production/busybox:1.35 中拉取鏡像 docker.io/rancher/busybox:1.35

                
                root@ksd-1:~# cat /etc/rancher/k3s/registries.yaml
          mirrors:
            docker.io:
              endpoint:
                - https://harbor.kingsd.top
              rewrite:
                "^rancher/(.*)""production/$1"
          root@ksd-1:~#
          root@ksd-1:~# crictl pull rancher/busybox:1.35
          Image is up to date for sha256:8aa0a6afef383f794b4f9a3785899de3832551d6c895ba74c8d0c3357823f3de
          root@ksd-1:~# crictl image list
          IMAGE                                                                TAG                    IMAGE ID            SIZE
          docker.io/rancher/busybox                                            1.35                   8aa0a6afef383       2.21MB

          以上配置是 K3s 使用的容器鏡像倉庫的鏡像重寫(rewrite)配置。讓我們逐步解釋每個部分的含義:

          • mirrors: 這個部分定義了鏡像倉庫的配置。
          • docker.io: 這里指定了要配置的鏡像倉庫的名稱,即 Docker Hub。
          • endpoint: 定義了鏡像倉庫的地址。在這里,它是 https://harbor.kingsd.top。
          • rewrite: 這是一個重要的部分,它定義了鏡像的重寫規(guī)則。在這個例子中,它使用正則表達式來重寫鏡像的路徑。具體來說,它將以 "rancher/" 開頭的路徑重寫為 "production/",這意味著所有以 "rancher/" 開頭的鏡像將被重寫為以 "production/" 開頭。

          上面的示例中嘗試拉取 rancher/busybox:1.35,根據(jù)重寫規(guī)則,它將被重寫為 production/busybox:1.35。所以,如果在你的鏡像倉庫中存在 production/busybox:1.35,那么拉取將成功。

          讀到這,你可能認為 rancher/busybox:1.35 是從 dockerhub 拉取的。但其實 dockerhub 中是不存在 rancher/busybox:1.35 的,如果換個主機,這個鏡像是拉不到的:

                
                root@harbor:~# docker pull rancher/busybox:1.35
          Error response from daemon: manifest for rancher/busybox:1.35 not found: manifest unknown: manifest unknown

          使用 Harbor 作為 K3S 的鏡像代理緩存后端

          借助 K3s 強大的 rewrite 特性,我們得以精心配置,將 Harbor 巧妙地嵌入到 K3S 的鏡像代理緩存體系中,為整個容器化環(huán)境提供了高效、靈活的鏡像管理解決方案。

          創(chuàng)建 Harbor 代理緩存項目

          建議 Harbor 配置訪問外網(wǎng)的 HTTP(S) 代理,不使用外網(wǎng)代理無法獲取 gcr.io/k8s.gcr.io 的鏡像

          登入 Harbor 管理后臺 https://harbor.kingsd.top

          1. 左側(cè)邊欄 Administration => Registries => New Endpoint 創(chuàng)建 5 個 Endpoint:
          Provider Name Endpoint URL Access ID
          Docker Hub docker.io

          Quay quay.io https://quay.io 清空
          Quay gcr.io https://gcr.io 清空
          Quay k8s.gcr.io https://k8s.gcr.io 清空
          Quay ghcr.io https://ghcr.io 清空
          1. 左側(cè)邊欄 Projects => New Project 創(chuàng)建 5 個項目:
          Project Name Access Level Proxy Cache
          docker.io Public Endpoint: docker.io
          quay.io Public Endpoint: quay.io
          gcr.io Public Endpoint: gcr.io
          k8s.gcr.io Public Endpoint: k8s.gcr.io
          ghcr.io Public Endpoint: ghcr.io

          配置 K3S registries.yaml

                
                cat >/etc/rancher/k3s/registries.yaml <<EOF
          mirrors:
            docker.io:
              endpoint:
                - https://harbor.kingsd.top
              rewrite:
                "(^.+$)""docker.io/$1"
            quay.io:
              endpoint:
                - https://harbor.kingsd.top
              rewrite:
                "(^.+$)""quay.io/$1"
            gcr.io:
              endpoint:
                - https://harbor.kingsd.top
              rewrite:
                "(^.+$)""gcr.io/$1"
            k8s.gcr.io:
              endpoint:
                - https://harbor.kingsd.top
              rewrite:
                "(^.+$)""k8s.gcr.io/$1"
            ghcr.io:
              endpoint:
                - https://harbor.kingsd.top
              rewrite:
                "(^.+$)""ghcr.io/$1"
          EOF

          上述配置可以用作鏡像倉庫的緩存配置。通過這樣的配置,K3s 集群會將對于 quay.io、gcr.io、ghcr.io 等鏡像倉庫的拉取請求重定向到指定的 Harbor 鏡像倉庫地址,從而實現(xiàn)鏡像的緩存和加速。

          具體而言,這個配置中的 endpoint 部分指定了 Harbor 鏡像倉庫的地址,而 rewrite 部分則將鏡像路徑重寫為對應(yīng)的鏡像倉庫路徑。這樣一來,當(dāng) K3s 集群中的容器需要從 gcr.io 或 ghcr.io 拉取鏡像時,實際上會先從 Harbor 鏡像倉庫中拉取,從而提高鏡像拉取的速度,并減輕對外部鏡像倉庫的依賴。

          這種做法對于在封閉網(wǎng)絡(luò)環(huán)境下或需要控制對外部鏡像倉庫訪問的場景非常有用,同時也可以減少對公共鏡像倉庫的訪問頻率,降低鏡像拉取的時間和成本。

          參考:

          • 使用 Harbor 作為 K3S 的鏡像代理緩存后端:https://www.cnblogs.com/roy2220/p/14811537.html
          • K3s 私有鏡像倉庫配置:https://docs.k3s.io/installation/private-registry?_highlight=rewrite#mirrors


          A b o u t   k 3 s


          k 3 s     C N C F     K 8 S   發(fā) , 當(dāng)   C N C F     K 8 S   發(fā) 2 0 1 9 3 發(fā) , 發(fā) 關(guān) G i t H u b   S t a r 數(shù)   1 7 , 0 0 0 , 區(qū)   K 8 S   , K 3 s 1 0 0 , 2 , 3 0 % 。


          k 3 s   環(huán)   K u b e r n e t e s   發(fā) 設(shè) 滿 環(huán)   x 8 6 、 A R M 6 4     A R M v 7   、   K u b e r n e t e s   。 k 3 s   發(fā) , 發(fā) R a n c h e r   2 . X   +   k 3 s 數(shù) 據(jù)   K 8 S   務(wù) K u b e r n e t e s - a s - a - S e r v i c e   K u b e r n e t e s   E v e r y w h e r e 。

          k 3 s 區(qū)

          術(shù) 區(qū)

          網(wǎng) h t t p s : / / k 3 s . i o

          瀏覽 123
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  中文字幕第一页精品 | 欧美在线免费 | 大黑鸡巴干中国美女大肥臀视频 | 2021黄片 | 久久国产激情 |