批量创建deployment资源脚本(Batch create deployment resource script)

  • 资源文件内容
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-
  labels:
    test_rollingupgrade: "123456"
spec:
  selector:
    matchLabels:
     app : "1234"
  replicas: 1
  template:
    metadata:
      labels:
        app: "123"
    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即可

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

————————
  • Resource file content
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-
  labels:
    test_rollingupgrade: "123456"
spec:
  selector:
    matchLabels:
     app : "1234"
  replicas: 1
  template:
    metadata:
      labels:
        app: "123"
    spec:
      containers:
      - name: test-pod
        image: nginx:1.12.2
  • Script content
#!/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-*

For batch deletion, just change kubectl apply to kubectl delete

For batch deletion, just change kubectl apply to kubectl delete