Skip to content

Commit

Permalink
fix scripts and settings for CNDT2020 presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hhiroshell committed Sep 16, 2020
1 parent 1e81fc1 commit a4571de
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 48 deletions.
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
```
11 changes: 9 additions & 2 deletions cowweb/cowweb-hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: cowweb
minReplicas: 2
minReplicas: 4
maxReplicas: 10
metrics:
- type: External
Expand All @@ -26,4 +26,11 @@ spec:
query-name: processed-events-per-second
target:
type: Value
averageValue: "2000m"
averageValue: "70"
behavior:
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Pods
value: 4
periodSeconds: 5
24 changes: 19 additions & 5 deletions cowweb/cowweb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
namespace: cowweb
name: cowweb
spec:
replicas: 2
replicas: 4
selector:
matchLabels:
app: cowweb
Expand All @@ -15,14 +15,28 @@ 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
readinessProbe:
httpGet:
path: /say
port: api
initialDelaySeconds: 5
periodSeconds: 10
imagePullPolicy: Always
initialDelaySeconds: 1
periodSeconds: 1
resources:
requests:
cpu: "200m"
memory: "128Mi"
limits:
cpu: "200m"
memory: "128Mi"
21 changes: 4 additions & 17 deletions gatling/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
#!/bin/sh

# Copyright (c) 2019 Hiroshi Hayakawa <[email protected]>
#
# 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"
JAVA_OPTS="-DbaseUrl=$BASE_URL -Dusers=$USERS -Dduring=$DURATION" gatling -s $SCENARIO -rd "$DESCRIPTION"
16 changes: 0 additions & 16 deletions gatling/user-files/simulations/cowweb/cowweb.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2019 Hiroshi Hayakawa <[email protected]>
*
* 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._
Expand Down
2 changes: 2 additions & 0 deletions ingress-nginx/overriding-chart-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a4571de

Please sign in to comment.