qcloud.sh
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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