Getting started with Opta on GCP.


One line installation (detailed instructions):

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

Make sure the gcp 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 gcp

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

name: staging # A unique identifier for your environment
org_name: runx # A unique identifier for your organization
    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
  - type: base
  - type: k8s-cluster
  - type: k8s-base

Now, run:

opta apply -c staging.yml

This step will create an GKE cluster for you and set up 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 hello-world.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 hello-world.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
  - name: staging
    path: "staging.yml"
  - name: app
    type: k8s-service
      http: 80
    image: docker.io/kennethreitz/httpbin:latest # Or you can specify your own
    healthcheck_path: "/get"
    public_uri: all
      - 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 -c hello-world.yml

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_ip`.

Now you can:

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


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

opta destroy -c hello-world.yml
opta destroy -c staging.yml

Next steps