在生產環境上需要轉換爲docker方式執行,先建立deploy目錄並將deployment執行的yaml檔案導出到該目錄,同樣建立svc目錄併到導出svc執行的yaml檔案。然後執行指令碼./k8s-TR-docker.sh deploy/gd-gateway.yaml
#!/bin/bash
#filename k8s-TR-docker.sh
curdir=$(cd $(dirname $0);pwd)
pname=${1:-"deploy/gd-gateway.yaml"}
sname=${pname##*/}
dockerName=$(grep name: ${curdir}/deploy/${sname} | awk -F ':' 'NR==1{print $2}')
echo -e "#!/bin/bash"
echo -e "#${dockerName}"
printf " docker run --restart=always -p "
sed -n '/nodePort:/,/port:/ p' ${curdir}/svc/${sname} | tr -d "\n " | sed 's/nodePort://g;s/port//g'
printf " "
sed -n '/ env:/,/image:/ p' ${curdir}/deploy/${sname} | grep -v 'env\|image' | sed "s/- name:/-e/g;s/^ *//g" | tr "\n" " " | sed "s/ value: /=/g"
printf " --name${dockerName} -itd "
awk -F ': ' '/image:/{print $2}' ${curdir}/deploy/${sname}
以上對yaml檔案提取主要片段在第一個printf之後