Provision EKS cluster with Terraform and Cloudify

What you’ll learn

Prerequisites

What is Cloudify?

Let’s Start

How to install Cloudify locally?

$ sudo docker run --name cfy_manager_local -d --restart unless-stopped -v /sys/fs/cgroup:/sys/fs/cgroup:ro --tmpfs /run --tmpfs /run/lock --security-opt seccomp:unconfined --cap-add SYS_ADMIN -p 80:80 -p 8000:8000 cloudifyplatform/community-cloudify-manager-aio:6.2.0
$ docker ps # to get ID of cloudify_container_id
$ docker logs cloudify_container_id

To install Cloudify to Kubernetes cluster

$ helm repo add cloudify-helm https://cloudify-cosmo.github.io/cloudify-helm$ helm install cloudify-manager-aio cloudify-helm/cloudify-manager-aio

Cloudify CLI installation

$ pip install cloudify==6.1.0

Configure the CLI

$ cfy profiles use localhost -u admin -p admin$ cfy profiles set --manager-tenant default_tenant

Installing Plugins

$ cfy plugins bundle-upload

Installing GIT

$ docker exec -it cloudify_container_id bash
$ sudo yum install git -y

Creating secrets for aws_access_key_id/aws_secret_access_key

$ cfy secrets create aws_access_key_id --secret-string YOUR_ACCESS_KEY_TO_AWS$ cfy secrets create aws_secret_access_key --secret-string YOUR_SECRET_ACCESS_KEY_TO_AWS

Terraform Template to provision EKS cluster

EKS

provider "aws" {
region = "eu-west-2"
}
data "aws_eks_cluster" "cluster" {
name = module.eks.cluster_id
}
data "aws_eks_cluster_auth" "cluster" {
name = module.eks.cluster_id
}
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
token = data.aws_eks_cluster_auth.cluster.token
load_config_file = false
}
data "aws_availability_zones" "available" {
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.11.0"
name = "k8s-${var.cluster_name}-vpc"
cidr = "172.16.0.0/16"
azs = data.aws_availability_zones.available.names
private_subnets = ["172.16.1.0/24", "172.16.2.0/24"]
public_subnets = ["172.16.3.0/24", "172.16.4.0/24"]
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
public_subnet_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/elb" = "1"
}
private_subnet_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
}
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "17.24.0"
cluster_name = "${var.cluster_name}"
cluster_version = "1.21"
subnets = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id
write_kubeconfig = true
worker_groups = [
{
name = "ng-medium"
instance_type = "t3.medium"
asg_desired_capacity = 1
tags = [{
key = "instance-type"
value = "on-demand-medium"
propagate_at_launch = true
}, {
key = "os-type"
value = "linux"
propagate_at_launch = true
}]
},
]
}

Run blueprint to provision EKS with Terraform and Cloudify Manager

module_source: https://github.com/cloudify-community/cloudify-tutorial.git
terraform_template_location: terraform/tf_11_eks_provision/template
variables:
access_key: { get_secret: aws_access_key_id }
secret_key: { get_secret: aws_secret_access_key }
aws_region: eu-west-3

Execute blueprint on your local Cloudify manager using CLI

$ cfy apply -i inputs.yaml

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Igor Zhivilo

Igor Zhivilo

I am DevOps/Software Engineer at Tikal who loves to learn and experiment with new technologies.