我已经在 docker 中设置了一个私有注册表,可以通过域“makdom.ddns.net”访问,我可以在本地登录推送和拉取图像,即使是从 kubes 节点我也可以做到这一点,
但是当我编写一个 kubes 部署文件时,它无法从私有注册表中提取图像并且失败。
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ssh-deployment
spec:
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: ssh-demo
image: makdom.ddns.net/my-ubuntu
imagePullPolicy: IfNotPresent
ports:
- name: nodejs-port
containerPort: 22
imagePullSecrets:
- name: myregistrykey
秘密:
DOCKER_REGISTRY_SERVER="https://makdom.ddns.net/v1/"
DOCKER_USER="user"
DOCKER_PASSWORD="password"
DOCKER_EMAIL="[email protected]"
kubectl create secret docker-registry myregistrykey \
--docker-server=$DOCKER_REGISTRY_SERVER \
--docker-username=$DOCKER_USER \
--docker-password=$DOCKER_PASSWORD \
--docker-email=$DOCKER_EMAIL
错误:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 1m default-scheduler Successfully assigned ssh-deployment-7b7c7bf977-m6stk to kubes-slave
Normal SuccessfulMountVolume 1m kubelet, kubes-slave MountVolume.SetUp succeeded for volume "default-token-mx7qq"
Normal Pulled 1m (x3 over 1m) kubelet, kubes-slave Container image "makdom.ddns.net/my-ubuntu" already present on machine
Normal Created 1m (x3 over 1m) kubelet, kubes-slave Created container
Normal Started 1m (x3 over 1m) kubelet, kubes-slave Started container
Normal Pulling 34s (x2 over 1m) kubelet, kubes-slave pulling image "makdom.ddns.net/my-ubuntu"
Warning Failed 34s (x2 over 1m) kubelet, kubes-slave Failed to pull image "makdom.ddns.net/my-ubuntu": rpc error: code = Unknown desc = Error: image my-ubuntu:latest not found
Warning Failed 34s (x2 over 1m) kubelet, kubes-slave Error: ErrImagePull
Warning BackOff 19s (x6 over 1m) kubelet, kubes-slave Back-off restarting failed container
已知问题https://github.com/kubernetes/kubernetes/issues/57427 ,在https://github.com/kubernetes/kubernetes/pull/57463的 master 中解决
https://github.com/kubernetes/kubernetes/pull/57472中针对 1.9.1 的针对性修复
在那之前的解决方法:
如果您的私有注册表已有 .dockerconfigjson,则可以手动指定类型和数据键:
如果您还没有 .dockerconfigjson 文件,您可以修复
kubectl create secret docker-registry
手动生成的秘密:--dry-run -o yaml > secret.yaml
kubernetes.io/dockercfg
为kubernetes.io/dockercfgjson
.dockercfg
为.dockercfgjson
kubectl create -f secret.yaml