【问题标题】:How do I edit a resource configuration with kubectl?如何使用 kubectl 编辑资源配置?
【发布时间】:2017-08-04 09:10:17
【问题描述】:

我创建了一个资源: kubectl create -f example.yaml

如何使用 kubectl 编辑此资源?据说是kubectl edit,但是我不确定资源名,kubectl edit example返回错误:

the server doesn't have a resource type "example"

【问题讨论】:

    标签: kubernetes kubectl


    【解决方案1】:

    您可以通过kubectl edit -f example.yaml 直接对其进行编辑。尽管如此,我还是建议在本地编辑文件并执行kubectl apply -f example.yaml,以便在 Kubernetes 上更新。

    另外:您的命令失败,因为您必须指定资源类型。示例类型为podservicedeployment 等。您可以使用普通的kubectl get 查看所有可能的类型。类型应与 YAML 文件中的 kind 值匹配,名称应与 metadata.name 匹配。

    例如下面的文件可以用kubectl edit deployment nginx-deployment编辑

    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      replicas: 2 # tells deployment to run 2 pods matching the template
      template: # create pods using pod definition in this template
        metadata:
          # unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
          # generated from the deployment name
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
    

    【讨论】:

    • 在这种情况下会是什么资源类型?还是取决于我的example.yaml 的内容?
    • 视内容而定。
    • 我在答案中添加了解释。
    • 只是一个注释。使用apply 会给我一个警告:Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl applykubectl replace -f example.yaml 似乎在没有警告的情况下实现了上述目标。
    • @ChrisStryczynski 来自 kubernete.io 的引述:“警告:不支持将 kubectl apply 与命令式对象配置命令 create 和 replace 混合。这是因为 create 和 replace 不保留 kubectl.kubernetes.io kubectl apply 用于计算更新的 /last-applied-configuration。” kubernetes.io/docs/concepts/overview/object-management-kubectl/…
    猜你喜欢
    • 2021-07-25
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 2022-12-03
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多