跳转至

配置私有镜像仓库凭证

1. docker 配置添加

在 Nexus 虚拟机192.168.100.12上,获取 docker 配置~/.docker/config.json如下:

{
  "auths": {
    "192.168.100.12:8082": {
      "auth": "**********"
    },
    "192.168.100.12:8083": {
      "auth": "**********"
    }
  }
}

将此配置复制到 kubernetes 的 master 节点的/tmp/config.json,并加入凭证到 keycloak 命名空间:

kubectl -n keycloak create secret generic nexus-regcred --from-file=.dockerconfigjson=/tmp/config.json --type=kubernetes.io/dockerconfigjson

2. CA 证书添加

在 Nexus 虚拟机192.168.100.12上,获取 CA 证书/etc/docker/certs.d/192.168.100.12:8082/ca.crt,将其复制到所有 k8s 节点的/etc/pki/ca-trust/source/anchors/nexus.crt,并在所有节点更新证书:

update-ca-trust

之后还需要重启 containerd:

systemctl restart containerd.service

3. 使用凭证拉取镜像

在命名空间 keycloak 创建一个 pod,使用凭证 nexus-regcred 拉取镜像,新建文件test-pod.yaml

test-pod.yaml
---
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
  namespace: keycloak
spec:
  containers:
    - name: keycloak
      image: 192.168.100.12:8082/keycloak/keycloak:24.0
  imagePullSecrets:
    - name: nexus-regcred

创建 pod:

kubectl create -f test-pod.yaml