<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nicholas Lu on Medium]]></title>
        <description><![CDATA[Stories by Nicholas Lu on Medium]]></description>
        <link>https://medium.com/@lucheeseng?source=rss-2b6694a7525------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PzdSc5OsYkzaYjmN4pjlvg@2x.jpeg</url>
            <title>Stories by Nicholas Lu on Medium</title>
            <link>https://medium.com/@lucheeseng?source=rss-2b6694a7525------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 15:50:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lucheeseng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Provisioning Spot Instance Nodegroup into EKS via Terraform]]></title>
            <link>https://lucheeseng.medium.com/provisioning-spot-instance-nodegroup-into-eks-via-terraform-4b407330d353?source=rss-2b6694a7525------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b407330d353</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[spot-instances]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ek]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Nicholas Lu]]></dc:creator>
            <pubDate>Tue, 22 Dec 2020 20:23:13 GMT</pubDate>
            <atom:updated>2020-12-22T20:23:13.898Z</atom:updated>
            <content:encoded><![CDATA[<p>Experimenting or deploying EKS workload can be expensive but it does not have to be that way.</p><p>Objective: We are going to deploy EKS cluster with spot instance Nodegroup with Terraform</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gj40bXiqw_9LeNJg" /><figcaption>Photo by <a href="https://unsplash.com/@dallasreedy?utm_source=medium&amp;utm_medium=referral">Dallas Reedy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Before we start, let’s dive into history of Kubernetes. Since its inception, there has been huge influx of demand to get developer and admin to speed on maintaining cloud and on-prem resources. The the need of getting resource pool collectively and ability to make use of cloud and on-prem as a resource pool is what Kubernetes offers. The inception of Kubernetes As A Service(KaaS) has just started three years ago, example like AWS EKS, Azure AKS,Google GKE are the few to name which offers managed cluster at a price. AWS especially, does offer different tier of compute:</p><p>1. Normal (On-demand)<br>2. Reserved (long term contractual)<br>3. <strong>Spot</strong> (“bid on unused AWS pool at a fraction of cost”)</p><p>You will be thinking that we could create the project with on demand without any extra work, but this will incur much of the charges as you run them long enough and with spot you can shave as much as possible without compromising flexibility.(You can potentially save up to 70% compared to on demand workload)</p><h3>First: Create cluster</h3><p>To create a cluster, you will need to start with the terraform, it should look like this.</p><p>First we are going to build the vpc using terraform, you can skip this method if you are using default vpc but I prefer to make it from ground up, therefore I will create a new vpc with three public subnet and three private subnet together with NAT gateway(you may want to comment out it if you are planning to do a basic setup and I recommend you to try the basic setup)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c254a4d97628456afb87c16a4c16f43/href">https://medium.com/media/5c254a4d97628456afb87c16a4c16f43/href</a></iframe><p>With the vpc created, you can now proceed with the eks cluster creation. The code will look like this, you will need to fill the subnet, vpc ids created earlier and I separate this from vpc due the the fact vpc is there to stay even the cluster is destroyed and you can reuse it back.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8613363ebf01bc675378b411621d0d7b/href">https://medium.com/media/8613363ebf01bc675378b411621d0d7b/href</a></iframe><p>Run the code and you should get a cluster with no nodegroup inside, keep that in mind I have left some of the part to be filled later(both variable <strong>aws_user</strong> and <strong>aws_nodegroup</strong> will need to be updated later)as we create our nodegroup.</p><h3>Second: Create nodegroup via terraform</h3><p>We have already create the cluster and vpc and they should be up and running, but now we dont have worker/nodegroup joining the cluster. This, we need to create a cloudformation deployment and have the configmap/aws-auth updated based on the nodegroup we will be creating. This will allow the cluster acknowledge the nodegroup and join the cluster.</p><p>Let’s create a yaml file of cloudformation stack as followed, save the following file and put into your s3 bucket(create a new bucket and put the file into it, keep the path of the file with you):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54074c1a8ec26730c0487939ea4ccd1c/href">https://medium.com/media/54074c1a8ec26730c0487939ea4ccd1c/href</a></iframe><p>Once uploaded, we will be creating our cloudformation, this time we are using terraform to create the stack for us and the code is as followed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5d0d5d119327121e2f0777001784dd6/href">https://medium.com/media/c5d0d5d119327121e2f0777001784dd6/href</a></iframe><p>Note: fill up the details of vpc, subnet, eks-cluster-security group, path of your yaml location</p><p>Run the file and you should get your nodegroup created, now proceed with the arn output return by terraform as you create your nodegroup, you will need to replace the variable <strong>aws_nodegroup</strong> of your <strong>eks.tf </strong>.It should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a9118f604a4259256766edfd07ee6f5/href">https://medium.com/media/9a9118f604a4259256766edfd07ee6f5/href</a></iframe><p>That should leave you with the cluster of cost saving nodegroup. You may destroy the stack as you please and recreate when you need them. Note: if you were to delete them, please use terraform destroy in the order(nodegroup, cluster, vpc).</p><h3>Where to go from here:</h3><p>We have done the creation of spot instance ec2 instance joining our EKS cluster, but this could be improved with the <a href="https://aws.amazon.com/blogs/containers/amazon-eks-now-supports-provisioning-and-managing-ec2-spot-instances-in-managed-node-groups/#:~:text=Starting%20today%2C%20customers%20can%20use,your%20interruption%20tolerant%20containerized%20applications.">newly announced EKS on spot instance</a>. I will put them in the post in the time to come. Please do no hesitate to ask or give any recommendation on how to make my tutorial better.</p><p>Linkedin: <a href="https://www.linkedin.com/in/chee-seng-lu-0051b245/">Nicholas Lu</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b407330d353" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Helm Charts into K8S with Terraform]]></title>
            <link>https://lucheeseng.medium.com/deploying-helm-charts-into-k8s-with-terraform-7125fc048647?source=rss-2b6694a7525------2</link>
            <guid isPermaLink="false">https://medium.com/p/7125fc048647</guid>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ek]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Nicholas Lu]]></dc:creator>
            <pubDate>Mon, 07 Dec 2020 17:50:54 GMT</pubDate>
            <atom:updated>2020-12-07T17:55:59.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aUJbrNA91IYHJyx1" /><figcaption>Photo by <a href="https://unsplash.com/@andrewtneel?utm_source=medium&amp;utm_medium=referral">Andrew Neel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“Look mom, no hands on Console”, <em>Deploying Helm charts into Kubernetes has never been easier with Terraform</em></p><p>I have just started my DevOps journey with Terraform not long ago and there are too much deployment methods into Kubernetes cluster. The existence of multiple deployment guide and pattern makes it easy for developer to get their code into the cluster with the requirement of knowing the ins and out of Kubernetes.</p><p>There are plenty of mode of deployment such as:<br>1) Creating a surrogate container to run CI/CD tasks via platform like Gitlab/Github Actions/Jenkins etc<br>2) Direct injection of manifest file/deployment on CI tools <br>3) Helm, a tool that distills deployment component together into a single package(includes deployment, ingress, service, configmap etc)</p><p>In this post, I am going to show how to deploy any charts into your cluster via terraform.</p><h3>Let start with the cluster creation</h3><p>We will be doing all from Terrafrom script with no console tinkering just to practice the best practice of IaC. We will need to create vpc with this method first then followed with the EKS cluster creation and the nodegroup creation. I am starting with the basic cluster of AWS EKS(public interfaced, bare minimal setup, dual az), the code is as follow:</p><pre>#vpc.tf<br>resource &quot;aws_vpc&quot; &quot;vpc-eks&quot; {<br>  cidr_block           = &quot;10.0.0.0/16&quot;<br>  instance_tenancy     = &quot;default&quot;<br>  enable_dns_hostnames = true<br>  enable_dns_support   = true</pre><pre>tags = {<br>    Name = var.cluster_name<br>  }<br>}</pre><pre>data &quot;aws_vpc&quot; &quot;selected&quot; {<br>  id = aws_vpc.vpc-eks.id<br>}</pre><pre>resource &quot;aws_subnet&quot; &quot;public-a&quot; {<br>  vpc_id                  = aws_vpc.vpc-eks.id<br>  cidr_block              = &quot;10.0.0.0/20&quot;<br>  availability_zone       = &quot;ap-southeast-1a&quot;<br>  map_public_ip_on_launch = true<br>  tags = {<br>    Name                                = &quot;public-a&quot;<br>  }<br>}</pre><pre>data &quot;aws_subnet&quot; &quot;public-a&quot; {<br>  id = aws_subnet.public-a.id<br>}</pre><pre>resource &quot;aws_subnet&quot; &quot;public-b&quot; {<br>  vpc_id                  = aws_vpc.vpc-eks.id<br>  cidr_block              = &quot;10.0.16.0/20&quot;<br>  availability_zone       = &quot;ap-southeast-1b&quot;<br>  map_public_ip_on_launch = true<br>  tags = {<br>    Name                                = &quot;public-b&quot;<br>  }<br>}</pre><pre>data &quot;aws_subnet&quot; &quot;public-b&quot; {<br>  id = aws_subnet.public-b.id<br>}</pre><pre>#assignment of routetable<br>resource &quot;aws_default_route_table&quot; &quot;route-public&quot; {<br>  default_route_table_id = aws_vpc.vpc-eks.default_route_table_id</pre><pre>route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.igw.id<br>  }</pre><pre>tags = {<br>    Name = &quot;rtb-main&quot;<br>  }</pre><pre>depends_on = [aws_internet_gateway.igw]<br>}</pre><pre>resource &quot;aws_internet_gateway&quot; &quot;igw&quot; {<br>  vpc_id = aws_vpc.vpc-eks.id</pre><pre>depends_on = [aws_vpc.vpc-eks]</pre><pre>tags = {<br>    Name = &quot;igw-example&quot;<br>  }<br>}</pre><pre>resource &quot;aws_route_table_association&quot; &quot;public_subnet-a&quot; {<br>  subnet_id      = aws_subnet.public-a.id<br>  route_table_id = aws_default_route_table.route-public.id<br>}</pre><pre>resource &quot;aws_route_table_association&quot; &quot;public_subnet-b&quot; {<br>  subnet_id      = aws_subnet.public-b.id<br>  route_table_id = aws_default_route_table.route-public.id<br>}</pre><pre>variable &quot;cluster_name&quot; {<br>  type = string<br>  default = &quot;example-eks&quot;<br>}</pre><p>Now the second file, the infrastructure of EKS and nodegroup:</p><pre>#main.tf<br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;3.6.0&quot;<br>    }<br>  }</pre><pre>provider &quot;aws&quot; {<br>  region = &quot;ap-southeast-1&quot;<br>}</pre><pre>backend &quot;remote&quot; {<br>    hostname     = &quot;app.terraform.io&quot;<br>    organization = &quot;example&quot;</pre><pre>workspaces {<br>      name = &quot;myworkplace&quot;<br>    }<br>  }<br>}</pre><pre>data &quot;aws_eks_cluster&quot; &quot;cluster&quot; {<br>  name = module.my-cluster.cluster_id<br>}</pre><pre>data &quot;aws_eks_cluster_auth&quot; &quot;cluster&quot; {<br>  name = module.my-cluster.cluster_id<br>}</pre><pre>provider &quot;kubernetes&quot; {<br>  host                   = data.aws_eks_cluster.cluster.endpoint<br>  cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)<br>  token                  = data.aws_eks_cluster_auth.cluster.token<br>  load_config_file       = false<br>  version                = &quot;~&gt; 1.9&quot;<br>}</pre><pre>module &quot;my-cluster&quot; {<br>  source          = &quot;terraform-aws-modules/eks/aws&quot;<br>  cluster_name    = var.cluster_name<br>  cluster_version = &quot;1.18&quot;<br>  subnets = [aws_subnet.public-a.id, aws_subnet.public-b.id]<br>  vpc_id                    = aws_vpc.vpc-eks.id<br>  cluster_enabled_log_types = [&quot;api&quot;, &quot;audit&quot;]<br> node_groups = [<br>    {<br>      name                 = &quot;nodegroup-a&quot;<br>      instance_type        = &quot;t3.medium&quot;<br>      platform             = &quot;linux&quot;<br>      asg_max_size         = 5<br>      asg_desired_capacity = 1<br>      public_ip            = false<br>      subnets              = [aws_subnet.subnet_public_a, aws_subnet.subnet_public_b]<br>      tags = {<br>        Name = &quot;nodegroup-a&quot;<br>      }<br>    },<br>  ]<br>}</pre><p>Spoiler: the Kubernetes provider component is important for the reference of the endpoint, token, certificate to authenticate with the cluster later in the deployment</p><p>Now, run the terraform apply and you should get the cluster ready within 15min or so. I prefer to run them via <a href="https://app.terraform.io/app">terraform</a> cloud and it’s the best place to preserve your state and run your plan and apply in one place where failure of terraform apply can be easily mitigated.</p><h3><strong>2) Let’s Get the Chart Deployed</strong></h3><p>With the cluster ready, now we can get Helm chart deployed into the cluster. The script is as followed<br>Notice : This <em>helm.tf </em>script is suppose to be separated from the vpc and eks terraform script. This because we want to decouple deployment from infrastructure as they are different in stages of functionality</p><pre>#helm.tf</pre><pre>provider &quot;aws&quot; {<br>  region = &quot;ap-southeast-1&quot;<br>}</pre><pre>backend &quot;remote&quot; {<br>    hostname     = &quot;app.terraform.io&quot;<br>    organization = &quot;example&quot;<br>workspaces {<br>      name = &quot;myworkplace-helm&quot;<br>    }<br>  }<br>}</pre><pre>provider &quot;kubernetes&quot; {<br>  load_config_file       = false<br>  host                   = data.aws_eks_cluster.example.endpoint<br>  cluster_ca_certificate = base64decode(data.aws_eks_cluster.example.certificate_authority.0.data)<br>  token                  = data.aws_eks_cluster_auth.example.token<br>}</pre><pre>provider &quot;helm&quot; {<br>  kubernetes {<br>    host     =  data.aws_eks_cluster.example.endpoint<br>    cluster_ca_certificate = base64decode(data.aws_eks_cluster.example.certificate_authority.0.data)<br>    token                  = data.aws_eks_cluster_auth.example.token<br>    load_config_file       = false<br>  }<br>}</pre><pre>resource &quot;helm_release&quot; &quot;metric_server&quot; {<br>  name       = &quot;metrics-server&quot; <br>  chart      = &quot;<a href="https://charts.bitnami.com/bitnami/metrics-server-5.2.0.tgz">https://charts.bitnami.com/bitnami/metrics-server-5.2.0.tgz</a>&quot;<br>  namespace  = &quot;kube-system&quot;</pre><pre>values = [&lt;&lt;EOF<br>apiService:<br>  create: true<br>  EOF<br>  ] <br>}</pre><pre>resource &quot;helm_release&quot; &quot;example&quot; {<br>  name  = &quot;redis&quot;<br>  chart = &quot;<a href="https://charts.bitnami.com/bitnami/redis-10.7.16.tgz">https://charts.bitnami.com/bitnami/redis-10.7.16.tgz</a>&quot;<br>}</pre><pre>resource &quot;helm_release&quot; &quot;spinnaker&quot; {<br>  name  = &quot;spin&quot;<br>  repository = &quot;<a href="https://helmcharts.opsmx.com/">https://helmcharts.opsmx.com</a>&quot;<br>  chart = &quot;spinnaker&quot;<br>  namespace = &quot;spinnaker&quot;<br>}</pre><p>The script will call the <strong>Kubernetes </strong>provider to <em>pass the credentials</em> to Helm provider(you can opt to <strong>kubeconfig </strong>though I prefer to use <strong>ca-certificate</strong> and <strong>token </strong>to authenticate against EKS cluster).</p><p>You should able to run the script and see the deployment ready in a bit, depending on the instance size and the charts you are installing, you might have to wait.</p><p><strong>Note</strong>: the Helm charts I have tested best be referenced as<strong> .tgz </strong>file as they are easier to refer on. You can still find the <strong>chart url </strong>and repo path but that will involve much trial and error.</p><p>For more information of Helm charts, checkout <a href="https://artifacthub.io/"><strong>helmhub</strong></a>.</p><p>Thanks and happy helming with Terraform.</p><p>I would love to hear from your input on how to make the tutorial series better. Please connect with me in <a href="https://www.linkedin.com/in/chee-seng-lu-0051b245/">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7125fc048647" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>