Difference between revisions of "Deploy EKS cluster using Terraform"

From wikieduonline
Jump to navigation Jump to search
 
(73 intermediate revisions by 7 users not shown)
Line 1: Line 1:
* Terraform <code>[[eks]]</code> [[module]]: https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest
+
* [[Terraform EKS module]]:  
** 21 resources: <code>[[aws_eks_cluster]]</code> ([[Terraform EKS apply output]], <code>[[terraform show (grep resource) in EKS|terraform show]]</code> | <code>grep [[resource]]</code>)
+
** https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest
 +
** FAQ: https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/faq.md
 +
** 21 resources:  
 +
*** <code>[[aws_eks_cluster]]</code> ([[Terraform EKS apply output]], <code>[[terraform show (grep resource) in EKS|terraform show]]</code> | <code>grep [[resource]]</code>)
 +
*** <code>[[aws_eks_addon]]</code>
 +
** Examples: https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples
  
 
== Example ==
 
== Example ==
  
 
0) Download code
 
0) Download code
:<code>[[git clone]] https://github.com/hashicorp/learn-terraform-provision-eks-cluster</code>
+
:<code>[[git clone]] https://github.com/hashicorp/learn-terraform-provision-eks-cluster && [[cd learn-terraform-provision-eks-cluster]]</code>
:<code>cd learn-terraform-provision-eks-cluster</code>
+
 
 +
1) Execute (<code>[[tf login]]</code>)
 +
* Change [[TFC execution mode]] to [[local]] in TFC web portal
 +
* Change [[name]] in [[main.tf]] ([[Terraform module: vpc]] section) to your prefered VPC name
 +
* Configure your [[AWS profile]] name in <code>[[main.tf]]</code>, do not use default.
 +
 
 +
[[export]] [[TF_CLOUD_ORGANIZATION]]=test
 +
 
  
1) Execute
 
 
  [[terraform init]] #It may take several minutes
 
  [[terraform init]] #It may take several minutes
 
  [[terraform plan]]
 
  [[terraform plan]]
  [[Terraform EKS: terraform apply|terraform apply]]
+
  [[Terraform EKS: terraform apply|terraform apply]]: [[Terraform EKS apply output]]
([[Terraform EKS apply output]])
+
It may take around 15 min
  
1.1) Review EKS cluster created
+
  one liner: export [[TF_CLOUD_ORGANIZATION]]=test && [[tf init]] && [[tf plan]] && [[tf apply]]
  [[kubectl get nodes]]
 
The connection to the server localhost:[[8080]] was refused - did you specify the right host or port?
 
  
 
2) Update configuration
 
2) Update configuration
 
  Update [[kubeconfig]] with credentials:
 
  Update [[kubeconfig]] with credentials:
  [[aws eks]] --region $(terraform output -raw region) [[update-kubeconfig]] --name $(terraform output -raw cluster_name)
+
  [[aws eks]] --region $([[terraform output -raw region]]) [[update-kubeconfig]] --name $([[terraform output -raw]] cluster_name)
  Added new context arn:aws:eks:us-east-2:XXXXXXX:cluster/myeks-eks-xxxx to /Users/youruser/[[.kube/config]]
+
   
 +
[[Added new context]] arn:aws:eks:us-east-2:XXXXXXX:cluster/myeks-eks-xxxx to /Users/youruser/[[.kube/config]]
 +
 
 +
2.1) Review EKS cluster created
 +
[[kubectl get nodes]]
 +
NAME                                      STATUS  ROLES    AGE    VERSION
 +
ip-10-0-1-29.us-east-2.compute.internal    Ready    <none>  5m31s  [[v1.23]].9-eks-ba74326
 +
ip-10-0-1-47.us-east-2.compute.internal    Ready    <none>  5m21s  v1.23.9-eks-ba74326
 +
ip-10-0-2-121.us-east-2.compute.internal  Ready    <none>  5m13s  v1.23.9-eks-ba74326
  
 
3) Review [[resources]]:
 
3) Review [[resources]]:
  <code>[[terraform show (grep resource) in EKS| terraform show]] | grep -w resource | sort | uniq</code>
+
  <code>[[terraform show (EKS using Terraform)|terraform show]] | grep -w resource | sort | uniq</code>
 +
<code>[[terraform show (EKS using Terraform)|terraform show]] | grep -w resource | sort | uniq | [[wc -l]]</code>
 +
34
  
 
4) Configure <code>[[kubectl]]</code>
 
4) Configure <code>[[kubectl]]</code>
 
  [[aws eks list-clusters]] --output text | awk '{print $2}'
 
  [[aws eks list-clusters]] --output text | awk '{print $2}'
  aws eks update-kubeconfig --name my-eks-cluster-name
+
  [[aws eks update-kubeconfig]] --name [[my-eks-cluster-name]]
  
5) Review cluster status/configuration
+
5) Review [[cluster status]]/configuration
 
  [[kubectl cluster-info]]
 
  [[kubectl cluster-info]]
 +
[[kubectl cluster-info dump]]
 +
[[kubectl get all -A]]
 +
[[Default EKS installation]]
 +
 +
6) Install your desired [[addons]]:
 +
[[helm install]]
 +
 +
== Errors ==
 +
* <code>[[Error: Failed to read organization]]</code>
 +
* <code>[[Error: failed to create backend alias to target]] "". The hostname is not in the correct format.</code>
 +
* <code>[[Error: Invalid or missing required argument]] .../... [[TF_CLOUD_ORGANIZATION]]</code>
 +
* [[Unable to parse config file]] ~/.aws/config
  
 
== Related ==
 
== Related ==
 +
* [[Addons]]: <code>[[eks-pod-identity-agent]]</code>, <code>[[aws-efs-csi-driver]], [[amazon-cloudwatch-observability]]</code>
 +
* <code>[[helm install]]</code>
 
* <code>[[aws eks update-kubeconfig --name my-eks-cluster-name]]</code>
 
* <code>[[aws eks update-kubeconfig --name my-eks-cluster-name]]</code>
 
* <code>[[kubectl cluster-info]]</code>
 
* <code>[[kubectl cluster-info]]</code>
* <code>[[kubectl get nodes]]</code>
+
* <code>[[kubectl get nodes]]</code>, <code>[[kubectl describe nodes]]</code>
* <code>[[kubectl describe nodes]]</code>
 
 
* <code>[[kubeclt get services]]</code>
 
* <code>[[kubeclt get services]]</code>
 
* <code>[[Terraform resource: aws eks cluster]]</code>
 
* <code>[[Terraform resource: aws eks cluster]]</code>
Line 44: Line 76:
 
* <code>[[aws eks create-cluster]]</code>
 
* <code>[[aws eks create-cluster]]</code>
 
* <code>[[asg_desired_capacity]]</code>, <code>[[InstanceType]]</code>
 
* <code>[[asg_desired_capacity]]</code>, <code>[[InstanceType]]</code>
* <code>[[kubectl proxy]]</code>
+
* [[Terraform eks managed node groups: instance types]]
* <code>[[kubeadm]]</code>
+
* [[K8s installation]]: <code>[[eksctl create cluster]]</code>
[[eksctl create cluster]]
+
* [[Deploy GKE cluster using Terraform]]
 +
* <code>[[eks-cluster.tf]]</code> https://github.com/hashicorp/learn-terraform-provision-eks-cluster/blob/main/eks-cluster.tf
 +
* <code>[[worker_groups]]</code>
 +
* <code>[[node_groups]]</code>
 +
* [[terraform.tf]]
 +
* [[Apply complete! Resources: 63 added, 0 changed, 0 destroyed.]]
  
 
== Activities ==
 
== Activities ==
 
* Review https://learn.hashicorp.com/tutorials/terraform/eks
 
* Review https://learn.hashicorp.com/tutorials/terraform/eks
 +
* [[Create your first EKS Cluster using AWS Management Console]]
  
 
== See also ==
 
== See also ==
* {{kubectl get}}
+
* {{Terraform EKS module}}
* {{EKS}}
 
 
* {{Terraform EKS}}
 
* {{Terraform EKS}}
* {{K8s installation}}
+
 
  
 
[[Category:EKS]]
 
[[Category:EKS]]
 
[[Category:Terraform]]
 
[[Category:Terraform]]

Latest revision as of 11:07, 12 February 2024

Example[edit]

0) Download code

git clone https://github.com/hashicorp/learn-terraform-provision-eks-cluster && cd learn-terraform-provision-eks-cluster

1) Execute (tf login)

export TF_CLOUD_ORGANIZATION=test


terraform init #It may take several minutes
terraform plan
terraform apply: Terraform EKS apply output
It may take around 15 min
one liner: export TF_CLOUD_ORGANIZATION=test && tf init && tf plan && tf apply

2) Update configuration

Update kubeconfig with credentials:
aws eks --region $(terraform output -raw region) update-kubeconfig --name $(terraform output -raw cluster_name)

Added new context arn:aws:eks:us-east-2:XXXXXXX:cluster/myeks-eks-xxxx to /Users/youruser/.kube/config

2.1) Review EKS cluster created

kubectl get nodes
NAME                                       STATUS   ROLES    AGE     VERSION
ip-10-0-1-29.us-east-2.compute.internal    Ready    <none>   5m31s   v1.23.9-eks-ba74326
ip-10-0-1-47.us-east-2.compute.internal    Ready    <none>   5m21s   v1.23.9-eks-ba74326
ip-10-0-2-121.us-east-2.compute.internal   Ready    <none>   5m13s   v1.23.9-eks-ba74326

3) Review resources:

terraform show | grep -w resource | sort | uniq
terraform show | grep -w resource | sort | uniq | wc -l
34

4) Configure kubectl

aws eks list-clusters --output text | awk '{print $2}'
aws eks update-kubeconfig --name my-eks-cluster-name

5) Review cluster status/configuration

kubectl cluster-info
kubectl cluster-info dump
kubectl get all -A
Default EKS installation

6) Install your desired addons:

helm install

Errors[edit]

Related[edit]

Activities[edit]

See also[edit]

Advertising: