gpt4 book ai didi

docker - 如何通过kubectl在kubernetes中使用本地docker镜像

转载 作者:行者123 更新时间:2023-12-02 11:56:52 24 4
gpt4 key购买 nike

我创建了自定义Docker Image并将其存储在本地系统中,现在我想通过kubectl使用该Docker Image。

Docker镜像:-
1:-docker build -t backend:v1。

然后Kubernetes文件:-

apiVersion: apps/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: backend
namespace: web-console
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: backend
spec:
containers:
- env:
- name: mail_auth_pass
- name: mail_auth_user
- name: mail_from
- name: mail_greeting
- name: mail_service
- name: mail_sign
- name: mongodb_url
value: mongodb://mongodb.mongodb.svc.cluster.local/console
- name: server_host
value: "0.0.0.0"
- name: server_port
value: "3000"
- name: server_sessionSecret
value: "1234"
image: backend
imagePullPolicy: Never
name: backend
resources: {}
restartPolicy: Always
status: {}```

Command to run kubectl:- kubectl create -f backend-deployment.yaml

**getting Error:-**
error: error validating "backend-deployment.yaml": error validating data: [ValidationError(Deployment.spec.template.spec.containers[0].env[9]): unknown field "image" in io.k8s.api.core.v1.EnvVar, ValidationError(Deployment.spec.template.spec.containers[0].env[9]): unknown field "imagePullPolicy" in io.k8s.api.core.v1.EnvVar]; if you choose to ignore these errors, turn validation off with --validate=false

最佳答案

由于错误指定unknown field "image" and unknown field "imagePullPolicy"
您的kubernetes部署文件中存在语法错误。

在yaml文件中进行这些更改。

apiVersion: apps/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: backend
namespace: web-console
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: backend
spec:
containers:
- name: backend
image: backend
imagePullPolicy: Never
env:
- name: mail_auth_pass
- name: mail_auth_user
- name: mail_from
- name: mail_greeting
- name: mail_service
- name: mail_sign
- name: mongodb_url
value: mongodb://mongodb.mongodb.svc.cluster.local/console
- name: server_host
value: "0.0.0.0"
- name: server_port
value: "3000"
- name: server_sessionSecret
value: "1234"
resources: {}
restartPolicy: Always
status: {}

使用 https://kubeyaml.com/在线验证您的kubernetes yaml文件

或使用 kubectl apply --validate=true --dry-run=true -f deployment.yaml
希望这可以帮助。

关于docker - 如何通过kubectl在kubernetes中使用本地docker镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57167104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com