jenkins-x / terraform-aws-eks-jx

A Terraform module for creating Jenkins X infrastructure on AWS
Apache License 2.0
63 stars 42 forks source link

Feat: added ability to run jx pipelines on EKS Fargate instances #312

Closed apentsak-vitech closed 2 years ago

apentsak-vitech commented 2 years ago

Description

Added ability to run jx pipelines on EKS Fargate instance to decrease AWS cost

Special notes for the reviewer(s)

Which issue this PR fixes

fixes #

ankitm123 commented 2 years ago

This is cool, I will give it a try in my test account tonight, and see if it works! Thanks for this!

apentsak-vitech commented 2 years ago

This is cool, I will give it a try in my test account tonight, and see if it works! Thanks for this!

Did you have a chance to try it ?

ankitm123 commented 2 years ago

Hi @AndrewsBot, Sorry for the delay. I was able to run terraform plan on the PR, after making a few changes, but I see that it still creates an eks cluster with EC2 instances ... From the tf plan

# module.eks-jx.module.cluster.module.eks.aws_launch_configuration.workers[0] will be created
  + resource "aws_launch_configuration" "workers" {

and

# module.eks-jx.module.cluster.module.eks.aws_autoscaling_group.workers[0] will be created
  + resource "aws_autoscaling_group" "workers" {

I am not familiar with fargate, but in fargate (EKS/ECS) EC2 instances are not created in the end user's account, right?

These were the changes I had to make to the example:

variables.tf

variable "region" {
  type    = string
  default = "us-east-1"
}

variable "profile" {
  type    = string
  default = "default"
}

main.tf

provider "aws" {
  region  = var.region
  profile = var.profile
}

module "eks-jx" {
  source                         = "../../"
  fargate_nodes_for_jx_pipelines = true
  # More details https://docs.aws.amazon.com/eks/latest/userguide/fargate.html
  # NAT needed by EKS Fargate
  enable_nat_gateway  = true
  single_nat_gateway  = true
  cluster_version     = "1.21"
  nginx_chart_version = "3.12.0"
}

So I think what is required is to check if the fargate variable is set to true and not create launch templates and configurations.

Also, we use this module internally, which seems to have support for fargate already, can we incorporate changes from that module into this module? (You have to change the variables being pased to this block) May be this will be of help? https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/examples/fargate/main.tf

apentsak-vitech commented 2 years ago

I used Fargate only for JX pipelines. For application and other stuff it creates cluster node.

ankitm123 commented 2 years ago

Can you format the files and just fix the example file (tf plan errors out ...), I think it's good to merge ... I mentioned the changes in this comment: https://github.com/jenkins-x/terraform-aws-eks-jx/pull/312#issuecomment-946744885

AndrewPentsak commented 2 years ago

Can you format the files and just fix the example file (tf plan errors out ...), I think it's good to merge ... I mentioned the changes in this comment: #312 (comment)

Ok, I will check it in few days