美文网首页
shell命令实现K8s Deployment资源有则更新,无则

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

作者: sexy_cyber | 来源:发表于2023-11-29 09:30 被阅读0次
    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
    

    • 命令中需要注意: 如果用-X PUT方法,那么URL需要携带部署的资源名称:xx
    https://www.xx.top/k8sapi/apis/apps/v1/namespaces/default/deployments/xx
    
    • 如果用 -X POST 方法,URL不能携带资源名称
    https://www.xx.top/k8sapi/apis/apps/v1/namespaces/default/deployments
    

    相关文章

      网友评论

          本文标题:shell命令实现K8s Deployment资源有则更新,无则

          本文链接:https://www.haomeiwen.com/subject/ynhxgdtx.html