Skip to content

Instantly share code, notes, and snippets.

@zhangguanzhang
Last active June 28, 2022 08:25
Show Gist options
  • Save zhangguanzhang/5146a962bbe0f245e7655a87c79db2da to your computer and use it in GitHub Desktop.
Save zhangguanzhang/5146a962bbe0f245e7655a87c79db2da to your computer and use it in GitHub Desktop.
#!/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"
}
}]
}
}
}]'
@zhangguanzhang
Copy link
Author

kubectl patch deployment x -p '{"op": "add", "path": "/spec/template/spec/containers/0/ports/-", "value": {"containerPort": 80, "hostPort":81,"protocol": "TCP"}}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment