ユーザ用ツール

サイト用ツール


aws:eks:eksctl

eksctlでのEKS構築する手順


関連ページ
AWS EKSで、Kubernetes(k8s)を利用



eksctlコマンドとは

eksctlコマンドは、EKSを構築する専用のCLIです。

eksctlコマンドを使うことにより、関連するVPCやポリシーなどのリソースも自動で作成してくれますので、
簡単にEKSクラスターを作成できます。


準備

eksctlコマンドを利用する場合、AWS CLIとkubectlコマンドもインストールされている必要があります。

AWS CLI

AWS CLIのバージョン確認
# aws --version
aws-cli/2.1.4

参考:AWS CLIの使い方

AWS CLIの認証情報の設定
# aws configure
AWS Access Key ID [None]: *************
AWS Secret Access Key [None]: *************
Default region name [None]: ap-northeast-1   #東京リージョンの場合


eksctlのインストール

# curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
# mv /tmp/eksctl /usr/local/bin
# eksctl version
0.31.0
確認コマンド
$ eksctl get cluster
NAME            REGION
eks-sample      ap-northeast-1


kubectlのインストール

# curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.8/2020-09-18/bin/linux/amd64/kubectl
# mv ./kubectl /usr/local/bin
# chmod +x /usr/local/bin/kubectl
# kubectl version --short --client
Client Version: v1.18.8-eks-7c9bda


kubeconfig(kubectl 接続設定ファイル)を作成
$ aws eks --region リージョン update-kubeconfig --name クラスター名

$ cat ~/.kube/config   #作成されたファイルの確認
確認コマンド
kubectl get svc

kubectl get nodes
kubectl get nodes -o wide

kubectl get pod -o wide

kubectl get service


EKSクラスターの作成

  • EKSクラスターの構築が完了するまで、10~20分程度の時間がかかります。
ヘルプ
eksctl create cluster --help
  • VPCネットワークを事前にTeraformなどで作る場合は、eksctl create clusterコマンドに--without-nodegroupオプションを付けて実行する
  • ワーカーノードのみを作る場合は、eksctl create nodegroup
既存のサブネットを利用する場合
      --vpc-private-subnets=subnet-xxxxxxxx,subnet-xxxxxxxx \
      --vpc-public-subnets=subnet-xxxxxxxx,subnet-xxxxxxxx \


EKSクラスター作成例
eksctl create cluster  \
  --name=test-cluster \      #クラスタ名
  --region=ap-northeast-1 \  #リージョン
  --version=1.18 \           #バージョン
  --node-type=t3.medium \    #Workerインスタンスタイプ
  --nodes=2 \                #Workerノード数
  --nodes-min=2 \            #Workerオートスケール最小
  --nodes-max=2 \            #Workerオートスケール最大
  --node-volume-size=20      #Workerディスクサイズ
$ eksctl create cluster \
    --vpc-cidr 10.0.0.0/16 \
    --vpc-nat-mode HighlyAvailable \
    --name eks-sample \
    --version 1.14 \
    --nodegroup-name ng-sample \
    --node-type t3.large \
    --nodes 3 \
    --nodes-min 2 \
    --nodes-max 4

https://dev.classmethod.jp/articles/getting-started-amazon-eks-with-eksctl/

$ eksctl create cluster \
      --vpc-cidr 10.0.0.0/16 \
      --name eks-sample \
      --region ap-northeast-1 \
      --version 1.14 \
      --nodegroup-name sample-workers \
      --node-type t2.small \
      --nodes 1 \
      --nodes-min 1 \
      --nodes-max 3 \
      --managed
eksctl create cluster \
  --name eks-sample \
  --version 1.14 \
  --region ap-northeast-1 \
  --zones ap-northeast-1a,ap-northeast-1c,ap-northeast-1d \
  --nodegroup-name eks-sample-node \
  --node-type m5.large \
  --nodes 3 \
  --nodes-min 3 \
  --nodes-max 4 \
  --alb-ingress-access \
  --asg-access

https://qiita.com/purini-to/items/89cf41ed6ac02c1114bc

https://kun432.hatenablog.com/entry/what-aws-resources-eksctl-create

$ eksctl create cluster \
--name eks-test \
--vpc-public-subnets $PUBSUBNET1,$PUBSUBNET2  \
--vpc-private-subnets $PRVSUBNET1,$PRVSUBNET2 \
--region ap-northeast-1 \
--version 1.17 \
--nodegroup-name eks-nodegroup \
--node-private-networking \
--ssh-access \
--node-type t2.small \
--nodes 2 \
--nodes-min 2 \
--nodes-max 5 \
--ssh-public-key=xxx_key


作成されたEKSクラスタの確認

https://tech.smartcamp.co.jp/entry/eksctl-handson

$ eksctl get cluster
NAME            REGION
eks-sample      ap-northeast-1
$ kubectl get service
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   10h

$ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   172.20.0.1   <none>        443/TCP   10m
$ kubectl get nodes
NAME                                            STATUS   ROLES    AGE    VERSION
ip-10-0-0-130.ap-northeast-1.compute.internal   Ready    <none>   5m   v1.14.7-eks-1861c5


eksctlで作成されるリソース

ENI

  • クラスターの作成により、クラスターVPC内にコントロールプレーンと通信するためのENIが作成され、Kubernetesのコントロールプレーンと通信可能となる


IAMロール

eksctlで以下のIAMロールが作成されます

cluster-ServiceRole
  • KubernetesクラスタのコントロールプレーンがAWSリソースを操作するためのポリシー
  • EC2のオートスケーリングやELBの操作を行うためのもの
nodegroup-ek-NodeInstanceRole
  • EC2の情報を参照したり、ENI周りの操作を行ったり、ECRにアクセスしたりするための権限です。
  • worker ndoeにも紐付いてる


セキュリティグループ

eks-cluster-sg-xxxxx
  • 同じセキュリティグループ内、および、ClusterSharedNodeSecurityGroupからの通信をすべて許可
  • クラスタ内通信を全許可
  • worker nodeのec2にアタッチ
ClusterSharedNodeSecurityGroup
  • 同じセキュリティグループ内、および、eks-cluster-sg-xxxxxからの通信をすべて許可
ControlPlaneSecurityGroup
  • コントロールプレーン向けのセキュリティグループ
eksctl-xxxxx-nodegroup-eks-nodegroup-remoteAccess
  • %–ssh-access%%オプション
  • VPC内のどこからもworker nodeにsshできる
  • worker nodeのec2にアタッチ


EKS k8sクラスタ削除

eksctl delete cluster --name クラスタ名
$ eksctl delete cluster \
     --name eks-sample \
     --wait


EKSクラスターの設定をyamlで管理(manifest)

https://qiita.com/purini-to/items/89cf41ed6ac02c1114bc

eksctl create cluster -f <yaml file>

cluster.yaml

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: eks-sample
  region: ap-northeast-1

# yamlならコメントも記載できます。
# MultiAZ
availabilityZones: ["ap-northeast-1a", "ap-northeast-1c", "ap-northeast-1d"]

nodeGroups:
  - name: eks-sample-node
    instanceType: m5.large
    # 3AZ保つための最低数
    desiredCapacity: 3
    minSize: 3
    maxSize: 10
    iam:
      withAddonPolicies:
        autoScaler: true
        albIngress: true
eksctl create cluster -f cluster.yaml


既存に追加したい場合

cluster.yml

nodeGroups:
  - name: eks-sample-node
    .....

  # プライベートネットワークにノードグループを作成
  - name: eks-sample-private-node
    instanceType: m5.large
    desiredCapacity: 3
    minSize: 3
    maxSize: 10
    privateNetworking: true
eksctl create nodegroup --config-file=cluster.yaml --include='eks-sample-private-node'

manifestの例

https://kun432.hatenablog.com/entry/what-aws-resources-eksctl-create

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: eks-test
  region: ap-northeast-1
  version: "1.17"

vpc:
  id: "vpc-0dd338ecf29863c55"
  cidr: "10.0.0.0/16"
  subnets:
    private:
      ap-northeast-1c:
        id: "subnet-aaaaaaaaaaaaaaaa"
        cidr: "10.0.0.0/24"
      ap-northeast-1d:
        id: "subnet-bbbbbbbbbbbbbbbb"
        cidr: "10.0.1.0/24"
    public:
      ap-northeast-1c:
        id: "subnet-cccccccccccccccc"
        cidr: "10.0.2.0/24"
      ap-northeast-1d:
        id: "subnet-dddddddddddddddd"
        cidr: "10.0.3.0/24"

managedNodeGroups:
  - name: eks-ng-blue
    instanceType: t2.small
    desiredCapacity: 2
    minSize: 2
    maxSize: 5
    privateNetworking: true
    ssh:
      publicKeyName: xxx_key
      allow: true
    labels: {role: worker}
    tags:
      nodegroup-role: worker


関連ページ
AWS EKSで、Kubernetes(k8s)を利用

aws/eks/eksctl.txt · 最終更新: 2021/08/16 19:25 by kurihara

ページ用ツール