如何使用kubectl编辑资源配置

如何使用kubectl编辑资源配置

本文介绍了如何使用kubectl编辑资源配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下资源:kubectl create -f example.yaml

I've created a resource with:kubectl create -f example.yaml

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

How do I edit this resource with kubectl? Supposedly kubectl edit, but I'm not sure of the resource name, and kubectl edit example returns an error of:

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

推荐答案

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

You can do a kubectl edit -f example.yaml to edit it directly. Nevertheless I would recommend to edit the file locally and do a kubectl apply -f example.yaml, so it gets updated on Kubernetes.

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

Also: Your command fails, because you have to specify a resource type. Example types are pod, service, deployment and so on. You can see all possible types with a plain kubectl get. The type should match the kind value in the YAML file and the name should match 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

这篇关于如何使用kubectl编辑资源配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:43