Getting Started

The first steps in working with Opta.

Installation

One line installation (detailed instructions):

/bin/bash -c "$(curl -fsSL https://docs.opta.dev/install.sh)"

Opta works on AWS, GCP, and Azure - so make sure the appropriate cloud credentails are configured in your terminal.

Environment creation

In this step we will create an environment (example staging, qa, prod) for your organization.

You can use the CLI option described below or checkout our interactive app to build your first environment and service.

Start by running:

opta init env [aws/gcp/azure]

This will create an opta.yml file with initial configurations for your environment. Below are examples of the resulting yaml files for each environment.

name: aws-staging # A unique identifier for your environment
org_name: runx # A unique identifier for your organization
providers:
  aws:
    region: us-east-1 # Your aws region. You can find a list of them here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
    account_id: XXXX # Your 12 digit account id
modules:
  - type: base
  - type: k8s-cluster
  - type: k8s-base
name: gcp-staging # A unique identifier for your environment
org_name: runx # A unique identifier for your organization
providers:
  google:
    region: us-central1 # Your gcp region. You can find a list of them here: https://cloud.google.com/compute/docs/regions-zones
    project: my-project-name-1234 # the name of your GCP project
modules:
  - type: base
  - type: k8s-cluster
  - type: k8s-base
name: azure-staging # A unique identifier for your environment
org_name: runx # A unique identifier for your organization
providers:
  azurerm:
    location: centralus
    tenant_id: XXX
    subscription_id: YYY
modules:
  - type: base
  - type: k8s-cluster
  - type: k8s-base
Now, run:

opta apply

This step will create an EKS cluster for you and set up VPC, networking and various other infrastructure pieces.

Service creation

In this step we will create a service - which is basically a docker container and associated database. We will create another opta.yml file, which defines high level configuration of this service.

To get started, run

opta init service <YOUR_ENV_FILE_PATH> k8s

This will prompt you for some information and create a starting point for your opta.yml file. Then, update the fields specific to your service setup. You can see examples of resulting files below.

name: hello-world # service names are unique per-environment
environments:
  - name: staging
    path: "staging/opta.yml"
modules:
  - name: app
    type: k8s-service
    port:
      http: 80
    image: docker.io/kennethreitz/httpbin:latest # Or you can specify your own
    healthcheck_path: "/get"
    public_uri: all
    links:
      - db
  - name: db
    type: postgres # Will spawn a RDS database and credentials will be passed via env vars
name: hello-world # service names are unique per-environment
environments:
  - name: staging
    path: "staging/opta.yml"
modules:
  - name: app
    type: k8s-service
    port:
      http: 80
    image: docker.io/kennethreitz/httpbin:latest # Or you can specify your own
    healthcheck_path: "/get"
    public_uri: all
    links:
      - db
  - name: db
    type: postgres # Will spawn a Cloud SQL database and credentials will be passed via env vars
name: hello-world # service names are unique per-environment
environments:
  - name: staging
    path: "staging/opta.yml"
modules:
  - name: app
    type: k8s-service
    port:
      http: 80
    image: docker.io/kennethreitz/httpbin:latest # Or you can specify your own
    healthcheck_path: "/get"
    public_uri: all
    links:
      - db
  - name: db
    type: postgres # Will spawn a Cloud SQL database and credentials will be passed via env vars

Now you are ready to deploy your service.

Service Deployment

One line deployment:

opta apply

Now, once this step is complete, you should be to curl your service by specifying the load balancer url/ip.

Run output and note down load_balancer_raw_dns (AWS) or load_balancer_raw_ip (GCP and Azure).

Now you can:

  • Access your service at http://<ip-or-dns>/
  • SSH into the container by running opta shell
  • See logs by running opta logs

Cleanup

Once you’re finished playing around with these examples, you may clean up by running the following command from the environment directory:

opta destroy

Next steps


Last modified September 22, 2021: Updating latest references (62bb6e2)