LoginSignup
0
0

More than 1 year has passed since last update.

EKSでk8sクラスター作成時にサブネットの紐付けをラクにするTips

Last updated at Posted at 2023-01-10

記事の目的

eksctlコマンドでクラスターを作成する際、サブネットを紐付けるためにサブネットIDを調べて指定するのが面倒くさいので、サブネットにタグをつけて自動認識できるようにする

前提

動作確認環境

  • k8sバージョン 1.23
  • aws cliバージョン 2.7.31
  • eksctlバージョン 0.122.0
  • kubectlバージョン 1.25.2

本題

k8sクラスターを作成したい対象のサブネットすべてに任意のタグをつける

タグのKey、Valueは何でも良いが、今回はForK8SPrivateCluster=trueとする

Key: ForK8SPrivateCluster
Value: true

aa547f90feeafb5d4f59b4979f695ab6.png

クラスター作成

# タグ「ForK8SPrivateCluster=true」がついているサブネットのIDリストをカンマ区切りで取得
K8S_CLUSTER_SUBNETS=$(aws ec2 describe-subnets --filters "Name=tag:ForK8SPrivateCluster,Values=true" --query 'Subnets[].SubnetId | join(`","`, @)' --output=text)

# 取得したカンマ区切りのサブネットID一覧を表示
echo "subnets: $K8S_CLUSTER_SUBNETS"

# 取得したサブネットIDを使ってクラスター作成
eksctl create cluster \
--name hoge-cluster \
--region ap-northeast-1 \
--vpc-private-subnets $K8S_CLUSTER_SUBNETS \
--with-oidc \
--without-nodegroup
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