GKE AutoPilotモードの制約
GKE の AutoPilotを利用する上で把握しておいた方がよい制約をメモしておきます。
AdmissionWebhook
Autopilotは、特定の条件でAdmissionWebhookの書き換え、拒否を行います。 https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-security?hl=ja#built-in-security
リソースリクエスト
AutoPilotは、リソースリクエストを書き換えます。ワークロードのリソースリクエストを指定しない場合、RequestとLimitがデフォルト値で設定されます。 デフォルトでは小規模なワークロード向けの指定になるため、実運用にあたっては、ワークロードのリソースリクエストを全て指定する必要があります。 https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-resource-requests?hl=ja#defaults
Nodeの増減ができない
AutoPilotの場合 Nodeの増減はユーザーからはコントロールできません。そのため、必要なリソースが一気に増えた際には、Nodeの追加を伴う場合があり、この場合時間がかかります。具体的には helm install などでリソースを一気に追加した場合にタイムアウトすることがありました。
まとめ
Admission Webhookを利用してSidecarの注入などワークロードの書き換えを行うツールを導入する際は注意が必要かなと思います。 具体的にはtelepresenceを導入しようとしてかなりはまりました。 telepresenceは、Admisson Webhookを利用してtraffic-agent というコンテナをSidecarとして追加するのですが、そのときに以下のエラーが発生し、解決が困難でした。
admission webhook "gkepolicy.common-webhooks.networking.gke.io" denied the request: GKE Warden rejected the request because it violates one or more constraints. Violations details: {"[denied by autogke-pod-limit-constraints]": ["container 'traffic-agent' does not have resources/limits defined for all resources which required in Autopilot clusters."]} Requested by user: 'system:serviceaccount:kube-system:replicaset-controller', groups: 'system:serviceaccounts,system:serviceaccounts:kube-system,system:authenticated'.
agentのresourceを指定できるオプション( https://www.getambassador.io/docs/telepresence/latest/reference/cluster-config#resources ) があり、指定してみたのですがエラーは解決しませんでした。 結局 AutoPilotは諦めて Standardクラスタを利用して解決しました。
おまけ
GKE Autopilotではなく、telepresenceの問題なのですが、 interceptを行うときにportの指定方法によっては NET_ADMIN特権が必要になり、エラーになる可能性があります。 以下のようなエラーがでます。
admission webhook "gkepolicy.common-webhooks.networking.gke.io" denied the request: GKE Warden rejected the request because it violates one or more constraints. Violations details: {"[denied by autogke-default-linux-capabilities]": ["linux capability 'NET_ADMIN' on container 'tel-agent-init' not allowed; Autopilot only allows the capabilities: 'AUDIT_WRITE,CHOWN,DAC_OVERRIDE,FOWNER,FSETID,KILL,MKNOD,NET_BIND_SERVICE,NET_RAW,SETFCAP,SETGID,SETPCAP,SETUID,SYS_CHROOT,SYS_PTRACE'."], "[denied by autogke-pod-limit-constraints]": ["container 'tel-agent-init' does not have resources/limits defined for all resources which required in Autopilot clusters.", "container 'traffic-agent' does not have resources/limits defined for all resources which required in Autopilot clusters."]} Requested by user: 'system:serviceaccount:kube-system:replicaset-controller', groups: 'system:serviceaccounts,system:serviceaccounts:kube-system,system:authenticated'.
これを回避するには、deploymentで公開するportに名前をつけ、serviceからはその名前を指定します。
deploymentで httpという名前をつける
ports: - name: http containerPort: 80 protocol: TCP
serviceのtargetPortでは名前を指定する
ports: - protocol: TCP port: 80 targetPort: http
これはtelepresenceの公式サイトにも記述があります。