|
| 1 | +# 1.2 Configuring an EKS Cluster |
| 2 | + |
| 3 | +- Create the EKS service role |
| 4 | +- Create the VPC infrastructure using CloudFormation |
| 5 | +- Create a cluster in the AWS Management Console |
| 6 | +- Configure kubectl for EKS |
| 7 | +- Configure aws-iam-authenticator |
| 8 | +- Launch EKS worker nodes |
| 9 | +- Deploy the Kubernetes dashboard |
| 10 | + |
| 11 | +## Amazon EKS Prerequisites |
| 12 | + |
| 13 | +Before you can create an Amazon EKS cluster, you must create an IAM role that Kubernetes can assume to create AWS resources. For example, when a load balancer is created, Kubernetes assumes the role to create an Elastic Load Balancing load balancer in your account. This only needs to be done one time and can be used for multiple EKS clusters. |
| 14 | + |
| 15 | +You must also create a VPC and a security group for your cluster to use. Although the VPC and security groups can be used for multiple EKS clusters, we recommend that you use a separate VPC for each EKS cluster to provide better network isolation. |
| 16 | + |
| 17 | +## Create EKS Service Role |
| 18 | + |
| 19 | +### Create the EKS service role in the IAM console |
| 20 | + |
| 21 | +1. Open the IAM console at [https://console\.aws\.amazon\.com/iam/](https://console.aws.amazon.com/iam/)\. |
| 22 | + |
| 23 | +1. Choose **Roles**, then **Create role**\. |
| 24 | + |
| 25 | +1. Choose **EKS** from the list of services, then **Allows Amazon EKS to manage your clusters on your behalf** for your use case, then **Next: Permissions**\. |
| 26 | + |
| 27 | +1. Choose **Next: Review**\. |
| 28 | + |
| 29 | +1. For **Role name**, enter a unique name for your role, such as `eksServiceRole`, then choose **Create role**\. |
| 30 | + |
| 31 | +## Create EKS Cluster VPC |
| 32 | + |
| 33 | +Specify this S3 template URL in CloudFormation: |
| 34 | + |
| 35 | +`https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-11-07/amazon-eks-vpc-sample.yaml` |
| 36 | + |
| 37 | +This is also available from the [EKS Getting Started Guide](https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html#vpc-create) |
| 38 | + |
| 39 | +Note the `SecurityGroups`, `VpcId`, and `SubnetIds` output values. |
| 40 | + |
| 41 | +## Create EKS Cluster |
| 42 | + |
| 43 | +Use AWS Management Console, supplying values from the CloudFormation output in the previous step. |
| 44 | + |
| 45 | +The Security group should be the one containing `ControlPlaneSecurityGroup` in the name. |
| 46 | + |
| 47 | +**Note:** Be sure to create the EKS Cluster using the same IAM user or role that you intend to manage that cluster with from the CLI. |
| 48 | + |
| 49 | +This step can take several minutes to complete. |
| 50 | + |
| 51 | +## Install kubectl |
| 52 | + |
| 53 | +For example, to install version 1.10.3 on macOS: |
| 54 | + |
| 55 | +```sh |
| 56 | +curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/darwin/amd64/kubectl |
| 57 | + |
| 58 | +chmod +x ./kubectl |
| 59 | +``` |
| 60 | + |
| 61 | +Ensure that `kubectl` is in your `PATH`. |
| 62 | + |
| 63 | +To install on Amazon Linux: |
| 64 | + |
| 65 | +```bash |
| 66 | +curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/kubectl |
| 67 | + |
| 68 | +chmod +x ./kubectl |
| 69 | + |
| 70 | + |
| 71 | +mkdir $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH |
| 72 | + |
| 73 | +echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc |
| 74 | +``` |
| 75 | + |
| 76 | +## Install aws-iam-authenticator |
| 77 | + |
| 78 | +For example, to install version 1.10.3 for macOS: |
| 79 | + |
| 80 | +```sh |
| 81 | +curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/darwin/amd64/aws-iam-authenticator |
| 82 | + |
| 83 | +chmod +x ./aws-iam-authenticator |
| 84 | +``` |
| 85 | + |
| 86 | +Ensure that `aws-iam-authenticator` is in your `PATH`. |
| 87 | + |
| 88 | +## Configure kubectl |
| 89 | + |
| 90 | +`aws eks update-kubeconfig --name <cluster name>` |
| 91 | + |
| 92 | +## Launch Worker Nodes |
| 93 | + |
| 94 | +Wait for the cluster status to show `ACTIVE`. |
| 95 | + |
| 96 | +Create the following CloudFormation stack using this S3 URL: |
| 97 | + |
| 98 | +`https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-11-07/amazon-eks-nodegroup.yaml` |
| 99 | + |
| 100 | +Specify the Amazon EKS-optimized AMI ID for your region: |
| 101 | + |
| 102 | +|Region|Amazon EKS-optimized AMI| |
| 103 | +|------|------------------------| |
| 104 | +|US West (Oregon) (us-west-2)|ami-0f54a2f7d2e9c88b3| |
| 105 | +|US East (N. Virginia)(us-east-1)|ami-0a0b913ef3249b655| |
| 106 | +|US East (Ohio)(us-east-2)|ami-0958a76db2d150238| |
| 107 | +|EU (Ireland)(eu-west-1)|ami-00c3b2d35bddd4f5c| |
| 108 | + |
| 109 | +## Enable Worker Nodes to Join Cluster |
| 110 | + |
| 111 | +Download the configuration map: |
| 112 | + |
| 113 | +`curl -O https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-11-07/aws-auth-cm.yaml` |
| 114 | + |
| 115 | +Edit this file, replacing the `<ARN of instance role (not instance profile)> ` snippet with the `NodeInstanceRole` value that you recorded in the previous procedure, and save the file. |
| 116 | + |
| 117 | +Apply the configuration. |
| 118 | + |
| 119 | +`kubectl apply -f aws-auth-cm.yaml` |
| 120 | + |
| 121 | +`kubectl get nodes --watch` |
| 122 | + |
| 123 | +## Deploy the Kubernetes Dashboard |
| 124 | + |
| 125 | +`kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml` |
| 126 | + |
| 127 | +`kubectl proxy &` |
| 128 | + |
| 129 | +Browse to: <http://localhost:8080/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/> |
| 130 | + |
| 131 | +## Get an authentication token |
| 132 | + |
| 133 | +`aws-iam-authenticator token -i <cluster_name> --token-only` |
| 134 | + |
| 135 | +Set this token in the k8s dashboard. |
0 commit comments