由於專案關係,建了不少服務到OpenShift上面。
來開始記錄服務帶起來的基本流程。
建立流程
- 先建立一個Project
- 這個名稱會影響內部的各專案的網路連結。例如名稱dev-test, 專案內部連結連上這個服務url為xxx.dev-test。(xxx 為專案內的服務名)
ConfigMaps
服務容器的環境變數
Services
設置服務名稱、port
Routes
對外URL、對該Route timeout設定
NetworkPolicies
防火牆、權限設置,這個可影響各專案是否可以內部互通。 若專案間沒設置就只能用外部Routes互通
DeploymentConfigs (這個會把Pod帶起來所以最後弄)
- 設置CPU使用、記憶體使用、 提供的port、服務檢測、服務備援、設定image來源、mount、triggers、termination-log 等設定
Extra:
- CronJobs (做法類似linux指令)
- ImageStreams (image 放置的地方)
Deploy Script (視情況調整)
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
| #!/bin/bash IsSuccess(){ if [$? != 0] then echo "${tput setaf 1} ~~Caution:" $1" fail ! ${tput sgr 0}" exit 1 else echo "${tput setaf 2} ~~Execution:" $1" OK ! ${tput sgr 0}" fi }
read -p "Please input [DeploymentConfig Name] : " dcName read -p "Please input [Version] : " version read -p "Please input [tar location path] : " tar_location read -p "Please input [OpenShift project] : " openshift_project read -p "Please input [OpenShift url] : " openshift_url read -p "Please input [OpenShift account] : " account read -p "Please input [OpenShift password] : " password
test -z ${dcName} && echo "You Must input a DeploymentConfig Name." && exit 0 test -z ${version} && echo "You Must input a version." && exit 0
image_name=$dcName image_tag=$version tar_location="${tar_location}/${image_name}-${image_tag}.tar"
echo "==================start==================" oc login -u $account -p $password IsSuccess "oc login" oc project $openshift_project IsSuccess "switch project" podman login $openshift_url -p ${oc whoami -t} -u ${oc whoami -t} IsSuccess "podman login" podman load -i "${tar_location}" IsSuccess "podman load [${tar_location}]" podman push "${openshift_url}/${openshift_project}/${image_name}:${image_tag}" IsSuccess "podman push" oc tag $image_name:$image_tag $image_name:stable IsSuccess "oc tag [${image_name}:${image_tag}] to stable" oc rollout status dc/$dcName echo "==================End=================="
|
more info:
Shell教程
Open shift CLI
Deployment vs DeploymentConfig
OpenShift中的Deployment和DeploymentConfig