저는 Google Cloud/Google Container Engine을 사용하고 있으며 클러스터와 노드 풀을 만든 다음 설정이 완료되면 노드 풀에서 작업을 수행하는 인프라 스크립트가 있습니다.
내 스크립트에서는 계속 진행하기 전에 노드 풀이 설정되어 있고 클러스터가 준비 상태인지 확인해야 합니다.
매우 gcloud container node-pools create
유사한 --wait
.--no-async
gcloud container node-pools delete
에 그런 옵션이 있나요 create
? 그렇지 않으면 노드 풀이 준비될 때까지 "대기"하는 권장 방법이 있나요?
gcloud container clusters describe myclustername --zone myzone | tail -n 2 | grep "status" | awk '{print $2}'
나는 내 bash 스크립트를 믿습니다. 노드 풀을 만든 후 while 루프를 수행하여 " "를 다시 얻을 때까지 주기적으로 값을 확인할 수 있지만 RUNNING
더 우아한 접근 방식이 있을까요?
(노드 풀 생성 및 삭제 옵션에 패리티가 있으면 좋을 것 같습니다!)
답변1
이 글을 쓰는 시점에서gcloud container node-pools create
--async
명령은 기본적으로 동기화되지만 또는 옵션이 없습니다 --no-wait
. 이는 명령을 배경으로 설정하는 것이 쉽고 특정 문제를 해결할 수 있으므로 쉘 스크립팅 관점에서 그리 나쁘지 않습니다.
원래 동작을 처리하는 대안은 --log-http
작업 ID를 가져와서 제공하는 것이었습니다 gcloud container operations wait
(이 방법은 약간 지저분하고 출력을 스크랩해야 함). 이는 비동기 명령이 작업 ID를 에코하는 또 다른 유용한 기능을 제안합니다.
답변2
아직 완료되지 않은 컨테이너 작업을 기다리는 이 스크립트를 만들었습니다.
wait_container_Operations.sh
#!/bin/bash
# This scripts runs gcloud container `operations describe` and `wait` for all found operations with `list --filter=STATUS!=DONE`
# API outlined here https://cloud.google.com/sdk/gcloud/reference/compute/operations/
set -euo pipefail
IFS=$'\n\t'
source_dir="$(dirname "$0")";
current_dir="$(pwd)";
echo "Listing, describing and awaiting NOT-DONE container-operations";
function sourceClusterZone(){
cd $source_dir;
source ./cluster_zone.sh;
cd $current_dir;
}
queryNotDone(){ gcloud container operations list --filter=STATUS!=DONE --sort-by='~START_TIME'; }
listNotDone(){ queryNotDone | awk '{if (NR!=1) {print $1;}}'; }
sleep 2;
LISTNOTDONE=(`listNotDone`);
echo "\""${LISTNOTDONE[@]}"\"";
if (( ${#LISTNOTDONE[@]} )); then
sourceClusterZone;
for notDone in ${LISTNOTDONE[@]}
do
echo "Waiting for $notDone";
gcloud container operations describe $notDone --zone="${ZONE}";
gcloud container operations wait $notDone --zone="${ZONE}";
echo "Done with $notDone";
done
else
echo 'Not Waiting';
fi
Cluster_zone.sh (동일한 디렉토리에 있음)
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
kubeClusterOptions(){ kubectl config current-context | awk -F '_' 'BEGIN { ORS=" " }; {print $4} {print $3}'; }
declare -a OPTIONS;
IFS=' ' read -a OPTIONS <<< `kubeClusterOptions`; IFS=$'\n\t';
while getopts c:z: option
do
case "${option}"
in
c) CLUSTER=${OPTARG:-${OPTIONS[0]}};;
z) ZONE=${OPTARG:-${OPTIONS[1]}};;
esac
done
export CLUSTER=${CLUSTER:-${OPTIONS[0]}};
export ZONE=${ZONE:-${OPTIONS[1]}};
-c YOUR_CLUSTER
및 를 사용하여 사용자 정의 클러스터 및 영역으로 스크립트를 구성할 수 있습니다 -z YOUR_ZONE
. kubectl config current-context
아무것도 지정하지 않으면 구성이 적용됩니다 .