pir

command module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 5 Imported by: 0

README

(P)od (I)mages (R)ewriter

简介

由于众所周知的原因,从 quay.io 或者 k8s.gcr.io 拉取镜像的速度非常慢,而 Azure China 刚好提供了 Container Registry Proxy,但如果要手动改每个 Deployment/StatefulSet/DaemonSet etc. 的 container 的 image 会非常繁琐,而 pir 通过 mutating admission webhook 实现了通过用户定义的规则来修改 container 的 image,目前支持正则匹配、前缀匹配、子字符串匹配,不需要手工去改 image 了。

部署

pir 依赖 cert-manager (版本不低于 0.11.0),如果集群里没有部署 cert-manager 的话,可以通过以下命令部署:

curl -L https://github.com/jetstack/cert-manager/releases/download/v0.11.0/cert-manager-no-webhook.yaml|kubectl create -f -

部署 pir:

git clone https://github.com/knight42/pir.git
kubectl create -f pir/.assets

给希望 pir 生效的 namespace 打上 rewrite-images-enabled=true 的 label:

kubectl label <NAMESPACE> rewrite-images-enabled=true

如果希望 pir 在所有的 namespace 下都生效的话,可以去掉名为 pod-images-rewritermutatingwebhookconfigurations 里面的 namespaceSelector

kubectl edit mutatingwebhookconfigurations pod-images-rewriter

配置

上面部署的时候会在 default namespace 创建名为 pod-images-rewriter-config 的 ConfigMap,配置如下:

rules:
  - type: regex # Available values: regex | prefix | substring
    match: "^([^/]+):(.+)"
    replace: "dockerhub.azk8s.cn/library/${1}:${2}"
  - type: regex
    match: "^([^/]+)/([^:]+):(.+)"
    replace: "dockerhub.azk8s.cn/${1}/${2}:${3}"
  - type: prefix
    match: "gcr.io"
    replace: "gcr.azk8s.cn"
  - type: prefix
    match: "k8s.gcr.io"
    replace: "gcr.azk8s.cn/google_containers"
  - type: prefix
    match: "quay.io"
    replace: "quay.azk8s.cn"

pir 会每 30s 检查一次配置是否更新,如果有更新的话就重载配置。

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL