In this tutorial we'll go over how to enable repeatable, effective, straightforward application deployments by automatically deploying Kubernetes resources to an Amazon EKS cluster.
During every application deployment plan, there are two primary questions that come up:
We’ll answer question 2 here.
When you’re figuring out the best method to deploy an application, it comes down to what is repeatable, effective, and straightforward. The last thing engineering teams want to do is manually run commands on their local terminal to get an application up.
In this blog post, you’ll learn how to automatically deploy Kubernetes resources to an EKS cluster using env0.
Amazon Elastic Kubernetes Service (AWS EKS) is a managed service to run Kubernetes on Amazon Web Services AWS cloud and on-premises.
Years ago, when engineers wanted to deploy an application to a server, it went something like this:
Today there are much more efficient methods to get this workflow configured.
The truth is, engineers don’t want to be bogged down by mundane, manual tasks and engineering leadership doesn’t want to waste time by manually deploying binaries to get an application up and running.
The whole idea behind automated and repeatable processes is to make engineers’ lives easier and have long-lasting deployments that are effective. Removing the manual effort and ensuring effective deployments are the primary reasons you want to use containerized applications and automate infrastructure deployments.
When it comes to Kubernetes applications, it’s far easier to automate a workload. Because an application is already containerized once it reaches the “Kubernetes phase”, the primary piece an engineer has to worry about is ensuring a proper Kubernetes Manifest is used with a valid container spec that will deploy applications and individual services.
Once the Kubernetes Manifest is valid, it can then be deployed. That’s where env0 comes into play.
To follow along with the hands-on portion of this blog post, you will need:
To automatically deploy a Kubernetes resource, you’ll need a Kubernetes resource to use. The below configuration is a Kubernetes Deployment resource/object that does the following:
Save the following Kubernetes Manifest in GitHub or another source control system to be used later with env0.
While env0 is used a lot for Infrastructure as Code deployments, it's also fully compatible with Kubernetes containerized application deployments: a GitOps platform alternative to deploying manually.
Engineers don't want to in most cases deploy or run Kubernetes Manifests from their local computer. It’s neither scalable nor efficient. Also, it creates a major blocker in getting teams to work together on the deployments. At the same time, some organizations may not be ready to implement a true GitOps platform as it can be fairly complex and a heavy lift.
Deploying with env0 is a solid middle ground.
Prior to deploying a resource/object to Kubernetes, you’ll need a way to connect to your Kubernetes clusters. This is where env0 configuration files come into play.
In the code below, you’ll see that there’s an [.code]aws eks[.code] command running that pulls down the kubeconfig on the environment that’s being created via env0. This way, you have the ability to connect to the Kubernetes cluster.
- name: nginxdeployment
- containerPort: 80
You’ll want to store this code in the same repository as the NGINX configuration in the previous section and call the file [.code]env0.yaml[.code].
Your Git repository should look like the screenshot below, which shows the [.code]nginx.yaml[.code].
Once the code setup is complete, you can create variables for the [.code]nginx.yaml[.code] and the [.code]env0.yaml[.code] in the same repository. [.code]AWS_DEFAULT_REGION[.code] and [.code]CLUSTER_NAME[.code] that contains the appropriate values. For example, below the values show
that the cluster name is [.code]k8senv-cluster[.code] and it’s deployed in [.code]us-east-1[.code].
Ensure that you create environment variables for this configuration and not Terraform variables as in the screenshot below.
Inside the project of your choosing, click the green + CREATE NEW ENVIRONMENT button.
You have two options when creating an environment:
VCS pulls the Terraform configuration directly from GitHub. Choose the VCS option as that’s where the Kubernetes Manifest for resource creation exists.
Next, choose Kubernetes as the IaC type and click next.
Choose the source control system in which you stored the Terraform code.
When you choose a source control system, you’ll be prompted to authenticate to it.
Once authenticated, you’ll be able to choose the repo where the Kubernetes Manifest exists along with the branch name.
On the variables page, you should see that the variables you created in the previous section are shown.
Give your environment a name and click DONE.
Once the environment is created in the previous section, you’ll see that the deployment has started.
Once complete, you should see that all steps were successfully deployed.
You can also see in the “K8S Apply” step that the NGINX resource was created.
You can also confirm that the Nginx configuration was created by running the following command against the Kubernetes cluster: [.code]kubectl get pods[.code]
The output should be similar to the screenshot below.
Congratulations! You've deployed Kubernetes clusters running your containerized applications!
This is part three of a four-part series. Keep reading to learn more!