LoginSignup
0
1

More than 3 years have passed since last update.

eksctlでEKS Fargateクラスターを作成する

Last updated at Posted at 2020-06-12

ecs-cliでECS Fargateクラスターを作成したので、今度はeksctlでEKS Fargateクラスターを作成してみる。
なおk8sそのものはkubectlでちょっと遊んだことあります程度なので、ほとんどゼロスタートに近い。追々学ぶことにして、まずはクラスター立てるところまで。

やりたいこと

  • EKSでFargateクラスターを立ててみる
  • eksctlを使ってみる

eksctlについて

コマンドでやるようだが、何やら二つある。
eksctl
aws eksコマンド

後者は要するにいつものAWS CLIだが、どっち使えばいいんだ?
と一瞬迷ったが、既にecs-cliに手を出してるし(ECSも、改めて見るとaws ecs create-clusterとかあった)、ここはkubectlっぽい名前のeksctlから始めてみればよかろうと雑に判断してスタート。

Step by Step

1. eksctlのインストール

公式を見ながらインストール。homebrewが入っていれば、eksctl自体のインストールは3分で終わる(コマンド出力は割愛)。kubectlも一緒にインストールしてくれるようだ。
参考までに、自分のmacのバージョンは以下の通り。先日更新したばかりのCatalinaの最新バージョンを使用しているが、特に問題は出なかった。

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.5
BuildVersion:   19F101
% brew tap weaveworks/tap
% brew install weaveworks/tap/eksctl

バージョンを見てみる。

% eksctl version
0.21.0

0.21.0が現行の最新バージョンの模様。

2. EKS Fargate作成

これも公式に記載があるので、まずは何も考えずに叩いてみる。
こちらは少々時間がかかる。待つことおよそ20分。

% eksctl create cluster --name myEKSFargate --version 1.16 --fargate
[ℹ]  eksctl version 0.21.0
[ℹ]  using region ap-northeast-1
[ℹ]  setting availability zones to [ap-northeast-1a ap-northeast-1c ap-northeast-1d]
[ℹ]  subnets for ap-northeast-1a - public:192.168.0.0/19 private:192.168.96.0/19
[ℹ]  subnets for ap-northeast-1c - public:192.168.32.0/19 private:192.168.128.0/19
[ℹ]  subnets for ap-northeast-1d - public:192.168.64.0/19 private:192.168.160.0/19
[ℹ]  using Kubernetes version 1.16
[ℹ]  creating EKS cluster "myEKSFargate" in "ap-northeast-1" region with Fargate profile
[ℹ]  if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=ap-northeast-1 --cluster=myEKSFargate'
[ℹ]  CloudWatch logging will not be enabled for cluster "myEKSFargate" in "ap-northeast-1"
[ℹ]  you can enable it with 'eksctl utils update-cluster-logging --region=ap-northeast-1 --cluster=myEKSFargate'
[ℹ]  Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "myEKSFargate" in "ap-northeast-1"
[ℹ]  2 sequential tasks: { create cluster control plane "myEKSFargate", no tasks }
[ℹ]  building cluster stack "eksctl-myEKSFargate-cluster"
[ℹ]  deploying stack "eksctl-myEKSFargate-cluster"
[ℹ]  waiting for the control plane availability...
[✔]  saved kubeconfig as "/Users/XXXXX/.kube/config"
[ℹ]  no tasks
[✔]  all EKS cluster resources for "myEKSFargate" have been created
[ℹ]  creating Fargate profile "fp-default" on EKS cluster "myEKSFargate"
[ℹ]  created Fargate profile "fp-default" on EKS cluster "myEKSFargate"
[ℹ]  "coredns" is now schedulable onto Fargate
[ℹ]  "coredns" pods are now scheduled onto Fargate
[ℹ]  "coredns" is now scheduled onto Fargate
[ℹ]  "coredns" pods are now scheduled onto Fargate
[ℹ]  kubectl command should work with "/Users/XXXXX/.kube/config", try 'kubectl get nodes'
[✔]  EKS cluster "myEKSFargate" in "ap-northeast-1" region is ready

できた。

% eksctl get cluster
NAME        REGION
myEKS       ap-northeast-1
myEKSFargate    ap-northeast-1

% eksctl get cluster myEKSFargate
NAME        VERSION STATUS  CREATED         VPC         SUBNETS                 SECURITYGROUPS
myEKSFargate    1.16    ACTIVE  2020-06-12T14:54:13Z    vpc-06XXXXXXXXdd    subnet-00XXXXXXXX15,subnet-0135XXXX1a3,subnet-02XXXXXXeb,subnet-03XXXXXXXX12,subnet-05XXXXXXXX83,subnet-08XXXXXXXXda    sg-01XXXXXXXX1a

必要なIAMロール等は自動作成してくれているようだ。

マネジメントコンソールからは以下の通り。正直、ECSの独特なコンソール画面より、こちらの方が見やすくていい。

スクリーンショット 2020-06-13 00.19.54.png

ただ、先程のコマンドだと、VPCから何から全部スクラッチで作成されてしまう模様。手軽ではあるが実用的でないので、既存のネットワークコンポーネントで作り直してみる。

3. 諸々パラメーターを指定して再度実行

まず削除。
クラスター本体の削除に5分くらいかかる。コマンド完了後も、CloudFormationスタックを非同期で削除しにいっていて、VPCやIAMのリソースをクリーンアップしている模様。これも含めると、トータル10分くらいはかかっている。

% eksctl delete cluster --name myEKSFargate
[ℹ]  eksctl version 0.21.0
[ℹ]  using region ap-northeast-1
[ℹ]  deleting EKS cluster "myEKSFargate"
[ℹ]  deleting Fargate profile "fp-default"
[ℹ]  deleted Fargate profile "fp-default"
[ℹ]  deleted 1 Fargate profile(s)
[✔]  kubeconfig has been updated
[ℹ]  cleaning up LoadBalancer services
[ℹ]  1 task: { delete cluster control plane "myEKSFargate" [async] }
[ℹ]  will delete stack "eksctl-myEKSFargate-cluster"
[✔]  all cluster resources were deleted

次に以下のコマンドで、自分好みの設定でEKS Fargateクラスターを再度作成する。
オプションはeksctl create cluster --helpでその場で確認しながらやってみた。

% eksctl create cluster --name myEKSFargate --version 1.16 --fargate  --vpc-public-subnets subnet-aeXXXXXXXXd9,subnet-d3XXXXXXXX8a,subnet-8eXXXXXXXXa6 --vpc-private-subnets subnet-87XXXXXXXXf0,subnet-ccXXXXXXXX95,subnet-80XXXXXXXXa8 --node-security-groups sg-a9XXXXXXXXcd
[ℹ]  eksctl version 0.21.0
[ℹ]  using region ap-northeast-1
[✔]  using existing VPC (vpc-a4XXXXXXXXc1) and subnets (private:[subnet-ccXXXXXXXX95 ...
(以下略)

こちらも20分ほどで無事作成された。

% eksctl get cluster myEKSFargate
NAME        VERSION STATUS  CREATED         VPC     SUBNETS                                             SECURITYGROUPS
myEKSFargate    1.16    ACTIVE  2020-06-12T15:50:12Z    vpc-a4XXXXXXXXc1    subnet-80XXXXXXXXa8,subnet-87XXXXXXXXf0,subnet-8eXXXXXXXXa6,subnet-aeXXXXXXXXd9,subnet-ccXXXXXXXX95,subnet-d3XXXXXXXX8a sg-0dXXXXXXXXa9

結論

起動するだけなら、EKS Fargateは拍子抜けするほど簡単。
運用に載せようとすると、EKSやk8s特有のつらみが顕在化してくるのかも知れないが、少なくとも本稿の内容の範囲では、(いちいち時間がかかる点を除けば)ハマリどころもなく至ってスムーズだった。

0
1
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
1