qcloud.sh 1.33 KB
#!/bin/bash
echo "para clusterId is : $1"
echo "para serviceName is : $2"
echo "para containerName is : $3"
echo "para imageInfo is : $4"

clusterInfo="system-$1"
serviceName=$2
containerName=$3
imageInfo="ccr.ccs.tencentyun.com/$4"


## 切换当前的工作空间
/usr/local/bin/kubectl config use-context $clusterInfo
/usr/local/bin/kubectl get pods

## 更新镜像信息
/usr/local/bin/kubectl set image deployment/$serviceName $containerName=$imageInfo
## 等待30s后校验
waitnum=1
while [ $waitnum -le 4 ]
do
    let waitnum=waitnum+1
    echo "print the cluster info "
    /usr/local/bin/kubectl get pods |grep $serviceName
    sleep 5
done
## check service is done
num=1
while [ $num -le 60 ]
do
    echo "begin check the service is done ,the check number is :$num "
    if [ "$num" == 60 ];then
        echo "over the check number ,the check number is :$num "
        exit 1
    fi
    let num=num+1
    echo "print the cluster info "
    /usr/local/bin/kubectl get pods |grep $serviceName
    newrunning=$(/usr/local/bin/kubectl get pods |grep "$serviceName" |awk '$3!="Running"' |wc -l)
    newredy=$(/usr/local/bin/kubectl get pods |grep "$serviceName" |awk '$2!="1/1" || $2!="2/2"' |wc -l)
    if [ "$newrunning" == 0 && "$newredy" == 0 ];then
        echo "end with the cluster check the publish is ok"
        break;
    fi
    sleep 10
done