EKS will setup and manage our Kubernetes clusters:
In short, you will get an EKS control plane and you'll just need to setup the worker nodes in the availability zones.
The from the laptop, you can use kubectl to talk to AWS.
There is also deep integration with AWS:
kubectl
properlyeksctl
CLIEKS Architecture
EKS itself will manage all the load and master nodes and etcd as needed.
Basic setup
To be able to run through this course your IAM user needs to have certain privileges to e.g. create all the required resources and objects. According AWS Best Practices you should never use your root account for working with AWS services. E.g. to demonstrate the Hands-On lectures, the user eks-course has been used.
There are 2 attempts to follow:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["eks:*"], "Resource": "*" } ] }
CloudFormation-Admin-policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["cloudformation:*"], "Resource": "*" } ] }
Finally, assign the following policies to your IAM user you are going to use throughout the course:
https://console.aws.amazon.com/iam/
and choose Roles => create rolehttps://console.aws.amazon.com/ec2
AWS-console => IAM => Users => <your user> => tab _Security credentials_ => button _Create access key_
AWS EKS Cluster setup
To create a VPC there is a prepared CloudFormation template to use. It creates a VPC including 3 Subnets At the moment EKS is only available in the following 2 regions:
https://console.aws.amazon.com/cloudformation/
and select one of the above mentioned regionseks-course-vpc.yaml
# eks-course-vpc.yaml --- AWSTemplateFormatVersion: '2010-09-09' Description: 'AWS EKS course' Parameters: VpcBlock: Type: String Default: 192.168.0.0/16 Description: CIDR range for VPC Subnet01Block: Type: String Default: 192.168.64.0/18 Description: CIDR for first subnet within VPC Subnet02Block: Type: String Default: 192.168.128.0/18 Description: CIDR for second subnet within VPC Subnet03Block: Type: String Default: 192.168.192.0/18 Description: CIDR for third subnet within VPC Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcBlock EnableDnsSupport: true EnableDnsHostnames: true Tags: - Key: Name Value: !Sub '${AWS::StackName}-VPC' InternetGateway: Type: 'AWS::EC2::InternetGateway' VPCGatewayAttachment: Type: 'AWS::EC2::VPCGatewayAttachment' Properties: InternetGatewayId: !Ref InternetGateway VpcId: !Ref VPC RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC Tags: - Key: Name Value: Public Subnets - Key: Network Value: Public Route: DependsOn: VPCGatewayAttachment Type: AWS::EC2::Route Properties: RouteTableId: !Ref RouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway Subnet01: Type: AWS::EC2::Subnet Properties: AvailabilityZone: Fn::Select: - '0' - Fn::GetAZs: Ref: AWS::Region CidrBlock: Ref: Subnet01Block VpcId: Ref: VPC Tags: - Key: Name Value: !Sub '${AWS::StackName}-Subnet1' Subnet02: Type: AWS::EC2::Subnet Properties: AvailabilityZone: Fn::Select: - '1' - Fn::GetAZs: Ref: AWS::Region CidrBlock: Ref: Subnet02Block VpcId: Ref: VPC Tags: - Key: Name Value: !Sub '${AWS::StackName}-Subnet2' Subnet03: Type: AWS::EC2::Subnet Properties: AvailabilityZone: Fn::Select: - '2' - Fn::GetAZs: Ref: AWS::Region CidrBlock: Ref: Subnet03Block VpcId: Ref: VPC Tags: - Key: Name Value: !Sub '${AWS::StackName}-Subnet3' Subnet01RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref Subnet01 RouteTableId: !Ref RouteTable Subnet02RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref Subnet02 RouteTableId: !Ref RouteTable Subnet03RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref Subnet03 RouteTableId: !Ref RouteTable ControlPlaneSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Cluster communication with worker nodes VpcId: !Ref VPC Outputs: SubnetIds: Description: Your subnets Value: !Join [',', [!Ref Subnet01, !Ref Subnet02, !Ref Subnet03]] SecurityGroups: Description: SecGroup for communication betw controlplane and workernodes Value: !Join [',', [!Ref ControlPlaneSecurityGroup]] VpcId: Description: The VPC Id Value: !Ref VPC
aws eks create-cluster --name prod --role-arn arn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI --resources-vpc-config subnetIds=subnet-6782e71e,subnet-e7e761ac,securityGroupIds=sg-6979fe18
EKS Control Plane
Kubernetes API server is a AWS service, hence it doesn't need dedicated EC2 instances to run.
https://console.aws.amazon.com/eks/home#/clusters
and click Create Cluster.Populate the following fields:
Then for creation:
Click on your clustername, and record the API server endpoint and Certificate authority values to configure kubectl
in the next Hands-On Part IV: install & configure kubectl.
kubectl
relies on the kubectl config file
aws-iam-authenticator
executableaws credentials file
kubectl
sudo dnf install kubernetes-client
kubectl version --short --client
curl -k -# -o kubectl.exe https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/windows/amd64/kubectl.exe chmod +x kubectl.exe mkdir $HOME/bin mv kubectl.exe $HOME/bin echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc source .bashrc
kubectl.exe version --short --client
aws-iam-authenticator
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator chmod +x ./aws-iam-authenticator cp ./aws-iam-authenticator /usr/local/bin/
Test: aws-iam-authenticator help
on Windows, open a terminal emulator, preferrably MobaXterm:
curl -k -# -o aws-iam-authenticator.exe https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/windows/amd64/aws-iam-authenticator.exe chmod +x aws-iam-authenticator.exe mv aws-iam-authenticator.exe $HOME/bin
aws-iam-authenticator.exe help
aws credentials (ACCESS KEY+SECRET) now we have to provide the Access key+secret from the first lesson Part I : covering prerequisites and put them into the credentials template.
* populate aws credentials file copy the provided file named _credentials_ to * WINDOWS cygwin: ```mkdir $HOMEPATH/.aws && vi $HOMEPATH/.aws/credentials``` * Linux: ```~/.aws/credentials``` and set the properties _aws_access_key_id_ and _aws_secret_access_key_
in this step we are creating a configuration file for the binary kubectl
, which is the main tool to interact with Kubernetes later on.
Use template file kube-config-eks and copy it to:
~/.kube/kube-config-eks
mkdir $HOMEPATH/.kube && vi $HOMEPATH/.kube/kube-config-eks
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: aws-iam-authenticator args: - 'token' - '-i' - 'EKS-course-cluster'
edit file kube-config-eks
and replace endpoint-url, base64-encoded-ca-cert by the values you recorded in the Hands-On lesson 3 Part III: create the K8s control plane.
Linux : export KUBECONFIG=~/.kube/kube-config-eks
Windows : export KUBECONFIG=$HOMEPATH/.kube/kube-config-eks
Test connectivity and access:
#>kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP xxxxxxxxx <none> 443/TCP 4m
command to check the config for kubectl: kubectl config view
Now you successfully talked to the K8s control plane on AWS