Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling
前提:
a,先搭建好weblogic operator环境,发布testwebapp.war。
可以参照Kubernetes上使用Weblogic Kubernetes Operator创建Weblogic Domain(使用NFS方式)创建。
详细步骤:
1,创建wls-exporter.war
git clone https://github.com/oracle/weblogic-monitoring-exporter.git
进入到项目根目录
cd weblogic-monitoring-exporter
mvn install
创建配置文件
cat > ./webapp/config.yaml <<EOF
query_sync:
url: http://coordinator:8099/
interval: 5
metricsNameSnakeCase: true
queries:
- applicationRuntimes:
key: name
keyName: app
componentRuntimes:
type: WebAppComponentRuntime
prefix: webapp_config_
key: name
values: [deploymentState, contextRoot, sourceInfo, openSessionsHighCount, openSessionsCurrentCount, sessionsOpenedTotalCount, sessionCookieMaxAgeSecs, sessionInvalidationIntervalSecs, sessionTimeoutSecs, singleThreadedServletPoolSize, sessionIDLength, servletReloadCheckSecs, jSPPageCheckSecs]
servlets:
prefix: weblogic_servlet_
key: servletName
values: [invocationTotalCount, reloadTotal, executionTimeAverage, poolMaxCapacity, executionTimeTotal, reloadTotalCount, executionTimeHigh, executionTimeLow]
- JVMRuntime:
key: name
values: [heapFreeCurrent, heapFreePercent, heapSizeCurrent, heapSizeMax, uptime, processCpuLoad]
EOF
进入到webapp目录
cd webapp
创建
mvn package -Dconfiguration=config.yaml
回到根目录
cd ..
2,发布webapp/target/wls-exporter.war到weblogic domain的cluster-1。
3,创建Ingress
cat > wls-exporter-path-routing.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-pathrouting-wls-exporter
namespace: sample-domain2-ns
annotations:
kubernetes.io/ingress.class: traefik
ingress.kubernetes.io/rewrite-target: /wls-exporter
ingress.kubernetes.io/rule-type: PathPrefix
spec:
rules:
- host:
http:
paths:
- path: /wls-exporter
backend:
serviceName: sample-domain2-cluster-cluster-1
servicePort: 8001
EOF
kubectl apply -f wls-exporter-path-routing.yaml
cat > management-path-routing.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-pathrouting-management
namespace: sample-domain2-ns
annotations:
kubernetes.io/ingress.class: traefik
ingress.kubernetes.io/rewrite-target: /management
ingress.kubernetes.io/rule-type: PathPrefix
# ingress.kubernetes.io/rule-type: PathPrefixStrip
spec:
rules:
- host:
http:
paths:
- path: /management
backend:
serviceName: sample-domain2-cluster-cluster-1
servicePort: 8001
EOF
kubectl apply -f management-path-routing.yaml
4,确认weblogic managed server的metrics。
打开http://<HOST_NAME or HOST_IP>:30305/wls-exporter/metrics,输入用户名/密码为weblogic/welcome1。
5,创建RBAC
cd samples/kubernetes
从template文件拷贝配置文件
cp crossnsrbac.yaml my-crossnsrbac.yaml
修改my-crossnsrbac.yaml
vi my-crossnsrbac.yaml
修改前
name: weblogic-domain-cluster-role
name: domain-cluster-rolebinding
namespace: weblogic-domain
name: weblogic-domain-cluster-role
name: weblogic-domain-operator-rolebinding
namespace: weblogic-operator
namespace: weblogic-domain
修改后
name: sample-domain2-ns-cluster-role
name: sample-domain2-cluster-rolebinding
namespace: sample-domain2-ns
name: sample-domain2-ns-cluster-role
name: sample-domain2-ns-operator-rolebinding
namespace: sample-weblogic-operator-ns
namespace: sample-domain2-ns
发布
kubectl apply -f my-crossnsrbac.yaml
6,创建monitoring namespace
kubectl apply -f monitoring-namespace.yaml
7,发布prometheus
从template文件拷贝
cp prometheus-withalertmanager-deployment.yaml my-prometheus-withalertmanager-deployment.yaml
修改my-prometheus-withalertmanager-deployment.yaml
vi my-prometheus-withalertmanager-deployment.yaml
修改前
if sum(webapp_config_open_sessions_current_count{webapp="OpenSessionApp"}) > 1
summary = "Scale up when current sessions is greater than 1",
description = "Firing when total sessions active greater than 1"
修改后
if sum(webapp_config_open_sessions_current_count{app="testwebapp"}) > 15
summary = "Scale up when current sessions is greater than 15",
description = "Firing when total sessions active greater than 15"
发布
kubectl apply -f my-prometheus-withalertmanager-deployment.yaml
8,发布grafana
kubectl apply -f grafana-deployment.yaml
9,发布alertmanager
kubectl apply -f alertmanager-deployment.yaml
10,确认和配置prometheus
通过浏览器打开http://<HOST_NAME or HOST_IP>:32000。
在Expression处输入webapp_config_open_sessions_current_count{app="testwebapp"} >= 0,点击【Execute】。
点击【Alerts】,然后点击【scaleup(0 active)】。显示配置的Alerts。
11,设置grafana
通过浏览器打开http://<HOST_NAME or HOST_IP>:31000,输入用户名/密码为admin/admin。
11-1,设置Data Source。
点击【Create your first data source】。
输入Name、Type、URL、Access相关信息,点击【Add】。
点击【Save & Test】,确认Data source工作正常。
11-23,配置Dashboard。
点击【Dashboards】⇒【New】。
点击【Graph】
点击【Panel Title】 ,然后点击【Edit】
在Query的A处输入: webapp_config_open_sessions_current_count{app="testwebapp"}
在Query的Legend format处输入:{{pod_name}} :appName={{app}} : serverName={{weblogic_serverName}}
点击【Legend】,勾选Values的Current。
点击【Alert】,然后点击【Create Alert】。
修改Conditions,
WHEN:sum()
IS ABOVE:15
点击右上角的保存图标。
输入,
New name:Weblogic Dashboard
然后点击【Save】
未完!