How to quickly check whether sts contains a certain environment variable

env_name is replaced with your environment variable,

Execute the following script:

#!/bin/bash

# 获取所有的Namespace
namespaces=$(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}')
env_name="xxxxxx"
# 遍历所有的Namespace
for ns in $namespaces
  do
    echo "Namespace: $ns"
    # 获取Namespace中所有的StatefulSet
    sts=$(kubectl get statefulsets -n $ns -o jsonpath='{.items[*].metadata.name}')
    # 遍历所有的StatefulSet
    for st in $sts
      do
        # 获取StatefulSet的Topology Spread Constraints
        envs=$(kubectl get statefulsets $st -n $ns -o jsonpath='{.spec.template.spec.containers[*].env[*].name}')
        if echo "$envs" | grep -q "$env_name"; then
            echo "StatefulSet $st in $ns contains environment variable $env_name"
        fi
    done
done

Guess you like

Origin blog.csdn.net/zfw_666666/article/details/131941575