【问题标题】:How to use apply instead of create for deployment in Kubernetes?如何在 Kubernetes 中使用 apply 而不是 create 进行部署?
【发布时间】:2018-06-03 04:53:33
【问题描述】:

我正在尝试使用kubectl apply 以声明方式创建部署。当我这样做时,以下配置创建得很好

kubectl create -f postgres-deployment.yaml

如果我去

kubectl apply -f postgres-deployment.yaml

我收到了可爱的错误消息:

错误:无法解码“postgres-deployment.yaml”:没有种类 为版本“apps/v1beta1”注册了“部署”

我试图寻找解释这意味着什么,但我无法弄清楚。

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:10.1
        ports:
        - containerPort: 5432

【问题讨论】:

  • 你能发布kubectl version的输出吗
  • 来自kubectl apply --helpTo use 'apply', always create the resource initially with either 'apply' or 'create --save-config'。所以也许试试kubectl create --save-config -f postgres-deployment.yaml,然后使用kubectl apply -f postgres-deployment.yaml
  • 这能回答你的问题吗? kubectl apply vs kubectl create?

标签: kubernetes


【解决方案1】:

旧 Kubernetes 版本支持 extensions/v1beta1 API 组上的 Deployment 对象。 That is no longer the case.

对于 1.9.0 之前的 Kubernetes 版本,您应该使用 API 组 apps/v1beta2

In Kubernetes 1.9及以上你应该使用API​​组apps/v1

【讨论】:

  • 但是为什么kubectl create 有效而kubectl apply 无效?我希望当使用错误的 API 版本时两者都会失败。
  • 我只是在这里假设,但由于 kubectl apply 是创建对象的声明方式的一部分,它执行的操作最终确保不弃用正在创建的对象的 api 组。另一方面,kubectl create 是创建对象的强制方式的一部分,因此,在这种管理对象的方式中,如果 api 组存在,即使已弃用,对象也会被创建。我敢打赌,如果您将 apps/v1beta1 替换为“bananas”,kubectl create 将会失败。
  • 客户端版本还是服务器版本?
猜你喜欢
  • 1970-01-01
  • 2020-09-15
  • 2020-02-07
  • 1970-01-01
  • 1970-01-01
  • 2018-12-14
  • 2023-03-03
  • 1970-01-01
  • 2020-08-05
相关资源
最近更新 更多