Last active
June 28, 2022 08:25
-
-
Save zhangguanzhang/5146a962bbe0f245e7655a87c79db2da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# dnsConfig | |
kubectl -n kafka patch deployments kafka-0 -p '{"spec":{"template":{"spec":{"dnsConfig":{"options":[{"name":"single-request-reopen"}]}}}}}' | |
# dnsOptions | |
kubectl patch deploy $name \ | |
-p '{"spec":{"template":{"spec":{"dnsConfig":{"options":[{"name":"single-request-reopen"}]}}}}}' | |
function t(){ | |
local ns deploy | |
for ns in $@;do | |
for deploy in $(kubectl -n $ns get deploy --no-headers | awk '{print $1}');do | |
kubectl -n $ns patch deploy $deploy \ | |
-p '{"spec":{"template":{"spec":{"dnsConfig":{"options":[{"name":"single-request-reopen"}]}}}}}' | |
done | |
done | |
} | |
# hostNetwork | |
kubectl -n ingress-nginx \ | |
patch deploy nginx-ingress-controller \ | |
-p '{"spec":{"template":{"spec":{"dnsPolicy":"ClusterFirstWithHostNet","hostNetwork":true}}}}' | |
# patch deploy imagePullPolicy | |
kubectl patch deploy $name \ | |
-p '{"spec":{"template":{"spec":{"containers": ['$( | |
kubectl get deploy $name -o jsonpath='{range .spec.template.spec.containers[*]}{"{\"name\":\""}{.name}{"\",\"imagePullPolicy\":\"IfNotPresent\"}\n"}{end}' | paste -s - -d , | |
)'] }}}}' | |
# patch all deploy imagePullPolicy | |
while read name;do | |
kubectl patch deploy $name \ | |
-p '{"spec":{"template":{"spec":{"containers": ['$( | |
kubectl get deploy $name -o jsonpath='{range .spec.template.spec.containers[*]}{"{\"name\":\""}{.name}{"\",\"imagePullPolicy\":\"IfNotPresent\"}\n"}{end}' | paste -s - -d , | |
)'] }}}}' | |
done< <(kubectl get deployments --no-headers | awk '{print $1}') | |
while read ns name;do | |
kubectl -n $ns patch deployments $name \ | |
-p '{"spec":{"template":{"spec":{"imagePullSecrets":[{"name":"regcred"}]}}}}' | |
done< <(kubectl get deployments --no-headers --all-namespaces | awk '{print $1,$2}') | |
kubectl patch deployments ng-test --type=json -p='[{"op":"replace","path":"/spec/template/spec/affinity/podAntiAffinity","value": { | |
"preferredDuringSchedulingIgnoredDuringExecution": [{ | |
"weight": 100, | |
"podAffinityTerm":{ | |
"labelSelector": { | |
"matchExpressions": [ | |
{ | |
"key": "app", | |
"operator": "In", | |
"values": [ | |
"ng-test" | |
] | |
} | |
] | |
}, | |
"topologyKey": "kubernetes.io/hostname" | |
} | |
}] | |
}}]' | |
kubectl patch deployments test --type=json -p='[{"op":"replace","path":"/spec/template/spec/affinity","value": { | |
"podAntiAffinity": { | |
"preferredDuringSchedulingIgnoredDuringExecution": [{ | |
"weight": 100, | |
"podAffinityTerm":{ | |
"labelSelector": { | |
"matchExpressions": [ | |
{ | |
"key": "app", | |
"operator": "In", | |
"values": [ | |
"test" | |
] | |
} | |
] | |
}, | |
"topologyKey": "kubernetes.io/hostname" | |
} | |
}] | |
} | |
} | |
}]' |
Author
zhangguanzhang
commented
Jun 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment