1 [student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com 2 [student@workstation ~]$ oc new-project scaling 3 [student@workstation ~]$ oc new-app -o yaml -i php:7.0 4 http://registry.lab.example.com/scaling > ~/scaling.yml #将部署的yaml导出至本地 5 [student@workstation ~]$ vi ~/scaling.yml 6 …… 7 spec: 8 replicas: 3 9 selector: 10 app: scaling 11 deploymentconfig: scaling #修改副本数 12 …… 13 [student@workstation ~]$ oc create -f ~/scaling.yml #以修改副本数后的yaml部署应用
1 [student@workstation ~]$ watch -n 3 oc get builds 2 Every 3.0s: oc get builds Mon Jul 22 11:12:02 2019 3 4 NAME TYPE FROM STATUS STARTED DURATION 5 scaling-1 Source Git@0bdae71 Complete About a minute ago 1m0s 6 [student@workstation ~]$ oc get pods 7 NAME READY STATUS RESTARTS AGE 8 scaling-1-build 0/1 Completed 0 2m 9 scaling-1-ft249 1/1 Running 0 1m 10 scaling-1-gjvkp 1/1 Running 0 1m 11 scaling-1-mtrxr 1/1 Running 0 1m
1 [student@workstation ~]$ oc expose service scaling 2 --hostname=scaling.apps.lab.example.com
1 [student@workstation ~]$ for i in {1..5};do curl -s \http://scaling.apps.lab.example.com | grep IP;done #多次请求 2 <br/> Server IP: 10.128.0.17 3 <br/> Server IP: 10.129.0.35 4 <br/> Server IP: 10.129.0.36 5 <br/> Server IP: 10.128.0.17 6 <br/> Server IP: 10.129.0.35
1 [student@workstation ~]$ oc describe dc scaling | grep Replicas 2 Replicas: 3 3 Replicas: 3 current / 3 desired 4 [student@workstation ~]$ oc scale --replicas=5 dc scaling
1 [student@workstation ~]$ oc get pods -o wide
1 [student@workstation ~]$ for i in {1..5};do curl -s \http://scaling.apps.lab.example.com | grep IP;done #多次请求 2 <br/> Server IP: 10.128.0.17 3 <br/> Server IP: 10.128.0.18 4 <br/> Server IP: 10.129.0.35 5 <br/> Server IP: 10.129.0.36 6 <br/> Server IP: 10.129.0.37
1 $ oc label node1 region=ZheJiang zone=Cloud1A --overwrite 2 $ oc label node node2 region=ZheJiang zone=Cloud1A --overwrite 3 $ oc label node node3 region=ZheJiang zone=Cloud2A --overwrite 4 $ oc label node node4 region=ZheJiang zone=Cloud2A --overwrite 5 $ oc label node node5 region=HuNan zone=Cloud1B --overwrite 6 $ oc label node node6 region=HuNan zone=Cloud1B --overwrite 7 $ oc label node node7 region=HuNan zone=Cloud2B --overwrite 8 $ oc label node node8 region=HuNan zone=Cloud2B --overwrite
1 $ oc get node node1.lab.example.com -L region 2 $ oc get node node1.lab.example.com -L region -L zone #支持oc get跟多个-L选项
1 $ oc adm manage-node --schedulable=false node2.lab.example.com
1 $ oc adm drain node2.lab.example.com
1 $ oc adm manage-node --schedulable=true node2.lab.example.com
1 $ oc patch dc myapp --patch ‘{"spec":{"template":{"nodeSelector":{"env":"qa"}}}}‘
1 $ oc annotate --overwrite namespace default 2 openshift.io/node-selector=‘region=infra‘
1 [student@workstation ~]$ lab schedule-control setup 2 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com
1 [student@workstation ~]$ oc get nodes -L region 2 NAME STATUS ROLES AGE VERSION REGION 3 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 4 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra 5 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra
1 [student@workstation ~]$ oc new-project schedule-control
1 [student@workstation ~]$ oc new-app --name=hello 2 --docker-image=registry.lab.example.com/openshift/hello-openshift
1 [student@workstation ~]$ oc scale dc hello --replicas=5 2 deploymentconfig "hello" scaled 3 [student@workstation ~]$ oc get pod -o wide 4 NAME READY STATUS RESTARTS AGE IP NODE 5 hello-1-c5z2n 1/1 Running 0 7s 10.128.0.21 node1.lab.example.com 6 hello-1-hhvp7 1/1 Running 0 34s 10.129.0.38 node2.lab.example.com 7 hello-1-jqrkb 1/1 Running 0 7s 10.128.0.20 node1.lab.example.com 8 hello-1-tgmbr 1/1 Running 0 7s 10.129.0.39 node2.lab.example.com 9 hello-1-z2bn7 1/1 Running 0 7s 10.128.0.22 node1.lab.example.com
1 [student@workstation ~]$ oc label node node2.lab.example.com region=apps --overwrite=true 2 [student@workstation ~]$ oc get nodes -L region #确认修改 3 NAME STATUS ROLES AGE VERSION REGION 4 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 5 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra 6 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 apps
1 [student@workstation ~]$ oc get dc hello -o yaml > dc.yaml
1 [student@workstation ~]$ vi dc.yaml 2 …… 3 template: 4 …… 5 spec: 6 nodeSelector: #添加节点选择器 7 region: apps 8 ……
1 [student@workstation ~]$ oc apply -f dc.yaml
1 [student@workstation ~]$ oc get pod -o wide 2 NAME READY STATUS RESTARTS AGE IP NODE 3 hello-2-4c2gv 1/1 Running 0 40s 10.129.0.42 node2.lab.example.com 4 hello-2-6966b 1/1 Running 0 38s 10.129.0.43 node2.lab.example.com 5 hello-2-dcqbr 1/1 Running 0 36s 10.129.0.44 node2.lab.example.com 6 hello-2-dlf8k 1/1 Running 0 36s 10.129.0.45 node2.lab.example.com 7 hello-2-rnk4w 1/1 Running 0 40s 10.129.0.41 node2.lab.example.com
1 [student@workstation ~]$ oc label node node1.lab.example.com region=apps --overwrite=true 2 [student@workstation ~]$ oc get node -L region 3 NAME STATUS ROLES AGE VERSION REGION 4 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 5 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 apps 6 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 apps
1 [student@workstation ~]$ oc adm manage-node --schedulable=false node2.lab.example.com 2 NAME STATUS ROLES AGE VERSION 3 node2.lab.example.com Ready,SchedulingDisabled compute 2d v1.9.1+a0ce1bc657
1 [student@workstation ~]$ oc adm drain node2.lab.example.com --delete-local-data
1 [student@workstation ~]$ oc get pods -o wide 2 NAME READY STATUS RESTARTS AGE IP NODE 3 hello-2-bjsj4 1/1 Running 0 51s 10.128.0.25 node1.lab.example.com 4 hello-2-kmmmn 1/1 Running 0 50s 10.128.0.23 node1.lab.example.com 5 hello-2-n6wvj 1/1 Running 0 51s 10.128.0.24 node1.lab.example.com 6 hello-2-plr65 1/1 Running 0 50s 10.128.0.26 node1.lab.example.com 7 hello-2-xsz68 1/1 Running 0 51s 10.128.0.27 node1.lab.example.com
1 [student@workstation ~]$ lab schedule-is setup
1 [student@workstation ~]$ oc login -u developer -p redhat 2 https://master.lab.example.com 3 [student@workstation ~]$ oc new-project schedule-is
1 [student@workstation ~]$ oc new-app --name=phpmyadmin 2 --docker-image=registry.lab.example.com/phpmyadmin/phpmyadmin:4.7
1 [student@workstation ~]$ oc login -u admin -p redhat 2 [student@workstation ~]$ oc project schedule-is 3 [student@workstation ~]$ oc create serviceaccount phpmyadmin-account
1 [student@workstation ~]$ oc adm policy add-scc-to-user anyuid 2 -z phpmyadmin-account
1 [student@workstation ~]$ oc login -u developer 2 [student@workstation ~]$ oc patch dc/phpmyadmin --patch 3 ‘{"spec":{"template":{"spec":{"serviceAccountName": "phpmyadmin-account"}}}}‘
1 [student@workstation ~]$ oc get pods #确认验证 2 NAME READY STATUS RESTARTS AGE 3 phpmyadmin-2-vh29z 1/1 Running 0 3m
1 [student@workstation ~]$ cd /home/student/DO280/labs/schedule-is/ 2 [student@workstation schedule-is]$ ls 3 phpmyadmin-latest.tar trust_internal_registry.sh 4 [student@workstation schedule-is]$ docker load -i phpmyadmin-latest.tar 5 #使用docker load命令加载新的image。 6 [student@workstation schedule-is]$ docker images 7 REPOSITORY TAG IMAGE ID CREATED SIZE 8 <none> <none> 93d0d7db5ce2 13 months ago 166 MB
1 [student@workstation schedule-is]$ docker tag 93d0d7db5ce2 2 docker-registry-default.apps.lab.example.com/schedule-is/phpmyadmin:4.7 3 #打完标记进行推送。
1 [student@workstation schedule-is]$ ./trust_internal_registry.sh
1 [student@workstation schedule-is]$ docker push 2 docker-registry-default.apps.lab.example.com/schedule-is/phpmyadmin:4.7
1 [student@workstation schedule-is]$ oc get pods 2 NAME READY STATUS RESTARTS AGE 3 phpmyadmin-3-hnfjk 1/1 Running 0 23s
1 [student@workstation ~]$ lab manage-review setup
1 [student@workstation ~]$ oc login -uadmin -predhat https://master.lab.example.com 2 [student@workstation ~]$ oc get nodes -L region 3 NAME STATUS ROLES AGE VERSION REGION 4 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 5 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra 6 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra
1 [student@workstation ~]$ oc label node node1.lab.example.com region=services --overwrite=true 2 [student@workstation ~]$ oc label node node2.lab.example.com region=applications --overwrite=true 3 [student@workstation ~]$ oc get nodes -L region 4 NAME STATUS ROLES AGE VERSION REGION 5 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 6 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 services 7 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 applications
1 [student@workstation ~]$ oc new-project manage-review
1 [student@workstation ~]$ oc new-app -i php:7.0 2 http://registry.lab.example.com/version
1 [student@workstation ~]$ oc scale dc version --replicas=3 2 [student@workstation ~]$ oc get pods -o wide #确认验证 3 NAME READY STATUS RESTARTS AGE IP NODE 4 version-1-9626w 1/1 Running 0 40s 10.129.0.55 node2.lab.example.com 5 version-1-build 0/1 Completed 0 1m 10.129.0.52 node2.lab.example.com 6 version-1-f6vj2 1/1 Running 0 40s 10.129.0.56 node2.lab.example.com 7 version-1-mrhk4 1/1 Running 0 45s 10.129.0.54 node2.lab.example.com
1 [student@workstation ~]$ oc export dc version -o yaml > version-dc.yml #导出yaml 2 spac 3 …… 4 template: 5 metadata: 6 …… 7 spec: 8 nodeSelector: #添加节点选择器 9 region: applications 10 ……
1 [student@workstation ~]$ oc replace -f version-dc.yml #迭代
1 [student@workstation ~]$ oc get pod -o wide 2 NAME READY STATUS RESTARTS AGE IP NODE 3 version-1-build 0/1 Completed 0 15m 10.129.0.52 node2.lab.example.com 4 version-2-2bmqq 1/1 Running 0 58s 10.129.0.60 node2.lab.example.com 5 version-2-nz58r 1/1 Running 0 1m 10.129.0.59 node2.lab.example.com 6 version-2-rlj2h 1/1 Running 0 1m 10.129.0.58 node2.lab.example.com
1 [student@workstation ~]$ oc label node node1.lab.example.com region=applications --overwrite=true 2 [student@workstation ~]$ oc get nodes -L region #确认验证 3 NAME STATUS ROLES AGE VERSION REGION 4 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 5 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 applications 6 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 applications
1 [student@workstation ~]$ oc adm manage-node --schedulable=false node2.lab.example.com 2 NAME STATUS ROLES AGE VERSION 3 node2.lab.example.com Ready,SchedulingDisabled compute 2d v1.9.1+a0ce1bc657
1 [student@workstation ~]$ oc adm drain node2.lab.example.com --delete-local-data
1 [student@workstation ~]$ oc get pods -o wide 2 NAME READY STATUS RESTARTS AGE IP NODE 3 version-2-d9fhp 1/1 Running 0 3m 10.128.0.34 node1.lab.example.com 4 version-2-jp5gr 1/1 Running 0 3m 10.128.0.35 node1.lab.example.com 5 version-2-z5lv5 1/1 Running 0 3m 10.128.0.33 node1.lab.example.com
1 [student@workstation ~]$ oc expose service version --hostname=version.apps.lab.example.com 2 [student@workstation ~]$ curl http://version.apps.lab.example.com #确认测试 3 <html> 4 <head> 5 <title>PHP Test</title> 6 </head> 7 <body> 8 <p>Version v1</p> 9 </body> 10 </html>
1 [student@workstation ~]$ lab manage-review grade #环境脚本判断
1 [student@workstation ~]$ oc adm manage-node --schedulable=true node2.lab.example.com 2 [student@workstation ~]$ oc label node node1.lab.example.com region=infra --overwrite=true 3 [student@workstation ~]$ oc label node node2.lab.example.com region=infra --overwrite=true 4 [student@workstation ~]$ oc get node -L region 5 NAME STATUS ROLES AGE VERSION REGION 6 master.lab.example.com Ready master 2d v1.9.1+a0ce1bc657 7 node1.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra 8 node2.lab.example.com Ready compute 2d v1.9.1+a0ce1bc657 infra 9 [student@workstation ~]$ oc delete project manage-review
原文:https://www.cnblogs.com/itzgr/p/13173679.html