脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
source /etc/rc.d/init.d/functions
set -euo pipefail
export PATH=/opt/kube/bin:$PATH

secret_name=test-com
cert_name=test.com.crt
key_name=test.com.key

if [ "$#" == 0 ];then
for ns in `kubectl get ns|grep -v "NAME\|kube-*"|awk '{print $1}'`;do
kubectl create secret tls $secret_name --cert=$cert_name --key=$key_name -n $ns --dry-run=client -o yaml |kubectl apply -f -
action $ns true
done
else
for ns in $@;do
kubectl create secret tls $secret_name --cert=$cert_name --key=$key_name -n $ns --dry-run=client -o yaml |kubectl apply -f -
action $ns true
done
fi