项目作者: miztiik

项目描述 :
simple-eks-cluster
高级语言: Python
项目地址: git://github.com/miztiik/simple-eks-cluster.git
创建时间: 2021-05-09T13:30:04Z
项目社区:https://github.com/miztiik/simple-eks-cluster

开源协议:

下载


Simple EKS Cluster

Can you show the developers in Miztiik Unicorn Corp how to launch a kubernetes cluster in AWS and use kubectl to interact with the cluster.

🎯 Solutions

In this demo, let us launch a EKS1 cluster in a custom VPC using AWS CDK. The cluster will have the following attributes

  • VPC:
    • 2-AZ Subnets with Public, Private and Isolated Subnets.
    • 1 NAT GW for internet access from private subnets
  • EKS
    • The control pane is launched with public access. i.e the cluster can be access without a bastion host
    • c_admin IAM role added to aws-auth configMap to administer the cluster from CLI
    • One managed EC2 node group
      • Launch template Two t3.medium instances running Amazon Linux 2
      • Auto-scaling Group with 2 desired instances.

Miztiik Automation: Simple EKS Cluster Architecture

  1. 🧰 Prerequisites

    This demo, instructions, scripts and cloudformation template is designed to be run in us-east-1. With few modifications you can try it out in other regions as well(Not covered here).

    • 🛠 AWS CLI Installed & Configured - Get help here
    • 🛠 AWS CDK Installed & Configured - Get help here
    • 🛠 Python Packages, Change the below commands to suit your OS, the following is written for amzn linux 2
      • Python3 - yum install -y python3
      • Python Pip - yum install -y python-pip
      • Virtualenv - pip3 install virtualenv
  2. ⚙️ Setting up the environment

    • Get the application code

      1. git clone https://github.com/miztiik/simple-eks-cluster
      2. cd simple-eks-cluster
  3. 🚀 Prepare the dev environment to run AWS CDK

    We will use cdk to make our deployments easier. Lets go ahead and install the necessary components.

    1. # You should have npm pre-installed
    2. # If you DONT have cdk installed
    3. npm install -g aws-cdk
    4. # Make sure you in root directory
    5. python3 -m venv .venv
    6. source .venv/bin/activate
    7. pip3 install -r requirements.txt

    The very first time you deploy an AWS CDK app into an environment (account/region), you’ll need to install a bootstrap stack, Otherwise just go ahead and deploy using cdk deploy.

    1. cdk bootstrap
    2. cdk ls
    3. # Follow on screen prompts

    You should see an output of the available stacks,

    1. eks-cluster-vpc-stack
    2. eks-cluster-stack
  4. 🚀 Deploying the application

    Let us walk through each of the stacks,

    • Stack: eks-cluster-stack
      As we are starting out a new cluster, we will use most default. No logging is configured or any add-ons.

      Initiate the deployment with the following command,

      1. cdk deploy eks-cluster-vpc-stack
      2. cdk deploy eks-cluster-stack

      After successfully deploying the stack, Check the Outputs section of the stack. You will find the *ConfigCommand* that allows yous to interact with your cluster using kubectl

  5. 🔬 Testing the solution

    1. Connect To EKS Cluster Consumer:

      Connect the KafkaAdminInstance instance using SSM Session Manager3. Navigate to /var/kafka/ directory. Kafka has been preinstalled and if user-data script had ran successfully, we should have a kafka topic created automatically for us. You can check the user data script status in logs on the instance at /var/log/miztiik-automation-*.log. The same log had been pushed to cloudwatch as well.

      Let us verify the kafka topic exists

      1. # Set kubeconfig
      2. aws eks update-kubeconfig \
      3. --name 1_cdk_c \
      4. --region us-east-1 \
      5. --role-arn arn:aws:iam::111122223333:role/eks-cluster-stack-cAdminRole655A13CE-XBF2V3PPV4FI
      6. # List nodes
      7. kubectl get no
      8. # Sample Output
      9. (.venv) simple-eks-cluster]# kubectl get no
      10. NAME STATUS ROLES AGE VERSION
      11. ip-10-10-0-90.ec2.internal Ready <none> 36h v1.18.9-eks-d1db3c
      12. ip-10-10-1-229.ec2.internal Ready <none> 36h v1.18.9-eks-d1db3c
      1. # Watching the status of nodes,
      2. (.venv) simple-eks-cluster]# kubectl get nodes --watch
      3. NAME STATUS ROLES AGE VERSION
      4. ip-10-10-0-90.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      5. ip-10-10-1-229.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      6. ip-10-10-1-229.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      7. ip-10-10-0-90.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      8. ip-10-10-1-229.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      9. ip-10-10-0-90.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      10. ip-10-10-1-229.ec2.internal Ready <none> 15h v1.18.9-eks-d1db3c
      11. ip-10-10-0-90.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      12. ip-10-10-1-229.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      13. ip-10-10-0-90.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      14. ip-10-10-1-229.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      15. ip-10-10-0-90.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      16. ip-10-10-1-229.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      17. ip-10-10-0-90.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c
      18. ip-10-10-1-229.ec2.internal Ready <none> 16h v1.18.9-eks-d1db3c

      You may face an error on the GUI2. For example, You may not be able to see workloads or nodes in your AWS Management Console.
      Make sure you using the same user/role you used to deploy the cluster. If they are different then you need to update the console user to kubernetes configmap. This doc3 has the instructions for the same

  6. 📒 Conclusion

    Here we have demonstrated how to use AWS for launching highly available EKS cluster. You can extend this launching your workloads using service and deployment manifests.

  7. 🧹 CleanUp

    If you want to destroy all the resources created by the stack, Execute the below command to delete the stack, or you can delete the stack from console as well

    • Resources created during Deploying The Application
    • Delete CloudWatch Lambda LogGroups
    • Any other custom resources, you have created for this demo
    1. # Delete from cdk
    2. cdk destroy
    3. # Follow any on-screen prompts
    4. # Delete the CF Stack, If you used cloudformation to deploy the stack.
    5. aws cloudformation delete-stack \
    6. --stack-name "MiztiikAutomationStack" \
    7. --region "${AWS_REGION}"

    This is not an exhaustive list, please carry out other necessary steps as maybe applicable to your needs.

📌 Who is using this

This repository aims to show how to use AWS EKS to new developers, Solution Architects & Ops Engineers in AWS. Based on that knowledge these Udemy course #1, course #2 helps you build complete architecture in AWS.

💡 Help/Suggestions or 🐛 Bugs

Thank you for your interest in contributing to our project. Whether it is a bug report, new feature, correction, or additional documentation or solutions, we greatly value feedback and contributions from our community. Start here

👋 Buy me a coffee

ko-fi Buy me a coffee ☕.

📚 References

  1. AWS Docs: EKS Getting Started
  2. AWS EKS Troubleshooting - EKS IAM
  3. AWS EKS Troubleshooting - Resolve user/role does not have access to objects
  4. AWS EKS Troubleshooting - Resolve an unauthorized server

🏷️ Metadata

:Automation:Level-200-green" alt="miztiik-success-green">

Level: 200