Kubernetes pull from image private network / fails to respec



我正在运行一个小型的3节点测试kubernetes集群(使用kubeadm),运行在Ubuntu Server 22.04上,使用法兰绒作为网络结构。我也有一个单独的gitlab私有服务器,与容器注册表设置和工作。

我遇到的问题是我有一个简单的测试部署,当我应用部署yaml时,它无法从gitlab私有服务器提取图像。

apiVersion: apps/v1
kind: Deployment
metadata:
name: platform-deployment
spec:
replicas: 1
selector:
matchLabels:
app: platform-service
template:
metadata:
labels:
app: platform-service
spec:
containers:
- name: platform-service
image: registry.examle.com/demo/platform-service:latest

Ubuntu Server:/etc/hosts(相关行)

192.168.1.30 registry.example.com
误差

Failed to pull image "registry.example.com/demo/platform-service:latest": 
rpc error: code = Unknown desc = failed to pull and unpack image 
"registry.example.com/deni/platform-service:latest": failed to resolve reference 
"registry.example.com/demo/platform-service:latest": failed to do request: Head 
"https://registry.example.com/v2/demo/platform-service/manifests/latest": dial tcp 
xxx.xxx.xxx.xxx:443: i/o timeout

"xxx.xxx.xxx。xxx'与我的外部网络有关,在DNS中存在一个域名,但是我所有的内部网络都被设置为连接到内部网络表示,并且'registry.example.com'是我自己的域名表示。

另需注意:

docker pull registry.example.com/demo/platform-service:latest

从服务器的命令行,工作得很好,它只是不能从kubernetes部署yaml。

虽然服务器上的网络和服务器上的主机文件配置正确,但docker映像没有解析,因为当我应用它时,它没有使用正确的IP(在hosts中配置),而是使用不同服务器的公共IP。超时的原因是因为面向公众的服务器没有设置相同。

当我运行kubectl apply -f platform-service.yaml时,为什么它不尊重服务器的hosts文件,是否有办法在Kubernetes中配置主机。

(如果这个问题不清楚,我很抱歉,我是新手,还在学习术语,也许为什么谷歌不帮我解决这个问题。)

我能找到的最近的S/O是:

Kubernetes无法从私有注册表中提取映像,私有域名指向/etc/hosts

(所以答案#1):hostAliases(这是为pod本身,而不是拉映像),也通过apt/包管理器安装,而不是snap。剩下的答案建议更改发行版,我宁愿使用我当前的设置而不是更改它。

尝试向coredns添加主机也不工作:(如何像coredns中的主机文件一样更改主机名解析)

kubectl -n kube-system edit configmap/coredns
...
.:53 {
errors
health {
lameduck 5s
}
ready
hosts custom.hosts registry.example.com {
192.168.1.30 registry.example.com
fallthrough
}
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf {
max_concurrent 1000
}
cache 30
loop
reload
loadbalance
}
...

删除coredns pod(以便重新创建)

,并且docker在部署上的pull仍然失败,使用外部IP地址而不是内部地址。

在经历了许多不同的解决方案和大量的研究和测试之后。答案其实很简单。

我的解决方案

/etc/hosts文件必须每个节点上包含注册表的主机(也可能包含gitlab实例的条目),包括主节点。

192.168.1.30 registry.example.com
192.168.1.30 gitlab.example.com    # Necessary in my case, not sure required

一旦我在2个从属服务器上都包含了这个,它就会尝试提取映像,并且由于凭据问题而失败(我希望在主机问题解决后看到这个问题)。从那里我可以添加凭据,现在图像从私有注册表而不是面向公共的注册表中提取。

奖励:修复连接到私有注册表的凭据错误(不是原始问题的一部分,而是连接设置过程的一部分)

修复/etc/hosts问题后,您可能需要设置'regcred'凭据来访问私有注册表,Kubernetes文档提供了这部分的步骤:

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

最新更新