007.OpenShiefc管理应用部署
一 REPLICATION CONTROLLERS
1.1 RC概述
- 所需的副本数量
- 用于创建复制pod的pod定义
- 用于标识后续管理操作的selector
1.2 从DC创建RC
1.3 pod副本数控制
1.4 自动伸缩pod
二 扩展程序实验
2.1 前置准备
2.2 创建应用
1 [student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com2 [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部署应用
2.3 监视部署
1 [student@workstation ~]$ watch -n 3 oc get builds2 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
2.4 暴露服务
1 [student@workstation ~]$ oc expose service scaling \2 --hostname=scaling.apps.lab.example.com
2.5 web查看相关信息
2.6 测试负载均衡
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
2.7 扩容应用
1 [student@workstation ~]$ oc describe dc scaling | grep Replicas2 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
2.8 测试负载均衡
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
三 pod调度控制
3.1 pod调度算法
3.2 调度算法步骤
- 过滤节点
- 对过滤后的节点列表进行优先级排序
- 选择最合适的节点。
3.3 调度拓扑
- 从相同的RC创建的或从相同的DC创建的pod副本调度至具有相同region标签值的节点中运行。
- 副本Pod调位至具有不同zone标签的节点中运行。
1 $ oc label node1 region=ZheJiang zone=Cloud1A --overwrite2 $ 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 region2 $ oc get node node1.lab.example.com -L region -L zone #支持oc get跟多个-L选项
3.4 UNSCHEDULABLE节点
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
3.5 控制pod位置
1 $ oc patch dc myapp --patch '{"spec":{"template":{"nodeSelector":{"env":"qa"}}}}'
3.5 管理默认项目
- 使用region=infra标签标记专用节点;
- 为缺省名称空间配置缺省节点选择器。
1 $ oc annotate --overwrite namespace default \2 openshift.io/node-selector='region=infra'
四 控制Pod调度
4.1 前置准备
4.2 本练习准备
1 [student@workstation ~]$ lab schedule-control setup2 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com
4.3 查看region
1 [student@workstation ~]$ oc get nodes -L region2 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
4.4 创建project
1 [student@workstation ~]$ oc new-project schedule-control
4.5 创建应用
1 [student@workstation ~]$ oc new-app --name=hello \2 --docker-image=registry.lab.example.com/openshift/hello-openshift
4.6 扩展应用
1 [student@workstation ~]$ oc scale dc hello --replicas=52 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
4.7 修改节点label
1 [student@workstation ~]$ oc label node node2.lab.example.com region=apps --overwrite=true2 [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
4.8 导出dc
1 [student@workstation ~]$ oc get dc hello -o yaml > dc.yaml
4.9 修改node2调度策略
1 [student@workstation ~]$ vi dc.yaml2 ……
3 template:
4 ……
5 spec:
6 nodeSelector: #添加节点选择器
7 region: apps
8 ……
4.10 应用更新
1 [student@workstation ~]$ oc apply -f dc.yaml
4.11 确认验证
1 [student@workstation ~]$ oc get pod -o wide2 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
4.12 修改node1调度策略
1 [student@workstation ~]$ oc label node node1.lab.example.com region=apps --overwrite=true2 [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
4.13 终止node2
1 [student@workstation ~]$ oc adm manage-node --schedulable=false node2.lab.example.com2 NAME STATUS ROLES AGE VERSION
3 node2.lab.example.com Ready,SchedulingDisabled compute 2d v1.9.1+a0ce1bc657
4.14 删除pod
1 [student@workstation ~]$ oc adm drain node2.lab.example.com --delete-local-data
4.15 查看pod
1 [student@workstation ~]$ oc get pods -o wide2 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
五 管理IS、image、Templates
5.1 image介绍
5.2 IS
5.3 标记image
5.4 删除tag
5.5 建议的tag形式
描述 | 示例 |
Revision | myimage:v2.0.1 |
Architecture | myimage:v2.0-x86_64 |
Base Image | myimage:v1.2-rhel7 |
Latest Image | myimage:latest |
Latest Stable | Image myimage:stable |
5.6 Templates介绍
5.7 Templates管理
5.8 使用模板
六 管理IS
6.1 前置准备
6.2 本练习准备
1 [student@workstation ~]$ lab schedule-is setup
6.3 创建项目
1 [student@workstation ~]$ oc login -u developer -p redhat \2 https://master.lab.example.com
3 [student@workstation ~]$ oc new-project schedule-is
6.4 创建应用
1 [student@workstation ~]$ oc new-app --name=phpmyadmin \2 --docker-image=registry.lab.example.com/phpmyadmin/phpmyadmin:4.7
6.5 创建服务账户
1 [student@workstation ~]$ oc login -u admin -p redhat2 [student@workstation ~]$ oc project schedule-is
3 [student@workstation ~]$ oc create serviceaccount phpmyadmin-account
6.6 授权特权运行
1 [student@workstation ~]$ oc adm policy add-scc-to-user anyuid \2 -z phpmyadmin-account
6.7 更新pod
1 [student@workstation ~]$ oc login -u developer2 [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
6.8 更新内部仓库image
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
6.9 tag镜像
1 [student@workstation schedule-is]$ docker tag 93d0d7db5ce2 \2 docker-registry-default.apps.lab.example.com/schedule-is/phpmyadmin:4.7
3#打完标记进行推送。
6.10 登录docker仓库
6.11 修改信任
1 [student@workstation schedule-is]$ ./trust_internal_registry.sh
6.12 推送image
1 [student@workstation schedule-is]$ docker push \2 docker-registry-default.apps.lab.example.com/schedule-is/phpmyadmin:4.7
6.13 确认更新
1 [student@workstation schedule-is]$ oc get pods2 NAME READY STATUS RESTARTS AGE
3 phpmyadmin-3-hnfjk 1/1 Running 0 23s
七 管理应用部署实验
7.1 前置准备
7.2 本练习准备
1 [student@workstation ~]$ lab manage-review setup
7.3 确认region
1 [student@workstation ~]$ oc login -uadmin -predhat https://master.lab.example.com2 [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
7.4 修改region
1 [student@workstation ~]$ oc label node node1.lab.example.com region=services --overwrite=true2 [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
7.5 创建项目
1 [student@workstation ~]$ oc new-project manage-review
7.6 创建应用
1 [student@workstation ~]$ oc new-app -i php:7.0 \2 http://registry.lab.example.com/version
7.7 扩展应用
1 [student@workstation ~]$ oc scale dc version --replicas=32 [student@workstation ~]$ oc get pods -o wide #确认验证
3 NAME READY STATUS RESTARTS AGE IP NODE
4version-1-9626w 1/1 Running 0 40s 10.129.0.55 node2.lab.example.com
5version-1-build 0/1 Completed 0 1m 10.129.0.52 node2.lab.example.com
6version-1-f6vj2 1/1 Running 0 40s 10.129.0.56 node2.lab.example.com
7version-1-mrhk4 1/1 Running 0 45s 10.129.0.54 node2.lab.example.com
7.8 调度pod
1 [student@workstation ~]$ oc export dc version -o yaml > version-dc.yml #导出yaml2 spac
3 ……
4 template:
5 metadata:
6 ……
7 spec:
8 nodeSelector: #添加节点选择器
9 region: applications
10 ……
7.9 迭代部署
1 [student@workstation ~]$ oc replace -f version-dc.yml #迭代
7.10 确认验证
1 [student@workstation ~]$ oc get pod -o wide2 NAME READY STATUS RESTARTS AGE IP NODE
3version-1-build 0/1 Completed 0 15m 10.129.0.52 node2.lab.example.com
4version-2-2bmqq 1/1 Running 0 58s 10.129.0.60 node2.lab.example.com
5version-2-nz58r 1/1 Running 0 1m 10.129.0.59 node2.lab.example.com
6version-2-rlj2h 1/1 Running 0 1m 10.129.0.58 node2.lab.example.com
7.11 修改region
1 [student@workstation ~]$ oc label node node1.lab.example.com region=applications --overwrite=true2 [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
7.12 终止node2
1 [student@workstation ~]$ oc adm manage-node --schedulable=false node2.lab.example.com2 NAME STATUS ROLES AGE VERSION
3 node2.lab.example.com Ready,SchedulingDisabled compute 2d v1.9.1+a0ce1bc657
7.13 删除pod
1 [student@workstation ~]$ oc adm drain node2.lab.example.com --delete-local-data
7.14 查看pod
1 [student@workstation ~]$ oc get pods -o wide2 NAME READY STATUS RESTARTS AGE IP NODE
3version-2-d9fhp 1/1 Running 0 3m 10.128.0.34 node1.lab.example.com
4version-2-jp5gr 1/1 Running 0 3m 10.128.0.35 node1.lab.example.com
5version-2-z5lv5 1/1 Running 0 3m 10.128.0.33 node1.lab.example.com
7.15 暴露服务
1 [student@workstation ~]$ oc expose service version --hostname=version.apps.lab.example.com2 [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>
7.16 确认验证
1 [student@workstation ~]$ lab manage-review grade #环境脚本判断
7.17 还原环境
1 [student@workstation ~]$ oc adm manage-node --schedulable=true node2.lab.example.com2 [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
以上是 007.OpenShiefc管理应用部署 的全部内容, 来源链接: utcz.com/a/61129.html