Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[EKS/Terraform] Installing or Provisioning an EKS cluster through Terraform Module.

Posted on October 17, 2022July 21, 2025 By nim No Comments on [EKS/Terraform] Installing or Provisioning an EKS cluster through Terraform Module.

Hello anh em!

Trước đó mình có hướng dẫn Install EKS cluster bằng terraform resource.
Bạn có thể tham khảo bài viết bên dưới.

[AWS] Create EKS Cluster and EKS Node Groups in Public and Private Subnets


Hôm nay chúng ta sẽ Install 1 cluster eks thông qua terraform module.
Mình sẽ sử dụng module này:
https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest

Và đây là các bạn viết tham khảo:
(main) https://antonputra.com/amazon/create-eks-cluster-using-terraform-modules/
https://infraform.github.io/terraform-elastic-kubernetes/
https://github.com/alexlogy/terraform-eks-cluster
https://alexlogy.io/creating-eks-cluster-in-aws-with-terraform/
https://andrewtarry.com/posts/terraform-eks-alb-setup/
https://no-easy-dev.tistory.com/m/39

Upgrade from v17.x to v18.x
https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/UPGRADE-18.0.md#upgrade-from-v17x-to-v18x
https://billhegazy.com/eks-terraform-module-upgrade-from-v17-to-v18/

Contents

Toggle
  • Upgrade from v18.x to v19.x
  • Terraform EKS module version 19.x.x
  • 1) Creating VPC to repair to EKS Cluster
  • 2) Create EKS cluster via terraform module(v18.x.x)
    • 2.1) OpenID Connect Provider and IRSA
    • 2.2) Pods can’t connect the internet or need to be permited all outbound on eks
    • 2.3) Custom block storage for Node Group
    • 2.4) Update output
  • Issues
    • does not automatically assign public IP addresses to instances launched into it
  • Understanding EKS version upgrades using modules.

Upgrade from v18.x to v19.x

and delete all rules in node_security_group_additional_rules

remove node_security_group_ntp_ipv4_cidr_block = ["169.254.169.123/32"]

change cluster_encryption_config

Terraform EKS module version 19.x.x

Nếu bạn deploy mới thì có tham khảo code ở đây.

https://github.com/mrnim94/terraform-aws/tree/master/eks/eks_module/version-19.x.x/eks

1) Creating VPC to repair to EKS Cluster

Đầu tiên thì mình sẽ create VPC và bạn có thể tham khảo link dưới.
https://bitbucket.org/nimtechnology/aws-terraform/src/master/infra-structure/aws/250887682577/vpc/mdce-metadefender-devops/

Phần này cũng đơn giản là mình tạo VPC và tạo 2 vùng subnet private và subnet public

Ở phần VPC thì bạn cần lưu ý ở chỗ tag

Chỗ này thì cần khai báo đúng tên cluster eks.

"kubernetes.io/role/elb" = 1
==> Tag này thì tạo svc LoadBalancer sẽ cập IP or Domain Public

"kubernetes.io/role/internal-elb" = 1
==> Tag này thì tạo svc LoadBalancer sẽ cập IP or Domain Private.

2) Create EKS cluster via terraform module(v18.x.x)

Hiện tai project này mình đang provisioning bằng bitbucket pipeline nên mình share qua bitbucket luôn.

https://bitbucket.org/nimtechnology/aws-terraform/src/master/infra-structure/aws/250887682577/eks/mdce-metadefender-devops/

Chúng ta sẽ đi vào từng khai báo

2.1) OpenID Connect Provider and IRSA

enable_irsa: Determines whether to create an OpenID Connect Provider for EKS to enable IRSA
nếu bạn vẫn thấy lạ với khai niệm trên thì có thể lab bài dưới.

[AWS] EKS IAM Roles for Service Accounts (IRSA) using Terraform

2.2) Pods can’t connect the internet or need to be permited all outbound on eks

Sau khi bạn đã dựng eks cluster và bạn nhớ rằng mình chưa config terraform cho Security Group mục này cần thiết cho bạn
nếu pod của bạn không thể đi ra ngoài internet thì mục này cần thiết cho bạn

Cấu hình trong eks terraform module.

https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1779#issuecomment-1203398170

https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/examples/complete/main.tf#L81-L99

2.3) Custom block storage for Node Group

Nếu bạn muốn chỉnh một số liên quan đến disk của worker EKS.
encrypt data, volume type,…

module "eks" {
  source       = "terraform-aws-modules/eks/aws"
  version = "18.30.2"
....
....

  eks_managed_node_groups = {
    "general-${var.owners}" = {
      # because HA ArgoCD, we need at least 3 nodes
      desired_size = 3
      min_size     = 3
      max_size     = 10

      block_device_mappings = {
        xvda = {
          device_name = "/dev/xvda"
          ebs = {
            volume_size           = 100
            volume_type           = "gp3"
            iops                  = 3000
            throughput            = 125
            encrypted             = true
            delete_on_termination = true
          }
        }
      }

      labels = {
        role = "general"
      }

      instance_types = ["t3.medium"]
      capacity_type  = "ON_DEMAND"
    }

2.4) Update output

output "cluster_certificate_authority_data" {
  description = "Base64 encoded certificate data required to communicate with the cluster"
  value       = module.eks.cluster_certificate_authority_data
}

output "cluster_endpoint" {
  description = "Base64 encoded certificate data required to communicate with the cluster"
  value       = module.eks.cluster_endpoint
}

output "cluster_id" {
  description = "Base64 encoded certificate data required to communicate with the cluster"
  value       = module.eks.cluster_id
}

output "oidc_provider_arn" {
  description = "Base64 encoded certificate data required to communicate with the cluster"
  value       = module.eks.oidc_provider_arn
}

output "vpc_id" {
  description = "The ID of the VPC is installed EKS Cluster"
  value       = data.terraform_remote_state.eks.outputs.vpc_id
}

Issues

does not automatically assign public IP addresses to instances launched into it

Error: waiting for EKS Node Group (devsecops-nim:general-devsecops-2023072807281029660000000e) to create: unexpected state 'CREATE_FAILED', wanted target 'ACTIVE'. last error: 1 error occurred:
│ 	* subnet-04bdeb40bc6cfdc4c, subnet-098f6bd57eea12e52, subnet-062620f94a0f7824c: Ec2SubnetInvalidConfiguration: One or more Amazon EC2 Subnets of [subnet-04bdeb40bc6cfdc4c, subnet-098f6bd57eea12e52, subnet-062620f94a0f7824c] for node group general-devsecops-2023072807281029660000000e does not automatically assign public IP addresses to instances launched into it. If you want your instances to be assigned a public IP address, then you need to enable auto-assign public IP address for the subnet. See IP addressing in VPC guide: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-ip-addressing.html#subnet-public-ip

Khi bạn provisioning 1 eks trên public subnet mà bạn gặp lỗi trên thì quay lại vpc và check đã khai báo config này hay chưa?

# Specify true to indicate that instances launched into the subnet should be assigned a public IP address
  map_public_ip_on_launch = true

Understanding EKS version upgrades using modules.

Bước đầu tiền thì nó sẽ Upgrade Control Plane lên đầu tiên.
– Module sẽ đi qua các resource là aws_eks_cluster resource và gán vào value của cluster_version.
– AWS upgrades cái control-plane node tại chỗ và trong serial, API sẽ downtime trong 1 vài giây, Nếu trong thời khách đó bạn có nhận được status 5xx hoặc 4xx nếu bạn tranh thủ test thử.

Bước tiếp theo là managed add-ons
Trong module thì, cluster_addons sẽ phụ thuộc cluster. Sau khi control plane report cài new version thì terraform tính toán cái compatible default add-on versions và sẽ deploy theo nó nếu bạn không pin version.

Ở phần Node groups roll forward sẽ chia làm 2 tình huống là EKS Managed và Node groups roll forward

Node-group typeHow upgrade is triggeredRollout strategyDefault disruption settings
EKS ManagedNew release_version from AWS when control plane is already on the target minorRolling update performed by EKS servicemaxUnavailable = 33% (module sets parallel strategy)
Self-managed ASGNew AMI ID looked up by module based on cluster_versionEC2 Auto Scaling Instance Refresh started by modulemin_healthy_percentage = 34% (≈ 66% max unavailable)

trong quá trình này quá trình rollout Kubernetes evicts pods sẽ sảy ra

Chúng ta sẽ xoáy sâu vào EKS Managed node-group.

Có những trường hợp như sau:

Những trường hợp modifying -> nó edit launch-template lên version mới -> update launch-template version mới trong auto scaling Group.
-> trường hợp này không đang lo ngại.

Những trường hợp Creating… -> thì nó sẽ thực hiện tạo ra 1 cài launch-template mới -> Tiếp đến là Tạo Autoscaling Group mới -> integrate với launch-template mới tạo trước đó.

Ở Case Create thì sẽ nguy hiểm nếu desire trong terraform khác desire đang chạy trên console AWS.
Ví dụ như trong terraform desire đang là 1 nhưng trên console AWS là mười.
Về bản chất, Nó tạo lên ASG mới 1 con node ready thế là nó terminate ASG cũ.
Khiến cho các pod không có đủ node để migrate sang 1 cách đột ngội.

https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/eks/node_group.go#L93

Nếu bạn thay các value như ami_type hoặc instance_type vì nó đang có ForceNew: true
thì terraform sẽ đưa ASG vào trường hợp creating và bạn cần cẩn thận.

AWS - Amazon Web Service

Post navigation

Previous Post: [Terraform] Solve “Redundant ignore_changes element” on EKSmodule
Next Post: [VPC] The difference between public and private subnets in Amazon VPC?

More Related Articles

Manage Kubernetes Secrets With External Secrets Operator AWS - Amazon Web Service
[EKS] Adjusting things to migrate EKS legacy to new versions. AWS - Amazon Web Service
[AWS] Setup Schedule Action for Auto Scaling Group – Saving Cost is based on ASG AWS - Amazon Web Service
[AWS] Login Argocd via Cognito in AWS ArgoCD
[DocumentDB] Install MongoDB on AWS Cloud AWS - Amazon Web Service
[RabbitMQ] Queue announces “cluster is in minority” AWS - Amazon Web Service

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • The Hidden Costs of CloudWatch: Why It’s So Expensive September 12, 2025
  • [AWS] Enable VPC Flow log to investigate data transfer. September 3, 2025
  • [EKS] How to use Spot instance for EKS. September 3, 2025
  • Beautiful Infratructure August 28, 2025
  • Create Service Bus on azure August 25, 2025

Archives

  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.