DEV Community

Cover image for How to Deploy Your First Kubernetes Cluster
Nočnica Fee for Run [X]

Posted on

How to Deploy Your First Kubernetes Cluster

originally published on Towards AWS

Today every company is heading towards container and container management tools like Kubernetes. Thanks to cloud providers like AWS, we can launch Kubernetes Cluster in a few minutes, instead of installing everything by ourselves.

Unfortunately, having a K8s cluster up and running is only half the struggle and we still need to worry about things like DNS, service discovery, or managing permissions and privileges within our cluster.

This is all fine if we have a bunch of DevOps Engineers or Cloud Engineers available, but decent IT professionals are hard to come by and most companies simply don’t have the luxury of idle employees sitting around and waiting for new work.
For this reason, I was pretty curious as I stumbled about Opta.

What is Opta?

Opta is a deployment tool developed by RUN [X] and promises to create a fully operational K8S Cluster and launch your microservices without any DevOps headaches. To provide an agnostic approach to the different cloud providers it uses Terraform to deploy new resources to your infrastructure. To make use of the different services that the cloud providers offer it comes with its own modules to directly connect your microservices with external databases, caches, or object stores.

To take care of all internal communication Opta uses a Linkerd service mesh, which provides mTLS, load balancing, retries, and a lot more security features. By default, all microservices are launched in a private subnet created by Opta, which makes them inaccessible from the internet. If you want to enable a service to be accessable directly from the internet, you can specify an URL that will automatically be created in your DNS settings and routed to the container. Additionally, every service gets an internal-only domain name that is resolveable and can be used by other services for direct communication.

Without any need of advanced configuration or deep knowledge in Kubernets, you are able to create and run a fully operational K8S cluster, ready to host your microservices. This is especial useful if you don’t have the man power or knowledge to create and manage everything on your own and want to rather concentrate on deploying new services instead of going through all the trouble of configuring the cluster itself.

Deploy your first K8S Cluster

To get started you have to download and install Optas own CLI. The CLI is used to apply and deploy your resources, get access to stored secrets and connect your Kubernetes CLI directly with the deployed cluster.

After installing the CLI, Opta works with an Infrastructure-as-Code approach, where you create all infrastructure and services within a yml file, similiar to Terraform itself. The configurations files are separated in “environment” and “service” files. In your “environment” configuration files, you define your AWS, GCP, or Azure account and your Kubernetes cluster. You can create different providers in one file and specifiy which provider to use when you run the apply CLI command. A tipical environment configuration file can look like this:

name: devstage
org_name: xcloud
providers:
  aws:
    region: eu-central-1
    account_id: 
modules:
  - type: base
  - type: k8s-cluster
  - type: k8s-base
  - type: dns
    domain: 
    delegated: false                                                                     
Enter fullscreen mode Exit fullscreen mode

Under modules you can choose predefined modules which creates the default settings for your cluster and even create specific resourcen your cloud provider offers. A more detailed explanation of the modules can be found directly on their website.

With those few lines of code Opta creates the Kubernetes Cluster, including a VPC, setting up subnets, taking care of DNS and service discovery, and all the security aspects and monitoring. Without anything to worry about you have a fully operational K8s Cluster in roughly 20min.

Deploying microservices is equally easy, even if you decide to connect them directly to an Postgres or MySQL database, a redis cache or an object store. For this, you simply have to create a service configuration file in which you define the docker container or Helm chart you want to deploy. Describe all environment variables you need, use Opta modules for any external resources and specify a port and URL to open up your service to the world. \
A sample service configuration file could look like this:

name: sourcegraph
environments:
  - name: devstage
    path: "../opta.yml"
modules:
  - name: sourcegraph
    type: k8s-service
    image: sourcegraph/server:3.28.0
    port:
      http: 7080
    resource_request:
      cpu: 1000
      memory: 512 
    public_uri: "sourcegraph.{parent.domain}"      
    env_vars:
      - name: "PGSSLMODE"
        value: "require"
      - name: "PGPORT"
        value: "5432"
      - name: "CODEINTEL_PGSSLMODE"
        value: "require"
      - name: "CODEINTEL_PGPORT"
        value: "5432"
    links:
      - dbfrontend:
        - db_user: PGUSER
          db_host: PGHOST
          db_name: PGDATABASE
          db_password: PGPASSWORD
      - dbcodeintel:
        - db_user: CODEINTEL_PGUSER
          db_host: CODEINTEL_PGHOST
          db_name: CODEINTEL_PGDATABASE
          db_password: CODEINTEL_PGPASSWORD
  - name: dbfrontend
    type: postgres
    instance_class: db.r5.large
    engine_version: 12.4
  - name: dbcodeintel
    type: postgres
    instance_class: db.r5.large
    engine_version: 12.4
Enter fullscreen mode Exit fullscreen mode

Opta takes care of passing all connection information for the database directly to the service. Additionally, it takes care of all internal routing and attaches the right permissions to the service.

All the credentials will be stored in secrets and can be viewed via Optas CLI. If you want to directly communicate with your Cluster or services, the CLI can automatically configure the Kubernetes CLI with the need information. After a few seconds you are ready to list your pods, services or deployments by simply using the right kubectl commands.

Help and Support

Currently, you can find all documentation and information on the RUN [X] website. There you’ll find a guide for your first installation and deployment, all information about the different modules and integrations like Datadog.

If you need further help or support you can join their Slack Channel where you always find someone from RUN [X] who is eager to help you out.

If you want a look directly into the code or checkout other example on how to deploy your microservice with Opta you can check out their Github Repository to get more information.

Summary

Kubernetes is great for managing your various microservices and container but is pretty complex and difficult. Many of us have neither the time, man power or knowledge to take care of all the settings and configurations which are necessary to let the cluster run smoothly.

Opta is a great tool to assist you in configuring and launching your own cluster, taking care of all the underlying configuration and resources. It lets you concentrate on launching new services and increase your productivity without to sacrifise security or mantainability.

Discussion (0)