LoginSignup
0
0

More than 5 years have passed since last update.

AKS debug tips

Last updated at Posted at 2018-04-16

Hexadite/acs-keyvault-agentを試す必要があり、2時間を使ってしまったので、その過程で発生した AKS 関連のデバッグのためのコマンド等を自分のためにメモしておきたい。

代表的なデバッグコマンド

Pod のログを見る

kubectl logs <Pod name>

Pod の詳細を見る

ちなみに他のリソースを見たい場合も、Pod 部分を変えればよい

kubectl describe pod <PodName>

k8s クラスターのイベントを見る

Podのログで分からないケースでもこちらで分かる場合もあり。

kubectl get events

コンテナにログイン

kubectl exec -it <Pod Name> -c <Container Name> /bin/bash

Initialize Container のログ

Pod にコンテナが二つあるケースと同じ

kubectl logs <Pod name> -c <Initialize Container name> 

Service Principal の取得

AKS をデプロイすると、どの Service Principal だったか忘れる場合がある。 Service Principal は各nodeの/ect/kubernetes/azure.json の下に配置している。であるので、次のような、yamlを作ってデプロイして、ログインするとよい。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-sp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: keyvault
    spec:
      containers:
      - image: alpine:latest
        name: test-app
        command: ["/bin/sh", "-c", "--"]
        args: ["while true; do sleep 5; done;"]
        volumeMounts:
        - name: host-sp
          mountPath: /host/azure.json
          readOnly: true
      volumes:
      - name: host-sp
        hostPath:
          # this file contains the cluster service-principal, it exists on every node by default
          path: /etc/kubernetes/azure.json
          type: File

これを作って、下記のようにすれば、どの Service Principal だったかわかります。

kubectl create -f some.yaml
kubectl exec -it <podname> /bin/bash
# cat /host/azure.json

ちなみに、上記のリポジトリは、Azure keyVault にサービスプリンシパルを渡すことなく、KeyVault からSecretsを引っ張ってくれて、volume 経由でアクセスできるようにするものです。

$ kubectl exec -ti test-keyvault-f849dd45c-2bcgc -c test-app /bin/sh
/ # cat /secrets/secrets/hello
world
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0