批量创建deployment资源脚本

  • 资源文件内容
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-
  labels:
    app: "1234"
spec:
  selector:
    matchLabels:
     app: "1234"
  replicas: 1
  template:
    metadata:
      labels:
        app: "1234"
    spec:
      containers:
      - name: test-pod
        image: nginx:1.12.2
  • 脚本内容
#!/bin/bash

for i  in {1..100}
do
    deploymentName=deployment-$i
    newYaml=tmp-$i.yaml
    cp test.yaml $newYaml
    sed -ie 's/deployment-/'"$deploymentName"'/g' $newYaml
    echo $newYaml
    kubectl apply -f $newYaml
    rm $newYaml
done

rm tmp-*

批量删除直接把kubectl apply 改为kubectl delete即可

原文地址:https://www.cnblogs.com/Kingram/p/15596364.html