目次
- 事前準備
- AWS CLI インストール
- kubectl インストール
- heptio-authenticator-aws インストール
- EKS利用のための前提条件
- サービスロール作成
- VPC作成
- EKSクラスター作成
環境
クライアントマシン:Mac
事前準備
AWS CLI インストール
$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
$ python get-pip.py
$ pip install awscli
$ aws --version
kubectlインストール
Docker for Macのedgeバージョンをインストールし、Kubernetesを有効にする。
heptio-authenticator-aws インストール
kubectl実行時のEKS認証のために必要となる「heptio-authenticator-aws」をインストールする。
$ curl -o heptio-authenticator-aws https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/darwin/amd64/heptio-authenticator-aws
$ chmod +x ./heptio-authenticator-aws
$ mv ./heptio-authenticator-aws $HOME/bin/heptio-authenticator-aws && export PATH=$HOME/bin:$PATH
$ heptio-authenticator-aws help
EKS利用のための前提条件
サービスロール作成
VPC作成
IAMポリシーの作成
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"eks:*",
"iam:PassRole" ※この設定も必要と思われる。
],
"Resource": "*"
}
]
}
EKSクラスター作成
事前準備
aws configure コマンドで接続情報を設定しておくこと。
EKSを利用できるリージョンは以下。(2018/7/10時点)
- 米国西部 (オレゴン) (us-west-2)
- 米国東部 (バージニア北部) (us-east-1)
クラスターの作成
以下のコマンドでクラスターを作成する。
以降の手順では、クラスター名は「eks-cluster-sample-1」とする。
$ aws eks create-cluster \
--name <クラスタ名(eks-cluster-sample-1)> \
--role-arn <作成したサービスロールのARN> \
--resources-vpc-config \
subnetIds=<作成したVPCより>,<作成したVPCより>,securityGroupIds=<作成したVPCより>
{
"cluster": {
"name": "eks-cluster-sample-1",
"arn": "arn:aws:eks:us-west-2:************:cluster/eks-cluster-sample-1",
"createdAt": **********.***,
"version": "1.10",
"roleArn": "arn:aws:iam::************:role/**************",
"resourcesVpcConfig": {
"subnetIds": [
"subnet-********",
"subnet-********"
],
"securityGroupIds": [
"sg-********"
],
"vpcId": "vpc-********"
},
"status": "CREATING",
"certificateAuthority": {}
}
}
以下のコマンドでクラスター状態を確認する。
$ aws eks describe-cluster --name eks-cluster-sample-1 --query cluster.status
"ACTIVE"
EKSクラスターの情報取得
kubectlで作成したクラスターと通信できるように、endpoint および certificateAuthority.data を取得する。
以下のコマンドでendopointを取得する。
$ aws eks describe-cluster --name eks-cluster-sample-1 --query cluster.endpoint
以下のコマンドでcertificateAuthority.dataを取得する。
$ aws eks describe-cluster --name eks-cluster-sample-1 --query cluster.certificateAuthority.data
kubectlの設定
$ cd ~/.kube
$ vi config_eks-cluster-sample-1
以下を設定。
apiVersion: v1
clusters:
- cluster:
server: <endpoint-url>
certificate-authority-data: <base64-encoded-ca-cert>
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: aws
name: aws
current-context: aws
kind: Config
preferences: {}
users:
- name: aws
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
command: heptio-authenticator-aws
args:
- "token"
- "-i"
- "<cluster-name>"
# - "-r"
# - "<role-arn>"
作成したkubectlの定義を設定する。
$ export KUBECONFIG=$KUBECONFIG:~/.kube/config_eks-cluster-sample-1
EKSにアクセス確認をする。
$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 53m