ラボセットアップ:カオスメッシュ、スケーリング、Podアフィニティ
このガイドでは、高可用性のプラクティスを実装してUIサービスの回復力を強化するための手順を説明します。ヘルムのインストール、UIサービスのスケーリング、Podアンチアフィニティの実装、およびアベイラビリティーゾーン間のポッド分布を視覚化するヘルパースクリプトの使用方法について説明します。
カオスメッシュのインストール
クラスターの回復力テスト能力を強化するために、カオスメッシュをインストールします。カオスメッシュはKubernetes環境向けの強力なカオスエンジニアリングツールです。さまざまな障害シナリオをシミュレートし、アプリケーションがどのように応答するかをテストすることができます。
ヘルムを使用して、クラスターにカオスメッシュをインストールしましょう:
Release "chaos-mesh" does not exist. Installing it now.
NAME: chaos-mesh
LAST DEPLOYED: Tue Aug 20 04:44:31 2024
NAMESPACE: chaos-mesh
STATUS: deployed
REVISION: 1
TEST SUITE: None
スケーリングとトポロジースプレッド制約
Kustomizeパッチを使用してUIデプロイメントを変更し、5つのレプリカにスケールアップし、トポロジースプレッド制約ルールを追加します。これにより、UIポッドが異なるノードに分散され、ノード障害の影響が軽減されます。
パッチファイルの内容は次のとおりです:
- Kustomize Patch
- Deployment/ui
- Diff
apiVersion: apps/v1
kind: Deployment
metadata:
name: ui
namespace: ui
spec:
replicas: 5
selector:
matchLabels:
app: ui
template:
metadata:
labels:
app: ui
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: ui
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: ui
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/created-by: eks-workshop
app.kubernetes.io/type: app
name: ui
namespace: ui
spec:
replicas: 5
selector:
matchLabels:
app: ui
app.kubernetes.io/component: service
app.kubernetes.io/instance: ui
app.kubernetes.io/name: ui
template:
metadata:
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
labels:
app: ui
app.kubernetes.io/component: service
app.kubernetes.io/created-by: eks-workshop
app.kubernetes.io/instance: ui
app.kubernetes.io/name: ui
spec:
containers:
- env:
- name: JAVA_OPTS
value: -XX:MaxRAMPercentage=75.0 -Djava.security.egd=file:/dev/urandom
- name: METADATA_KUBERNETES_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: METADATA_KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: METADATA_KUBERNETES_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
envFrom:
- configMapRef:
name: ui
image: public.ecr.aws/aws-containers/retail-store-sample-ui:1.2.1
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 45
periodSeconds: 20
name: ui
ports:
- containerPort: 8080
name: http
protocol: TCP
resources:
limits:
memory: 1.5Gi
requests:
cpu: 250m
memory: 1.5Gi
securityContext:
capabilities:
add:
- NET_BIND_SERVICE
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
volumeMounts:
- mountPath: /tmp
name: tmp-volume
securityContext:
fsGroup: 1000
serviceAccountName: ui
topologySpreadConstraints:
- labelSelector:
matchLabels:
app: ui
maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
- labelSelector:
matchLabels:
app: ui
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
volumes:
- emptyDir:
medium: Memory
name: tmp-volume
app.kubernetes.io/type: app
name: ui
namespace: ui
spec:
- replicas: 1
+ replicas: 5
selector:
matchLabels:
+ app: ui
app.kubernetes.io/component: service
app.kubernetes.io/instance: ui
app.kubernetes.io/name: ui
template:
[...]
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
labels:
+ app: ui
app.kubernetes.io/component: service
app.kubernetes.io/created-by: eks-workshop
app.kubernetes.io/instance: ui
app.kubernetes.io/name: ui
[...]
name: tmp-volume
securityContext:
fsGroup: 1000
serviceAccountName: ui
+ topologySpreadConstraints:
+ - labelSelector:
+ matchLabels:
+ app: ui
+ maxSkew: 1
+ topologyKey: topology.kubernetes.io/zone
+ whenUnsatisfiable: ScheduleAnyway
+ - labelSelector:
+ matchLabels:
+ app: ui
+ maxSkew: 1
+ topologyKey: kubernetes.io/hostname
+ whenUnsatisfiable: ScheduleAnyway
volumes:
- emptyDir:
medium: Memory
name: tmp-volume
KustomizeパッチとKustomizationファイルを使用して変更を適用します:
小売店のアクセシビリティの確認
これらの変更を適用した後、小売店がアクセス可能であることを確認することが重要です:
Waiting for k8s-ui-ui-5ddc3ba496-721427594.us-west-2.elb.amazonaws.com...
You can now access http://k8s-ui-ui-5ddc3ba496-721427594.us-west-2.elb.amazonaws.com
このコマンドが完了すると、URLが出力されます。新しいブラウザタブでこのURLを開いて、小売店がアクセス可能で正常に機能していることを確認します。
小売URLが操作可能になるまで5〜10分かかる場合があります。
ヘルパースクリプト:AZごとのポッドの取得
get-pods-by-az.shスクリプトは、ターミナルで異なるアベイラビリティゾーンにわたるKubernetesポッドの分布を視覚化するのに役立ちます。スクリプトファイルはgithubでこちらで確認できます。
スクリプトの実行
スクリプトを実行してアベイラビリティゾーン間のポッド分布を確認するには、次を実行します:
------us-west-2a------
ip-10-42-127-82.us-west-2.compute.internal:
ui-6dfb84cf67-6fzrk 1/1 Running 0 56s
ui-6dfb84cf67-dsp55 1/1 Running 0 56s
------us-west-2b------
ip-10-42-153-179.us-west-2.compute.internal:
ui-6dfb84cf67-2pxnp 1/1 Running 0 59s
------us-west-2c------
ip-10-42-186-246.us-west-2.compute.internal:
ui-6dfb84cf67-n8x4f 1/1 Running 0 61s
ui-6dfb84cf67-wljth 1/1 Running 0 61s
これらの変更の詳細については、次のセクションをご覧ください: