gpt4 book ai didi

docker - 创建 "deployment.yaml": Deployment in version "v1" cannot be handled as a Deployment 时出错

转载 作者:行者123 更新时间:2023-12-02 11:27:59 32 4
gpt4 key购买 nike

我是 DevOps 的新手。我为刚刚在 Digital Oceans 上创建的 Kubernetes 集群编写了一个 deployment.yaml 文件。创建部署不断出现我现在无法解码的错误。这只是一个测试部署,为我公司的 Web 应用程序迁移到 kubernetes 做准备。

我尝试编辑部署的内容,使其看起来像我发现的常规示例。我什至无法让这个简单的例子起作用。您可以在下面找到 deployment.yaml 内容。

---
kind: Deployment
apiVersion: apps/v1
metadata:
name: testit-01-deployment
spec:
replicas: 4
#number of replicas generated
selector:
#assigns labels to the pods for future selection
matchLabels:
app: testit
version: v01
template:
metadata:
Labels:
app: testit
version: v01
spec:
containers:
-name: testit-container
image: teejayfamo/testit
ports:
-containerPort: 80

我在文件夹容器中的 cmd 上运行了这一行:
kubectl apply -f deployment.yaml --validate=false

Error from server (BadRequest): error when creating "deployment.yaml": Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: decode slice: expect [ or n, but found {, error found in #10 byte of ...|tainers":{"-name":"t|..., bigger context ...|:"testit","version":"v01"}},"spec":{"containers":{"-name":"testit-container","image":"teejayfamo/tes|...



我什至无法从搜索中获得任何有关此的信息。我不能只是创建部署。请问,谁理解并可以让我通过?

最佳答案

您的 yaml 文件中存在语法错误。

这应该有效。

---
kind: Deployment
apiVersion: apps/v1
metadata:
name: testit-01-deployment
spec:
replicas: 4
#number of replicas generated
selector:
#assigns labels to the pods for future selection
matchLabels:
app: testit
version: v01
template:
metadata:
labels:
app: testit
version: v01
spec:
containers:
- name: testit-container
image: teejayfamo/testit
ports:
- containerPort: 80

问题是:
  • Labels应该是 labels
  • - name: 的语法和 - containerPortspec.containers 中未正确格式化部分。

  • 希望这可以帮助。

    关于docker - 创建 "deployment.yaml": Deployment in version "v1" cannot be handled as a Deployment 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57233686/

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