bash - 如何仅使用 bash(无编辑器)创建 Kubernetes YAML 部署对象?

标签 bash kubernetes yaml

练习 Kubernetes。

是否可以仅通过 Bash 创建 YAML 部署对象及其配置?

我试过这个:

kubectl create -f deployment.yaml

创建一个 yaml,以便我稍后可以编辑。然而它只是显示

error: the path "deployment.yaml" does not exist

最佳答案

到目前为止,所有答案都提倡实际部署到集群,然后检索正在运行的部署。

使用--dry-run,您可以在不实际部署任何东西的情况下获取对象的 YAML 格式。例如:

kubectl create deployment nginx --image=nginx --dry-run -o yaml

将部署 YAML 输出到标准输出:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

关于bash - 如何仅使用 bash(无编辑器)创建 Kubernetes YAML 部署对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55691110/

相关文章:

java - 在 Ubuntu 中编译 Servlet 返回错误

bash - xclip 和尾随空格

python - Kubernetes Python API 客户端 : execute full yaml file

yaml - YAML 语法 ansible playbook 中列表或键的混淆

go - 无法解码Golang中的数组字段

linux - 使用 env 变量指定 makefile

bash - 如何使用 bash 测试 Internet 连接?

postgresql - 具有单独主机名/ip 的 Kubernetes Citus 设置

google-cloud-platform - 无法在 Google 容器引擎上的 Stackdriver 中访问 Kubernetes 指标

gitlab - 将 Yaml 从 GitLab 转换为 azure devops