跳到主內容

yaml 說明

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.15
        ports:
        - containerPort: 80

image-1736738210438.png

欄位名稱 說明
apiVersion API 版本
kind 資源類型
metadata 資源元數據
spec 資源規格
replicas 副本數量
selector 標籤選擇器
template Pod 模板
metadata Pod 元數據
spec Pod 規格
containers 容器配置

使用kubectl create 生成 yaml 文件

kubectl create deployment web --image=nginx -o yaml --dry-run > my1.yaml

使用kubectl get 導出 yaml 文件

kubectl get deploy niginx -o=yaml --export > my2.yaml