008.OpenShiefc Metric应用
一 METRICS子系统组件
1.1 metric架构介绍
- Heapster
- Hawkular Metrics
- Hawkular Agent
- Cassandra
- web控制台调用Hawkular Metrics API来获取数据,以呈现项目中pod的性能图形。如果没有部署度量子系统,则不显示图表。
- oc adm top命令使用Heapster API来获取关于集群中所有pod和节点的当前状态的数据。
- Kubernetes的autoscaler控制器调用Heapster API来从部署中获取关于所有pod当前状态的数据,以便决定如何伸缩部署控制器。
1.2 访问Heapster和Hawkular
1.3 Metrics subsystem大小
1.4 CASSANDRA配置持久存储
二 METRICS子系统
2.1 部署metrics子系统
1 [defaults]2 remote_user = student
3 inventory = ./inventory
4 log_path = ./ansible.log
5 [privilege_escalation]
6 become = yes
7 become_user = root
8 become_method = sudo
9 Metrics子系统剧本:
10# ansible-playbook \
11 /usr/share/ansible/openshift-ansible/playbooks
2.2 卸载metrics子系统
1# ansible-playbook \2 /usr/share/ansible/openshift-ansible/playbooks/openshift-metrics/config.yml \
3 -e openshift_metrics_install_metrics=False
2.3 验证metrics子系统
2.4 部署metrics子系统常见错误
- image缺失;
- metrics所需资源过高,节点无法满足;
- Cassandra pod所需的持久卷无法满足。
2.5 其他配置
2.6 metrics涉及变量
- openshift_metrics_cassandra_replicas
- openshift_metrics_hawkular_replicas
- openshift_metrics_cassandra_requests_memory
- openshift_metrics_cassandra_limits_memory
- openshift_metrics_cassandra_requests_cpu
- openshift_metrics_cassandra_limits_cpu
- openshift_metrics_hawkular_requests_memory
- openshift_metrics_heapster_requests_memory
- openshift_metrics_duration
- openshift_metrics_resolution
- openshift_metrics_cassandra_storage_type
- openshift_metrics_cassandra_pvc_prefix
- openshift_metrics_cassandra_pvc_size
- openshift_metrics_image_prefix
- openshift_metrics_image_version
- openshift_metrics_heapster_standalone
- openshift_metrics_hawkular_hostname
1 [OSEv3:vars]2 ...output omitted...
3 openshift_metrics_cassandra_replicas=2
4 openshift_metrics_cassandra_requests_memory=2Gi
5 openshift_metrics_cassandra_pvc_size=50Gi
1# ansible-playbook \2 /usr/share/ansible/openshift-ansible/playbooks/openshift-metrics/config.yml \
3 -e openshift_metrics_cassandra_replicas=3 \
4 -e openshift_metrics_cassandra_requests_memory=4Gi \
5 -e openshift_metrics_cassandra_pvc_size=25Gi
三 安装metrics子系统
3.1 前置准备
3.2 本练习准备
1 [student@workstation ~]$ lab install-metrics setup
3.3 验证image
1 [student@workstation ~]$ docker-registry-cli registry.lab.example.com \2search metrics-cassandra ssl
3 [student@workstation ~]$ docker-registry-cli registry.lab.example.com \
4search ose-recycler ssl
3.4 验证NFS
1 [root@services ~]# ll -aZ /exports/metrics/2 drwxrwxrwx. nfsnobody nfsnobody unconfined_u:object_r:default_t:s0 .
3 drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 ..
4 [root@services ~]# cat /etc/exports.d/openshift-ansible.exports
3.5 创建PV
1 [student@workstation ~]$ cat /home/student/DO280/labs/install-metrics/metrics-pv.yml2 apiVersion: v1
3 kind: PersistentVolume
4 metadata:
5name: metrics
6 spec:
7 capacity:
8 storage: 5Gi #定义capacity.storage容量为5G
9 accessModes:
10 - ReadWriteOnce #定义访问模式
11 nfs:
12path: /exports/metrics #定义nfs.path
13 server: services.lab.example.com #定义nfs.services
14 persistentVolumeReclaimPolicy: Recycl #定义回收策略
1 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com2 [student@workstation ~]$ oc create -f /home/student/DO280/labs/install-metrics/metrics-pv.yml
3 [student@workstation ~]$ oc get pv
4 NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
5 metrics Gi RWO Recycle Available 14s
3.6 规划安装变量
3.7 配置安装变量
1 [student@workstation ~]$ cd /home/student/DO280/labs/install-metrics2 [student@workstation install-metrics]$ cat metrics-vars.txt
3# Metrics Variables
4# Append the variables to the [OSEv3:vars] group
5 openshift_metrics_install_metrics=True
6 openshift_metrics_image_prefix=registry.lab.example.com/openshift3/ose-
7 openshift_metrics_image_version=v3.9
8 openshift_metrics_heapster_requests_memory=300M
9 openshift_metrics_hawkular_requests_memory=750M
10 openshift_metrics_cassandra_requests_memory=750M
11 openshift_metrics_cassandra_storage_type=pv
12 openshift_metrics_cassandra_pvc_size=5Gi
13 openshift_metrics_cassandra_pvc_prefix=metrics
14 [student@workstation install-metrics]$ cat metrics-vars.txt >> inventory
15 [student@workstation install-metrics]$ lab install-metrics grade #本环境使用脚本判断配置
3.8 执行安装
1 [student@workstation install-metrics]$ ansible-playbook /usr/share/ansible/openshift-ansible/playbooks/openshift-metrics/config.yml
3.9 验证安装
1 [student@workstation install-metrics]$ oc get pvc -n openshift-infra #验证持久卷是否成功挂载2 NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
3 metrics-1 Bound metrics 5Gi RWO 5m
4 [student@workstation install-metrics]$ oc get pod -n openshift-infra #验证metric相关pod
5 NAME READY STATUS RESTARTS AGE
6 hawkular-cassandra-1-6k7fr 1/1 Running 0 5m
7 hawkular-metrics-z9v85 1/1 Running 0 5m
8 heapster-mbdcl 1/1 Running 0 5m
9 [student@workstation install-metrics]$ oc get route -n openshift-infra #查看metric route地址
10 NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
11 hawkular-metrics hawkular-metrics.apps.lab.example.com hawkular-metrics <all> reencrypt
12 None
3.10 部署测试应用
1 [student@workstation ~]$ oc login -u developer -p redhat \2 https://master.lab.example.com #登录OpenShift
3 [student@workstation ~]$ oc new-project load#创建project
4 [student@workstation ~]$ oc new-app --name=hello \
5 --docker-image=registry.lab.example.com/openshift/hello-openshift #部署应用
6 [student@workstation ~]$ oc scale --replicas=9 dc/hello #扩展应用
7 [student@workstation ~]$ oc get pod -o wide #查看pod
8 NAME READY STATUS RESTARTS AGE IP NODE
9 hello-1-4nvfd 1/1 Running 0 1m 10.129.0.40 node2.lab.example.com
10 hello-1-c9f8t 1/1 Running 0 1m 10.128.0.22 node1.lab.example.com
11 hello-1-dfczg 1/1 Running 0 1m 10.128.0.23 node1.lab.example.com
12 hello-1-dvdx2 1/1 Running 0 1m 10.129.0.36 node2.lab.example.com
13 hello-1-f6rsl 1/1 Running 0 1m 10.128.0.20 node1.lab.example.com
14 hello-1-m2hb4 1/1 Running 0 1m 10.129.0.39 node2.lab.example.com
15 hello-1-r64z9 1/1 Running 0 1m 10.128.0.21 node1.lab.example.com
16 hello-1-tf4l5 1/1 Running 0 1m 10.129.0.37 node2.lab.example.com
17 hello-1-wl6zx 1/1 Running 0 1m 10.129.0.38 node2.lab.example.com
18 [student@workstation ~]$ oc expose svc hello
3.11 压力测试
1 [student@workstation ~]$ sudo yum -y install httpd-tools2 [student@workstation ~]$ ab -n 300000 -c 20 http://hello-load.apps.lab.example.com/
3.12 查看资源使用情况
1 [student@workstation ~]$ oc login -u admin -p redhat2 [student@workstation ~]$ oc adm top node \
3 --heapster-namespace=openshift-infra \
4 --heapster-scheme=https
5 NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
6 master.lab.example.com 273m 13% 1271Mi 73%
7 node1.lab.example.com 1685m 84% 3130Mi 40%
8 node2.lab.example.com 1037m 51% 477Mi 6%
3.13 获取指标
1 [student@workstation ~]$ cat ~/DO280/labs/install-metrics/node-metrics.sh #使用此脚本获取指标
1 [student@workstation ~]$ ./DO280/labs/install-metrics/node-metrics.sh
以上是 008.OpenShiefc Metric应用 的全部内容, 来源链接: utcz.com/a/61142.html