|
| 1 | +# Getting Started with EKS |
| 2 | + |
| 3 | +## Amazon CLI |
| 4 | + |
| 5 | +``` |
| 6 | +
|
| 7 | +# Run Amazon CLI |
| 8 | +docker run -it --rm -v ${PWD}:/work -w /work --entrypoint /bin/sh amazon/aws-cli:2.0.17 |
| 9 | +
|
| 10 | +cd ./kubernetes/cloud/amazon |
| 11 | +
|
| 12 | +yum install jq |
| 13 | +``` |
| 14 | + |
| 15 | +## Login to AWS |
| 16 | + |
| 17 | +https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html |
| 18 | + |
| 19 | +``` |
| 20 | +# Access your "My Security Credentials" section in your profile. |
| 21 | +# Create an access key |
| 22 | +
|
| 23 | +aws configure |
| 24 | +
|
| 25 | +# Regions |
| 26 | +https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html |
| 27 | +
|
| 28 | +``` |
| 29 | + |
| 30 | + |
| 31 | +# Deploy Cluster with AWS CLI |
| 32 | + |
| 33 | +You can deploy a cluster using multiple ways. </br> |
| 34 | +We will cover the two fundamental ways. |
| 35 | + |
| 36 | +1) AWS CLI https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html |
| 37 | +2) EKS CLI (newer) https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html |
| 38 | + |
| 39 | + |
| 40 | +## AWS CLI |
| 41 | + |
| 42 | +Kubernetes needs a service account to manage our Kubernetes cluster <br/> |
| 43 | +In AWS this is an IAM role <br/> |
| 44 | +Lets create one! <br/> |
| 45 | + |
| 46 | +Follow "Create your Amazon EKS cluster IAM role" [here](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-console.html) <br/> |
| 47 | + |
| 48 | +``` |
| 49 | +
|
| 50 | +# create our role for EKS |
| 51 | +role_arn=$(aws iam create-role --role-name getting-started-eks-role --assume-role-policy-document file://assume-policy.json | jq .Role.Arn | sed s/\"//g) |
| 52 | +aws iam attach-role-policy --role-name getting-started-eks-role --policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy |
| 53 | +
|
| 54 | +# create the cluster VPC |
| 55 | +
|
| 56 | +curl https://amazon-eks.s3.us-west-2.amazonaws.com/cloudformation/2020-05-08/amazon-eks-vpc-sample.yaml -o vpc.yaml |
| 57 | +aws cloudformation deploy --template-file vpc.yaml --stack-name getting-started-eks |
| 58 | +
|
| 59 | +# grab your stack details |
| 60 | +aws cloudformation list-stack-resources --stack-name getting-started-eks > stack.json |
| 61 | +
|
| 62 | +# create our cluster |
| 63 | +
|
| 64 | +aws eks create-cluster \ |
| 65 | +--name getting-started-eks \ |
| 66 | +--role-arn $role_arn \ |
| 67 | +--resources-vpc-config subnetIds=subnet-063efe1fa0c5d4913,subnet-06f91e563755e2077,subnet-0824d16f8536b3681,securityGroupIds=sg-0960d3a116ba912e1,endpointPublicAccess=true,endpointPrivateAccess=false |
| 68 | +
|
| 69 | +aws eks list-clusters |
| 70 | +aws eks describe-cluster --name getting-started-eks |
| 71 | +``` |
| 72 | + |
| 73 | + |
| 74 | +## Get a kubeconfig for our cluster |
| 75 | + |
| 76 | +``` |
| 77 | +
|
| 78 | +aws eks update-kubeconfig --name getting-started-eks --region ap-southeast-2 |
| 79 | +
|
| 80 | +#grab the config if you want it |
| 81 | +cp ~/.kube/config . |
| 82 | +
|
| 83 | +curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl |
| 84 | +chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl |
| 85 | +
|
| 86 | +``` |
| 87 | + |
| 88 | +## Add nodes to our cluster |
| 89 | + |
| 90 | +``` |
| 91 | +
|
| 92 | +# create our role for nodes |
| 93 | +role_arn=$(aws iam create-role --role-name getting-started-eks-role-nodes --assume-role-policy-document file://assume-node-policy.json | jq .Role.Arn | sed s/\"//g) |
| 94 | +
|
| 95 | +aws iam attach-role-policy --role-name getting-started-eks-role-nodes --policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy |
| 96 | +aws iam attach-role-policy --role-name getting-started-eks-role-nodes --policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy |
| 97 | +aws iam attach-role-policy --role-name getting-started-eks-role-nodes --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly |
| 98 | +
|
| 99 | +``` |
| 100 | +More details on node permissions [here](https://docs.aws.amazon.com/eks/latest/userguide/worker_node_IAM_role.html) |
| 101 | + |
| 102 | + |
| 103 | +More details on instance types to choose from [here](https://aws.amazon.com/ec2/instance-types/) |
| 104 | + |
| 105 | +``` |
| 106 | +aws eks create-nodegroup \ |
| 107 | +--cluster-name getting-started-eks \ |
| 108 | +--nodegroup-name test \ |
| 109 | +--node-role $role_arn \ |
| 110 | +--subnets subnet-0ec47e6ae964a233f \ |
| 111 | +--disk-size 200 \ |
| 112 | +--scaling-config minSize=1,maxSize=2,desiredSize=1 \ |
| 113 | +--instance-types t2.small |
| 114 | +``` |
| 115 | + |
| 116 | +## EKS CTL example |
| 117 | + |
| 118 | +``` |
| 119 | +eksctl create cluster --name getting-started-eks-1 \ |
| 120 | +--region ap-southeast-2 \ |
| 121 | +--version 1.16 \ |
| 122 | +--managed \ |
| 123 | +--node-type t2.small \ |
| 124 | +--nodes 1 \ |
| 125 | +--node-volume-size 200 |
| 126 | +
|
| 127 | +``` |
| 128 | +## Create some sample containers |
| 129 | + |
| 130 | +``` |
| 131 | +cd ../.. |
| 132 | +
|
| 133 | +kubectl create ns example-app |
| 134 | +
|
| 135 | +# lets create some resources. |
| 136 | +kubectl apply -n example-app -f secrets/secret.yaml |
| 137 | +kubectl apply -n example-app -f configmaps/configmap.yaml |
| 138 | +kubectl apply -n example-app -f deployments/deployment.yaml |
| 139 | +
|
| 140 | +# remember to change the `type: LoadBalancer` |
| 141 | +kubectl apply -n example-app -f services/service.yaml |
| 142 | +
|
| 143 | +``` |
| 144 | +## Cleanup |
| 145 | + |
| 146 | +``` |
| 147 | +
|
| 148 | +eksctl delete cluster --name getting-started-eks-1 |
| 149 | +
|
| 150 | +aws eks delete-nodegroup --cluster-name getting-started-eks --nodegroup-name test |
| 151 | +aws eks delete-cluster --name getting-started-eks |
| 152 | +
|
| 153 | +aws iam detach-role-policy --role-name getting-started-eks-role --policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy |
| 154 | +aws iam delete-role --role-name getting-started-eks-role |
| 155 | +
|
| 156 | +aws iam detach-role-policy --role-name getting-started-eks-role-nodes --policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy |
| 157 | +aws iam detach-role-policy --role-name getting-started-eks-role-nodes --policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy |
| 158 | +aws iam detach-role-policy --role-name getting-started-eks-role-nodes --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly |
| 159 | +
|
| 160 | +aws iam delete-role --role-name getting-started-eks-role-nodes |
| 161 | +
|
| 162 | +aws cloudformation delete-stack --stack-name getting-started-eks |
| 163 | +``` |
0 commit comments