コンソールから作成した EKS クラスターに、eksctl でセルフマネージドノードを作成してみた

AWS
AWS
この記事は約12分で読めます。

別の検証でコンソールから作成していた EKS クラスターに、セルフマネージドノードを作成します。
以下のドキュメントを参考にしています。

Launching self-managed Amazon Linux nodes - Amazon EKS
This topic describes how you can launch Auto Scaling groups of Linux nodes that register with your Amazon EKS cluster.

セルフマネージドノードは、EKS ではなくユーザーが作成した EC2 を EKS クラスターに登録したものです。

eksctl を利用すれば AutoScaling グループや起動テンプレートをよしなに作成してくれるので、eksctl で作成します。

$ eksctl create nodegroup --cluster cluster --name self-node --node-type t3.medium --nodes-min 1 --nodes-max 1 --ssh-access --managed=false --ssh-public-key xxx
2023-02-26 10:29:22 [ℹ]  will use version 1.24 for new nodegroup(s) based on control plane version
2023-02-26 10:29:23 [!]  no eksctl-managed CloudFormation stacks found for "cluster", will attempt to create nodegroup(s) on non eksctl-managed cluster
Error: loading VPC spec for cluster "cluster": VPC configuration required for creating nodegroups on clusters not owned by eksctl: vpc.subnets, vpc.id, vpc.securityGroup

セルフマネージドノードを作成しようとすると、eksctl で所有していない場合は VPC の設定が必要と怒られました。

eksctl のドキュメントでもこの点について記載されていました。

This means that in order to create nodegroups or managed nodegroups on a cluster which was not created by eksctl, a config file containing VPC details must be provided. At a minimum:

(機械翻訳:これは、eksctl によって作成されたのではないクラスター上にノードグループまたは管理対象ノードグループを作成するには、VPC の詳細を含む構成ファイルを提供する必要があることを意味します。最低でも:)

https://eksctl.io/usage/unowned-clusters/#creating-nodegroups

ということで、以下の設定ファイルを作成しました。

---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: cluster
  region: ap-northeast-1

vpc:
  id: "vpc-xxx"
  securityGroup: "sg-xxx"
    public:
      public1:
          id: "subnet-xxx"
      public2:
          id: "subnet-xxx"

nodeGroups:
  - name: self-node
    instanceType: t3.medium
    minSize: 1
    maxSize: 1
    ssh:
      allow: true
      publicKeyName: xxx

上記設定ファイルを利用して、セルフマネージドノードを作成します。

$ eksctl create nodegroup -f self-nodegroup.yml
2023-02-26 10:43:51 [ℹ]  will use version 1.24 for new nodegroup(s) based on control plane version
2023-02-26 10:43:51 [!]  no eksctl-managed CloudFormation stacks found for "cluster", will attempt to create nodegroup(s) on non eksctl-managed cluster
2023-02-26 10:43:53 [ℹ]  nodegroup "self-node" will use "ami-003969234aca764d1" [AmazonLinux2/1.24]
2023-02-26 10:43:53 [ℹ]  using EC2 key pair "xxx"
2023-02-26 10:43:54 [ℹ]  1 nodegroup (self-node) was included (based on the include/exclude rules)
2023-02-26 10:43:54 [ℹ]  will create a CloudFormation stack for each of 1 nodegroups in cluster "cluster"
2023-02-26 10:43:54 [ℹ]  1 task: { 1 task: { 1 task: { create nodegroup "self-node" } } }
2023-02-26 10:43:54 [ℹ]  building nodegroup stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:43:54 [ℹ]  deploying stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:43:54 [ℹ]  waiting for CloudFormation stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:44:24 [ℹ]  waiting for CloudFormation stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:45:02 [ℹ]  waiting for CloudFormation stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:46:38 [ℹ]  waiting for CloudFormation stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:48:01 [ℹ]  waiting for CloudFormation stack "eksctl-cluster-nodegroup-self-node"
2023-02-26 10:48:01 [ℹ]  no tasks
2023-02-26 10:48:01 [ℹ]  adding identity "arn:aws:iam::xxx:role/eksctl-cluster-nodegroup-self-nod-NodeInstanceRole-ZPY8K8DMR4ZV" to auth ConfigMap
2023-02-26 10:48:01 [ℹ]  nodegroup "self-node" has 0 node(s)
2023-02-26 10:48:01 [ℹ]  waiting for at least 1 node(s) to become ready in "self-node"
2023-02-26 10:48:41 [ℹ]  nodegroup "self-node" has 1 node(s)
2023-02-26 10:48:41 [ℹ]  node "ip-172-31-30-150.ap-northeast-1.compute.internal" is ready
2023-02-26 10:48:41 [✔]  created 1 nodegroup(s) in cluster "cluster"
2023-02-26 10:48:41 [✔]  created 0 managed nodegroup(s) in cluster "cluster"
2023-02-26 10:48:41 [ℹ]  checking security group configuration for all nodegroups
2023-02-26 10:48:41 [ℹ]  all nodegroups have up-to-date cloudformation templates

セルフマネージドノードの作成が完了しました。
コンソールでも確認ができました(マネージドノードグループにより作成されていませんので、ノードグループには表示されていません。)。

eksctl により作成した主なリソースは以下です。

  • AutoScaling グループ
  • 起動テンプレート
  • セキュリティグループ
  • IAM ロール

上記起動テンプレートを利用した AutoScaling グループでインスタンスが起動され、ユーザーデータに EKS クラスターに登録するための処理を行なっています。

マネージドノードグループも同じようなことを行なっていますが、違いはマネージドノードグループは EKS により AutoScaling グループなどの作成・管理が行われることです。

ユーザーデータの内容を確認しようと起動テンプレートや EC2 インスタンスのコンソールから確認しましたが、暗号化された後の文字列なのか base64 ではデコードできませんでした。EC2 に SSH 接続して確認しましたが、/var/lib/cloud/instance/user-data.txt の内容も同様であり、分かりませんでした。

ただ /var/log/cloud-init-output.log には以下のログがあったため、bootstrap.sh を実行していることはわかりました。

eksctl: running /etc/eks/bootstrap
$ ls -al /etc/eks/
合計 68
drwxr-xr-x  5 root root   226  2月 17 21:59 .
drwxr-xr-x 83 root root  8192  2月 26 01:47 ..
-rwxr-xr-x  1 root root 23162  2月 17 21:54 bootstrap.sh
drwxr-xr-x  2 root root   192  2月 26 01:47 containerd
drwxr-xr-x  2 root root    75  2月 17 21:58 ecr-credential-provider
-rw-r--r--  1 root root 11292  2月 17 21:54 eni-max-pods.txt
-rwxr-xr-x  1 root root  1165  2月 17 21:54 get-ecr-uri.sh
-rw-r--r--  1 root root   306  2月 17 21:54 iptables-restore.service
drwxr-xr-x  2 root root    34  2月 17 21:59 log-collector-script
-rwxr-xr-x  1 root root  5147  2月 17 21:54 max-pods-calculator.sh
-rw-rw-r--  1 root root   137  2月 17 21:59 release

bootstrap.sh の全ての内容を確認していませんが、eksctl 側でよしなに EKS クラスターに登録するための処理を行なっているのでしょう。

おそらく以下と同様の内容と思われます。

amazon-eks-ami/bootstrap.sh at master · awslabs/amazon-eks-ami
Packer configuration for building a custom EKS AMI - amazon-eks-ami/bootstrap.sh at master · awslabs/amazon-eks-ami

kubectl が EKS クラスターを接続できることを確認します。

$ aws eks update-kubeconfig --name cluster
Added new context arn:aws:eks:ap-northeast-1:xxx:cluster/cluster to /Users/xxx/.kube/config
$ kubectl get pod -n kube-system -o=wide
NAME                       READY   STATUS    RESTARTS   AGE    IP              NODE                                               NOMINATED NODE   READINESS GATES
aws-node-w7wrg             1/1     Running   0          57m    172.31.30.150   ip-172-31-30-150.ap-northeast-1.compute.internal   <none>           <none>
coredns-5fc8d4cdcf-bltzc   1/1     Running   0          131m   172.31.21.70    ip-172-31-30-150.ap-northeast-1.compute.internal   <none>           <none>
coredns-5fc8d4cdcf-ww7cz   1/1     Running   0          131m   172.31.29.101   ip-172-31-30-150.ap-northeast-1.compute.internal   <none>           <none>
kube-proxy-d4cs9           1/1     Running   0          57m    172.31.30.150   ip-172-31-30-150.ap-northeast-1.compute.internal   <none>           <none>

確認ができたので、セルフマネージドノードを削除します。

$ eksctl delete nodegroup --cluster cluster --name self-node
タイトルとURLをコピーしました