How to Setup a AWS EKS Anywhere Cluster
Tags: aws, devops, kubernetes
Published: 2022-07-07 05:58:48

In this blog, you will learn what EKS anywhere is and how to set up an EKS Anywhere development cluster and register it to the AWS EKS console using the EKS connector.

## What is EKS Anywhere?

EKS Anywhere is an AWS feature to run and manage EKS clusters in on-premises environments. It simplifies the on-premise Kubernetes management and enables a consistent Kubernetes experience in a multi-cloud Kubernetes deployment. Also, you will have full control over the control plane and the worker nodes.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkzgn4f1idb2zdax2yz8.png)

EKS anywhere uses Amazon EKS Distro (EKS-D), a Kubernetes distribution customized and open-sourced by AWS. It is the same distro that powers the AWS-managed EKS. This means that when you install EKS anywhere, it comes with parameters and configurations optimized for AWS.

Also, you can register the EKS anywhere clusters to the AWS EKS console using the EKS connector.Once the cluster is registered, you can visualize all the anywhere cluster components in the AWS EKS console.

EKS connector is a Statefulset that runs the AWS System Manager Agent in your cluster. It is responsible for maintaining the connection between EKS anywhere cluster and AWS.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uew3uf3vlqrdawrm79s5.png)

Following the key use cases of EKS anywhere:

Hybrid cloud consistency: EKS anywhere enables operational consistency across your on-premise and cloud Kubernetes clusters.
Disconnected environment: You can run EKS anywhere cluster without internet connection. At the same time, your disconnected clusters will have the same features as the cloud EKS with EKS-D distro.
Application modernization: With EKS-D, the administrative overhead of patching and version upgrades are reduced. So you can focus more on the applications.

<!-- wp:heading {"textAlign":"center","canvasClassName":"cnvs-block-core-heading-1656741261591"} -->
<h2 class="has-text-align-center">EKS Anywhere Development Cluster Setup</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101441468"} -->
<p>You can setup EKS anywhere development clusters using Docker on a MAC or Ubuntu systems. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101416973"} -->
<p>Follow the steps given below to setup EKS anywhere development cluster.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1657073978572"} -->
<h3>Step 1: Install Docker Desktop  </h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657073961600"} -->
<p>Go to <a href="https://docs.docker.com/desktop/mac/install/" data-type="URL" data-id="https://docs.docker.com/desktop/mac/install/" target="_blank" rel="noreferrer noopener">Docker downloads</a> and install the Docker desktop on MAC. For Ubuntu use <a href="https://docs.docker.com/desktop/linux/install/" data-type="URL" data-id="https://docs.docker.com/desktop/linux/install/" target="_blank" rel="noreferrer noopener">this link to download the deb package</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101599007"} -->
<p>Mac users, open the following file and change <code>deprecatedCgroupv1</code> to true. And then restart Docker desktop to apply the changes.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1656743362663"} -->
<pre class="wp-block-code"><code>vi ~/Library/Group\ Containers/group.com.docker/settings.json</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1656743438278"} -->
<p>Or else you will get the following error.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1656743451056"} -->
<pre class="wp-block-code"><code>Error: failed to validate docker desktop: EKS Anywhere requires Docker desktop to be configured to use CGroups v1. Please  set `deprecatedCgroupv1:true` in your `~/Library/Group\ Containers/group.com.docker/settings.json` file</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1657073994658"} -->
<h3>Step 2: Install eksctl-anywhere</h3>
<!-- /wp:heading -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1656741250854"} -->
<pre class="wp-block-code"><code>brew install eks-anywhere</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1656744735205"} -->
<h3>Step 3: Generate the cluster configuration</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1656744736830"} -->
<p>Generete the EKS anywhere cluster configuration using the following command.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1656744759245"} -->
<pre class="wp-block-code"><code>CLUSTER_NAME=dev-eks-cluster
eksctl anywhere generate clusterconfig $CLUSTER_NAME \
   --provider docker &gt; $CLUSTER_NAME.yaml</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657074080066"} -->
<p>You cluster configuration would look like the following.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1656744767511"} -->
<pre class="wp-block-code"><code>apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: Cluster
metadata:
  name: dev-eks-cluster
spec:
  clusterNetwork:
    cniConfig:
      cilium: {}
    pods:
      cidrBlocks:
      - 192.168.0.0/16
    services:
      cidrBlocks:
      - 10.96.0.0/12
  controlPlaneConfiguration:
    count: 1
  datacenterRef:
    kind: DockerDatacenterConfig
    name: dev-eks-cluster
  externalEtcdConfiguration:
    count: 1
  kubernetesVersion: "1.22"
  managementCluster:
    name: dev-eks-cluster
  workerNodeGroupConfigurations:
  - count: 1
    name: md-0

---
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: DockerDatacenterConfig
metadata:
  name: dev-eks-cluster
spec: {}

---</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1657074114679"} -->
<h3>Step 4: Deploy the cluster</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657074190010"} -->
<p>Deploy the cluster using <code>eksctl</code>. It will take a while for the cluster to be provisioned.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1656744789289"} -->
<pre class="wp-block-code"><code>eksctl anywhere create cluster -f dev-eks-cluster.yaml</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657099930122"} -->
<p>You will get the following output after a succesful cluster deployment.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":13988,"width":566,"height":423,"sizeSlug":"full","linkDestination":"media","canvasClassName":"cnvs-block-core-image-1657099918014"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><a href="https://devopscube.com/wp-content/uploads/2022/07/image-4.png"><img src="https://devopscube.com/wp-content/uploads/2022/07/image-4.png" alt="EKS anywhere cluster deployment." class="wp-image-13988" width="566" height="423"/></a></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1657090780562"} -->
<h3>Step 5: Validate the cluster</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657090784709"} -->
<p>Once the cluster is created you can see a folder named <code>dev-eks-cluster</code> with the kubeconfig file. Lets export the kubeconfig file.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657100060973"} -->
<p>Replace <code>/path/to</code> with the abosolute path of the <code>dev-eks-cluster</code> folder location. Or checkout the<a href="https://devopscube.com/kubernetes-kubeconfig-file/" data-type="post" data-id="13806"> Kubeconfig file guide</a> to know more about kubeconfig file practical usage.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1657099837185"} -->
<pre class="wp-block-code"><code>KUBECONFIG=/path/to/dev-eks-cluster/dev-eks-cluster-eks-a-cluster.kubeconfig</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657100186707"} -->
<p>Now, lets list the pods in the <code>kube-system</code> namespace to validate the cluster. You should see all the pods in running state as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":13989,"sizeSlug":"full","linkDestination":"media","canvasClassName":"cnvs-block-core-image-1657100414489"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://devopscube.com/wp-content/uploads/2022/07/image-5.png"><img src="https://devopscube.com/wp-content/uploads/2022/07/image-5.png" alt="EKS anywhere cluster validation" class="wp-image-13989"/></a></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1657074245314"} -->
<h3>Step 6: Generate &amp; Deploy EKS Connector Configs</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657100507401"} -->
<p>Now that we have a running EKS anywhere development clusters, we will go ahead and register the cluster using EKS connector.</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"canvasClassName":"cnvs-block-core-quote-1657074633312"} -->
<blockquote class="wp-block-quote"><p><strong>Note</strong>: Before you register the cluster, ensure you have a valid AWS cli configuration with admin privileges in your system. Refer the <a href="https://scriptcrunch.com/install-aws-cli-guide/" data-type="URL" data-id="https://scriptcrunch.com/install-aws-cli-guide/" target="_blank" rel="noreferrer noopener">AWS CLI configuration guide</a> for more details.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657074364649"} -->
<p>Here is the command to generate EKS connector config YAMLs. Replace region value if you are using a different region.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1657074388886"} -->
<pre class="wp-block-code"><code>eksctl register cluster --name dev-eks-cluster --provider EKS_ANYWHERE --region us-west-2 </code></pre>
<!-- /wp:code -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657100549306"} -->
<p>The above command creates the following three YAML files. Where <code>eks-connector.yaml</code> is the EKS connector agent statefulset YAML. </p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true,"className":"is-style-cnvs-list-styled","canvasClassName":"cnvs-block-core-list-1657100685657"} -->
<ol class="is-style-cnvs-list-styled"><li>eks-connector-clusterrole.yaml</li><li>eks-connector-console-dashboard-full-access-group.yaml</li><li>eks-connector.yaml</li></ol>
<!-- /wp:list -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657100700176"} -->
<p>Lets deploy all the three YAMLs.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"canvasClassName":"cnvs-block-core-code-1657100765901"} -->
<pre class="wp-block-code"><code>kubectl apply -f eks-connector-clusterrole.yaml
kubectl apply -f eks-connector-console-dashboard-full-access-group.yaml
kubectl apply -f eks-connector.yaml</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3,"canvasClassName":"cnvs-block-core-heading-1657101049104"} -->
<h3>Step 7: Validate EKS Anywhere Cluster Registration On EKS console</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101053164"} -->
<p>If you head over to the AWS EKS console, you should see the newly registered cluster as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":13991,"width":601,"height":273,"sizeSlug":"full","linkDestination":"media","canvasClassName":"cnvs-block-core-image-1657101077428"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><a href="https://devopscube.com/wp-content/uploads/2022/07/image-6.png"><img src="https://devopscube.com/wp-content/uploads/2022/07/image-6.png" alt="EKS anywhere cluster console" class="wp-image-13991" width="601" height="273"/></a></figure>
<!-- /wp:image -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101161735"} -->
<p>If you click the cluster name, you can view all the information and objects of the EKS anywhere cluster running in you local workstation.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":13992,"width":503,"height":869,"sizeSlug":"large","linkDestination":"media","canvasClassName":"cnvs-block-core-image-1657101193418"} -->
<figure class="wp-block-image aligncenter size-large is-resized"><a href="https://devopscube.com/wp-content/uploads/2022/07/image-7.png"><img src="https://devopscube.com/wp-content/uploads/2022/07/image-7-593x1024.png" alt="Listing EKS anywhere cluster resources on EKS console." class="wp-image-13992" width="503" height="869"/></a></figure>
<!-- /wp:image -->

Here is the EKS connector demo I have added in Youtube

{% embed https://www.youtube.com/watch?v=T_H65f4wDG8 %}


<!-- wp:heading {"textAlign":"center","canvasClassName":"cnvs-block-core-heading-1657101649892"} -->
<h2 class="has-text-align-center">Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101653093"} -->
<p>In this guide we looked at EKS anywhere Kubernetes development cluster setup. It is pretty easy to get started. Do give it a try.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657101904292"} -->
<p>Also if you are looking for light weight Kubernetes development clusters, checkout my <a href="https://devopscube.com/kubernetes-minikube-tutorial/" data-type="post" data-id="11021">minikube tutorial</a>.<br></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"canvasClassName":"cnvs-block-core-paragraph-1657102003413"} -->
<p>If you are learning Kubernetes, checkout 30+ <a href="https://devopscube.com/kubernetes-tutorials-beginners/" data-type="URL" data-id="https://devopscube.com/kubernetes-tutorials-beginners/" target="_blank" rel="noreferrer noopener">Kubernetes beginners tutorials.</a></p>
<!-- /wp:paragraph -->