为Kubernetes配置私有仓库

如题

创建访问私有仓库的令牌-Secret

1
2
3
4
kubectl create secret docker-registry regcred   \
    --docker-server=<your-registry-server>      \
    --docker-username=<your-name>               \
    --docker-password=<your-pword>

查看私有仓库的令牌

1
kubectl get secret regcred -o json

创建一个使用私有仓库的Pod

创建 pods/private-reg-pod.yaml

1
2
3
4
5
6
7
8
9
10
apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: <your-private-image>
  imagePullSecrets:
  - name: regcred

其中使用imagePullSecrets配置的凭证来获取私有镜像

1
2
kubectl create -f my-private-reg-pod.yaml
kubectl get pod private-reg