kubernetes - 如何使用 kubectl 编辑资源配置?

标签 kubernetes kubectl

我创建了一个资源:kubectl create -f example.yaml
如何使用 kubectl 编辑此资源?据说 kubectl edit ,但我不确定资源名称,以及 kubectl edit example返回错误:

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

最佳答案

你可以做一个 kubectl edit -f example.yaml直接编辑它。尽管如此,我还是建议在本地编辑文件并执行 kubectl apply -f example.yaml ,所以它会在 Kubernetes 上更新。

另外:您的命令失败,因为您必须指定资源类型。示例类型为 pod , service , deployment等等。您可以使用普通 kubectl get 查看所有可能的类型.类型应该匹配 kind YAML 文件中的值和名称应匹配 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

关于kubernetes - 如何使用 kubectl 编辑资源配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45502729/

相关文章:

kubernetes - 如何在 Kubernetes 上设置安全的 cockroachdb 以便从 NodeJs 访问

bash - 使用 kubectl 在 pod 中执行 bash 命令?

kubernetes - 如何获取kubernetes服务的集群IP

kubernetes - 将GitLab连接到新的GKE群集时如何解决计费警告

nginx - 如何在Kubernetes上访问简单的Nginx部署?

azure - 如何在不运行 Invoke Command 的情况下访问 azure k8s 集群?

kubernetes - 如何创建 gcePD 并将其作为持久卷链接到本地​​ k8s 集群?

kubernetes - kubectl 安装错误 - 连接到服务器 localhost :8080 was refused - did you specify the right host or port

jenkins - 使用 GitHub/Jenkins/Kubernetes 实现 CI/CD 管道时的最佳实践

kubernetes - 无法使用服务名访问kubernetes服务