Skip to content

kindにmetrics-serverをインストール ​

HorizontalPodAutoscalerやVerticalPodAutoscalerリソースを使うためのmetrics-serverをkindにインストールします。

手順 ​

cf. https://github.com/kubernetes-sigs/metrics-server#installation

  • 各種リソースを作成します:
shell
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
  • 現時点ではmetrics-serverが作成されていない状態です:
shell
kubectl get deploy metrics-server -n kube-system
  • metrics-serverのマニフェストをeditし、spec.template.spec.containers[0].argsに--kubelet-insecure-tlsを追加します(kubeletの証明書が自己証明書の場合などに必要、例えばkubeadmのデフォルト構成なら必要となります):
shell
kubectl edit deployment metrics-server -n kube-system

しばらくするとmetrics-serverが作成されます。

動作確認 ​

  • 検証用のDeploymentを作成します:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
        - name: nginx-container
          image: nginx:stable
          resources:
            requests:
              cpu: 100m
            limits:
              cpu: 500m
shell
kubectl apply -f sample-deploy.yaml
  • 検証用のHPAを作成します:
yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: sample-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: sample-deploy
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50
shell
kubectl apply -f sample-hpa.yaml