shell命令实现K8s Deployment资源有则更新,无则

2023-11-29  本文已影响0人  sexy_cyber
sed -i "s/spider:[^[:space:]]*/spider:$GIT_COMMIT/" xx.yml

token="2xkkdklag"

response=$(curl -H "Authorization: Bearer $token" \
     -H "Content-Type: application/yaml" \
     -X PUT \
     --data-binary "@xx.yml" \
     https://www.xx.top/k8sapi/apis/apps/v1/namespaces/default/deployments/xx)

if echo "$response" | grep -q "NotFound"; then
    response=$(curl -H "Authorization: Bearer $token" \
     -H "Content-Type: application/yaml" \
     -X POST \
     --data-binary "@xx.yml" \
     https://www.xx.top/k8sapi/apis/apps/v1/namespaces/default/deployments)
fi

https://www.xx.top/k8sapi/apis/apps/v1/namespaces/default/deployments/xx
https://www.xx.top/k8sapi/apis/apps/v1/namespaces/default/deployments
上一篇下一篇

猜你喜欢

热点阅读