批量替换掉k8s集群上面的所有证书

35 阅读1分钟

k8s上面ingress应用的证书过期,需要批量替换,因为没有使用证书管理工具,所以手动执行该过程。

步骤一:

把所有的证书的yaml编排文件放到本地目录:

kubectl get secret -A|awk '{if($3=="kubernetes.io/tls"){print "kubectl -n "$1" get secret "$2" -oyaml > "$1"-"$2".yaml"}}' **

步骤二:

使用yq脚本完成字段的替换

#!/bin/bash
for file in `find ./files -type f -name "*.yaml"`
  do
    echo $file
    key="..." crt="..." yq '.data."tls.key"=strenv(key)|.data."tls.crt"=strenv(crt) |.metadata.resourceVersion=""' -i $file
  done