[英]Kubernetes pull images from private registry fails --> unknown field "imagePullPolicy"
I'm trying to pull an image from my priavte harbor registry.我正在尝试从我的 priavte 港口注册表中提取图像。 In Kubernetes I created a secret first as explained in this documentation:
在 Kubernetes 中,我首先创建了一个秘密,如本文档中所述:
https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
Then I tried to implement that into my deployment.yaml:然后我尝试将其实现到我的 deployment.yaml 中:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-k8s-test9
namespace: k8s-test9
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-k8s-test9
spec:
containers:
- name: nginx-k8s-test9
image: my-registry.com/nginx-test/nginx:1.14.2
imagePullSecrets:
- name: harborcred
imagePullPolicy: Always
volumeMounts:
- name: webcontent
mountPath: usr/share/nginx/html
ports:
- containerPort: 80
volumes:
- name: webcontent
configMap:
name: webcontent
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: webcontent
namespace: k8s-test9
annotations:
volume.alpha.kubernetes.io/storage-class: default
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 5Gi
When I try to create the deployment I get the following error message:当我尝试创建部署时,我收到以下错误消息:
error: error validating "deployment.yaml": error validating data: [ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "imagePullPolicy" in io.k8s.api.core.v1.LocalObjectReference, ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "ports" in io.k8s.api.core.v1.LocalObjectReference, ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "volumeMounts" in io.k8s.api.core.v1.LocalObjectReference]; if you choose to ignore these errors, turn validation off with --validate=false
I guess it's a yaml issue somehow but I don't know where it should be.我想这是一个 yaml 问题,但我不知道它应该在哪里。
And here is the solution:这是解决方案:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-k8s-test9
namespace: k8s-test9
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-k8s-test9
spec:
containers:
- name: nginx-k8s-test9
image: my-registry.com/nginx-test/nginx:1.14.2
volumeMounts:
- name: webcontent
mountPath: usr/share/nginx/html
ports:
- containerPort: 80
volumes:
- name: webcontent
configMap:
name: webcontent
imagePullSecrets:
- name: harborcred-test
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: webcontent
namespace: k8s-test9
annotations:
volume.alpha.kubernetes.io/storage-class: default
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 5Gi
The imagePullSecrets section was not at the right place. imagePullSecrets 部分不在正确的位置。
can you chnage your config like this any give a try你能像这样改变你的配置吗?
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: webcontent
namespace: k8s-test9
annotations:
volume.alpha.kubernetes.io/storage-class: default
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 5Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-k8s-test9
namespace: k8s-test9
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-k8s-test9
spec:
containers:
- name: nginx-k8s-test9
image: my-registry.com/nginx-test/nginx:1.14.2
imagePullSecrets:
- name: harborcred
imagePullPolicy: Always
volumeMounts:
- name: webcontent
mountPath: usr/share/nginx/html
ports:
- containerPort: 80
volumes:
- name: webcontent
configMap:
name: webcontent
with kubectl apply -f deployment.yaml
if it's not work try使用
kubectl apply -f deployment.yaml
如果它不起作用尝试
kubectl apply -f deployment.yaml --validate=false
I resolved this via creating & providing secret in pipeline and not editing the .yaml file我通过在管道中创建和提供秘密而不是编辑 .yaml 文件来解决这个问题
we had requirement was not to save secret in .yaml file as it was fetched from repo我们要求不要将机密保存在 .yaml 文件中,因为它是从 repo 中获取的
step 1: create pipeline add a task第 1 步:创建管道添加任务
Deploy to Kubernetes >> choose Action: Create Secret - can find step how to create secrets部署到 Kubernetes >> 选择 Action: Create Secret - 可以找到如何创建密钥的步骤
step 2: Then in any Task where you are pulling the .yaml file can use the secret by providing the secret name in ImagePullSecrets of Deploy to Kubernetes第 2 步:然后在任何要拉取 .yaml 文件的任务中,都可以通过在 Deploy to Kubernetes 的 ImagePullSecrets 中提供机密名称来使用该机密
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.