From a4571de9e76c897139d91f4bead46f4eeb91bfd3 Mon Sep 17 00:00:00 2001 From: Hiroshi Hayakawa Date: Wed, 16 Sep 2020 12:17:52 +0900 Subject: [PATCH] fix scripts and settings for CNDT2020 presentation --- README.md | 38 +++++++++++++++---- cowweb/cowweb-hpa.yaml | 11 +++++- cowweb/cowweb.yaml | 24 +++++++++--- gatling/scripts/run.sh | 21 ++-------- .../simulations/cowweb/cowweb.scala | 16 -------- ingress-nginx/overriding-chart-values.yaml | 2 + 6 files changed, 64 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index ee18d8e..2fbb0fa 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Kubernetes の Horizontal Pod Autoscaler のいろいろな実験を行うリポ ### Nginx Ingress Controller ```bash -$ kubectl create -f ingress-nginx-namespace.yaml +$ kubectl create -f ingress-nginx/ingress-nginx-namespace.yaml $ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx @@ -37,23 +37,45 @@ $ kubectl apply -f ./cowweb/ $ kustomize build ./kube-metrics-adapter/ | kubectl apply -f - ``` -メトリクスの取得 +負荷試験の実行 --- +`gatling/scripts/run.sh` を編集して、アプリケーションのエンドポイントの、ホストパート部分までの文字列を `BASE URL` に記述します。 +また、必要に応じて負荷試験用の各種パラメータを変更しておきます。 + +``` +$ vim gatling/scripts/run.sh +``` + +```diff +- BASE_URL=http://localhost:8080 ++ BASE_URL=http://128.128.128.128 +``` -rps@nginx-ingress-controller +負荷試験の実行はコンテナ化されたGatringから実行します。 ``` -while true; do kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/cowweb/prometheus-query?labelSelector=query-name=processed-events-per-second" | jq '.items[].value'; sleep 1; done +$ cd gatling +$ docker-compose up ``` -cpu +メトリクスの取得 +--- +負荷試験中のメトリクスの推移を観察するには、 `kubectl get --raw` を使ってAPI Serverから取得します。 + +### rps@nginx-ingress-controller ``` -while true; do kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/cowweb/pods/" | jq -r '.items[] | .containers[].usage.cpu'; echo ---; sleep 1; done +while true; do date +"%Y/%m/%d %H:%M:%S"; kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/cowweb/prometheus-query?labelSelector=query-name=processed-events-per-second" | jq '.items[].value'; sleep 1; done ``` -memory +### cpu ``` -while true; do kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/cowweb/pods/" | jq -r '.items[] | .containers[].usage.memory'; echo ---; sleep 1; done +while true; do date +"%Y/%m/%d %H:%M:%S"; kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/cowweb/pods/" | jq -r '.items[] | .containers[].usage.cpu'; sleep 1; done +``` + +### memory + ``` +while true; do date +"%Y/%m/%d %H:%M:%S"; kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/cowweb/pods/" | jq -r '.items[] | .containers[].usage.memory'; sleep 1; done +``` \ No newline at end of file diff --git a/cowweb/cowweb-hpa.yaml b/cowweb/cowweb-hpa.yaml index 94b67db..c6c62bc 100644 --- a/cowweb/cowweb-hpa.yaml +++ b/cowweb/cowweb-hpa.yaml @@ -14,7 +14,7 @@ spec: apiVersion: apps/v1 kind: Deployment name: cowweb - minReplicas: 2 + minReplicas: 4 maxReplicas: 10 metrics: - type: External @@ -26,4 +26,11 @@ spec: query-name: processed-events-per-second target: type: Value - averageValue: "2000m" \ No newline at end of file + averageValue: "70" + behavior: + scaleUp: + stabilizationWindowSeconds: 0 + policies: + - type: Pods + value: 4 + periodSeconds: 5 \ No newline at end of file diff --git a/cowweb/cowweb.yaml b/cowweb/cowweb.yaml index b2d5f66..15918b1 100644 --- a/cowweb/cowweb.yaml +++ b/cowweb/cowweb.yaml @@ -4,7 +4,7 @@ metadata: namespace: cowweb name: cowweb spec: - replicas: 2 + replicas: 4 selector: matchLabels: app: cowweb @@ -15,7 +15,15 @@ spec: spec: containers: - name: cowweb - image: ghcr.io/hhiroshell/cowweb-go/cowweb:latest + image: ghcr.io/hhiroshell/cowweb-go/cowweb:v1.0.0 + command: + - ./cowweb + args: + - serve + - --port=8080 + - --slow + - --load=128 + imagePullPolicy: Always ports: - name: api containerPort: 8080 @@ -23,6 +31,12 @@ spec: httpGet: path: /say port: api - initialDelaySeconds: 5 - periodSeconds: 10 - imagePullPolicy: Always \ No newline at end of file + initialDelaySeconds: 1 + periodSeconds: 1 + resources: + requests: + cpu: "200m" + memory: "128Mi" + limits: + cpu: "200m" + memory: "128Mi" \ No newline at end of file diff --git a/gatling/scripts/run.sh b/gatling/scripts/run.sh index 36332c9..e3c9afa 100755 --- a/gatling/scripts/run.sh +++ b/gatling/scripts/run.sh @@ -1,24 +1,11 @@ #!/bin/sh -# Copyright (c) 2019 Hiroshi Hayakawa -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - cd `dirname $0` -USERS=1000 -DURATION=30 SCENARIO=cowweb.cowweb +BASE_URL=http://localhost:8080 +USERS=1000 +DURATION=60 DESCRIPTION="USERS=$USERS | DURATION=$DURATION" -JAVA_OPTS="-Dusers=$USERS -Dduring=$DURATION" gatling -s $SCENARIO -rd "$DESCRIPTION" \ No newline at end of file +JAVA_OPTS="-DbaseUrl=$BASE_URL -Dusers=$USERS -Dduring=$DURATION" gatling -s $SCENARIO -rd "$DESCRIPTION" \ No newline at end of file diff --git a/gatling/user-files/simulations/cowweb/cowweb.scala b/gatling/user-files/simulations/cowweb/cowweb.scala index 32fe106..2991762 100644 --- a/gatling/user-files/simulations/cowweb/cowweb.scala +++ b/gatling/user-files/simulations/cowweb/cowweb.scala @@ -1,19 +1,3 @@ -/* - * Copyright (c) 2019 Hiroshi Hayakawa - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package cowweb import io.gatling.core.Predef._ diff --git a/ingress-nginx/overriding-chart-values.yaml b/ingress-nginx/overriding-chart-values.yaml index 207809e..c76b173 100644 --- a/ingress-nginx/overriding-chart-values.yaml +++ b/ingress-nginx/overriding-chart-values.yaml @@ -2,6 +2,8 @@ ## Ref: https://github.com/kubernetes/ingress/blob/master/controllers/nginx/configuration.md ## controller: + replicaCount: 2 + ## Expose an exporter port on 10254(default) ## metrics: