Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Latest commit

 

History

History
225 lines (131 loc) · 5.73 KB

create-eks-with-eksctl.md

File metadata and controls

225 lines (131 loc) · 5.73 KB

Create your EKS Cluster with eksctl

eksctl is a CLI for Amazon EKS that helps you easily create Amazon EKS cluster!

eksctl website: https://eksctl.io/

You may follow the Amazon EKS official document - Getting Started with eksctl to complete the cluster creation with eksctl or just follow the steps below.

Steps

  1. Spin up your Cloud9 IDE from AWS console.

0-c9-0

  1. Create and name your environment

0-c9-0

  1. Leave everythong as default and click Next Step
  2. Click Create environment

(It would typically take 30-60s to create your Cloud9 IDE)

0-c9-0

  1. install the latest aws-cli

copy and paste the following script in the Cloud9 terminal and press enter.

cat << EOF | bash
cleanup() {
  rm -rf awscli-bundle
  rm -f awscli-bundle.zip
}


cleanup
rm -rf awscli-bundle*
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
EOF

check the awscli path and version

# check the path
$ which aws
/usr/local/bin/aws
# check the version
$ aws --version
aws-cli/1.16.184 Python/2.7.16 Linux/4.14.109-80.92.amzn1.x86_64 botocore/1.12.174

(make suer your version >= 1.16.184)

  1. We need to turn off the Cloud9 temporarily provided IAM credentials.

0-c9-0

  1. When you turn off the temporary credentials, you should not be able to un AWS CLI now.

0-c9-0

  1. execute aws configure to configure the credentials for your IAM user. Make sure this IAM User has AdministratorAccess and run aws sts get-caller-identity - you should be able to see the returned JSON output like this.

0-c9-0

  1. Download the kubectl and save to ~/bin. Check the Amazon EKS User Guide for Installing kubectl.
$ curl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl -o kubectl
$ chmod +x $_
$ sudo mv $_ /usr/local/bin/
  1. Download the eksctl from eksctl.io(actually it will download from GitHub)
$ curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
  1. run eksctl help, you should be able to see the help messages

0-c9-0

create cluster with eksctl

  1. Create your Amazon EKS cluster witn eksctl and spin up a nodegroup with 2 nodes
$ eksctl create cluster --name=<CLUSTER_NAME> --nodes 2 --auto-kubeconfig --ssh-public-key <EXISTING_SSH_KEY_NAME>

0-c9-0

Or like this

eksctl create cluster \
  --name=eksdemo \
  --region=us-west-2 \
  --nodes=2 \
  --tags environment=develop \
  --node-type=m5.large \
  --ssh-access \
  --ssh-public-key=your_key_name \
  --node-private-networking \
  --vpc-private-subnets=subnet-ed2b93c3,subnet-e6c38eac \
  --vpc-public-subnets=subnet-36368e18,subnet-aec68be4

Alternatively, you may also create your cluster with cluster config file.

cat << EOF > cluster.yaml
apiVersion: eksctl.io/v1alpha4
kind: ClusterConfig

metadata:
  name: eksdemo
  region: us-west-2

nodeGroups:
  - name: ng0
    instanceType: m5.large
    desiredCapacity: 2
EOF

And then, just

eksctl create cluster -f cluster.yaml

Nodegroup of Mixed Instance Types and Purchase Options

If you prefer to hybrid on-demand and spot instances with mixed instance types in your nodegroup, you may also create your nodegroup like this:

---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
    name: eksdemo
    region: ap-northeast-1

nodeGroups:
    - name: ng-1
      minSize: 2
      maxSize: 5
      instancesDistribution:
        instanceTypes: ["t3.small", "t3.medium", "t3.large"] # At least two instance types should be specified
        onDemandBaseCapacity: 0
        onDemandPercentageAboveBaseCapacity: 0
        spotInstancePools: 2

save the YAML body as mixed-ng.yaml and create your cluster

$ eksctl create cluster -f mixed-ng.yaml

This will spin up an Amazon EKS cluster with nodegroup of mixed instance types and purchase options(ondemand+spot), however, as we define onDemandBaseCapacity: 0 and onDemandPercentageAboveBaseCapacity: 0, actually there will be only spot instances for the best cost optimization. You may configure those options to optionally have some ondemand instances as your baseline. Check AWS document for more details about those attributes.

More cluster config samples from eksctl github

Generate kubeconfig with aws eks update-kubeconfig

And create/update your $HOME/.kube/config with aws eks update-kubeconfig

aws eks update-kubeconfig --name eksdemo

After executing aws eks update-kubeconfig, a new context will be generated in $HOME/.kube/config and you can execute kubectl get no to list all nodes in the nodegroup.

0-c9-0

Get the cluster-info or get all resources.

0-c9-0

Now your Amazon EKS cluster is ready! You may proceed to customize your nodegroup now.

If you need to delete this clusrer, run eksctl delete cluster —name=<CLUSTER_NAME> to trigger the deletion of the stack.