qcloud.sh 1.63 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
## 确定切换成功
currentcontext=$(/usr/local/bin/kubectl config current-context)
if [ "$currentcontext" != "$clusterInfo" ];then
    echo "change kubectl ca failure,please check result"
    exit 1
fi
/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 10 min the service is not down please check the service ,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" |grep -v 2/2|grep -v 1/1 |wc -l)
    echo "newrunning is $newrunning ,newredy is $newredy"
    if [ "$newrunning" -eq 0  -a "$newredy" -eq 0 ];then
        echo "end with the cluster check the publish is ok"
        break;
    fi
    sleep 10
done