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】。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

点击【Alerts】,然后点击【scaleup(0 active)】。显示配置的Alerts。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

11,设置grafana

通过浏览器打开http://<HOST_NAME or HOST_IP>:31000,输入用户名/密码为admin/admin。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

11-1,设置Data Source。

点击【Create your first data source】。

输入Name、Type、URL、Access相关信息,点击【Add】。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

 

点击【Save & Test】,确认Data source工作正常。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

 11-23,配置Dashboard。

点击【Dashboards】⇒【New】。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

点击【Graph】

 Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

点击【Panel Title】 ,然后点击【Edit】

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

在Query的A处输入: webapp_config_open_sessions_current_count{app="testwebapp"}

在Query的Legend format处输入:{{pod_name}} :appName={{app}} : serverName={{weblogic_serverName}}

 Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

 点击【Legend】,勾选Values的Current。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

点击【Alert】,然后点击【Create Alert】。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

修改Conditions,

WHEN:sum()

IS ABOVE:15

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

点击右上角的保存图标。

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

输入,

New name:Weblogic Dashboard

然后点击【Save】

Kubernetes上使用Weblogic Kubernetes Operator实现autoscaling

 

未完!

 

 

 

 

相关文章:

  • 2021-06-29
  • 2022-12-23
  • 2021-07-03
  • 2021-07-01
  • 2021-08-01
  • 2021-06-08
  • 2022-02-20
  • 2021-08-13
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2021-11-15
  • 2021-08-13
  • 2021-12-27
  • 2021-09-04
相关资源
相似解决方案