Deploy and Configure StackGres

You'll need to create an Oracle Container Engine for Kubernetes cluster, deploy StackGres on it, and then create your database.

Before you begin, you'll need to get your OCI architecture set up. The following instructions assume you have everything besides your Kubernetes cluster and database ready.

Create a Kubernetes Cluster

Create a Oracle Cloud Infrastructure Container Engine for Kubernetes instance in your compartment for the StackGres deployment.

  1. From the OCI console main menu, select Developer Services.
  2. Under Containers & Artifacts, select Kubernetes Clusters (OKE).
    Any existing clusters in your compartment are listed in a table.
  3. Click the Create cluster button.
  4. In the Create cluster dialog, select Quick create and click Submit.
    The Quick create option will create all the network resources you need for this deployment, including subnets. If you have already configured subnets, you can use the Custom create option instead.
  5. In the Create cluster (quick) wizard, provide values for the following fields and options, and then click Next.
    For example, these are some typical values for a small (3 CPU) deployment:
  6. In the Review step, the Resources to be created page gives a summary of cluster, network, and node pool information. Carefully review all of the displayed information and if it is correct, click Create cluster.
    The Creating cluster and associated network resources page is shown. Each component to be created is listed with a status that is updated as the automated process completes. The process typically takes around 15 minutes to complete.
When the Kubernetes cluster creation is complete, you can proceed to install StackGres on the cluster.

Install StackGres Using Cloud Shell

Install StackGres on your new Kubernetes cluster by using the Oracle Cloud Infrastructure Cloud Shell command line interface.

  1. In the OCI Console, nagivate to the Cluster details page for your Kubernetes cluster. You will need the information shown here for the following steps.
  2. In the top bar of the OCI console, next to the Region drop down menu, click the code icon and select Cloud Shell.
    After a few moments, the CLI opens. The console and prompt show your username, tenancy, region, and home folder.
  3. Use the create-kubeconfig command with the Cluster ID value shown on your Cluster details page, and your region:
    oci ce cluster create-kubeconfig --cluster-id your_cluster_id --file $HOME/.kube/config --region your_region --token-version 2.0.0 --kube-endpoint PUBLIC_ENDPOINT
  4. Verify that the Kubernetes nodes have started up correctly:
    kubectl get nodes
    The console output should list each of your nodes with their IP addresses and status of Ready.
  5. Validate that the pods have also started up correctly:
    kubectl get pods -A
    The console output should list all of the pods in the kube-system namespace as Running.
  6. Add the StackGres installation repository, using the package installation:
    helm repo add stackgres-charts https://stackgres.io/downloads/stackgres-k8s/stackgres/helm/
    The console output should indicate that the repository was added succesfully.
  7. Run the installation:
    helm install --create-namespace --namespace stackgres stackgres-operator stackgres-charts/stackgres-operator
    The installation will take about five minutes to run.
The console will output a message that the STATUS is deployed, followed by a list of helpful commands, including the command with the URI for the StackGres Operator UI and the get secret commands for generating the admin username and password. Copy all of this output to a text file for later reference.

Configure the Service

Configure the StackGres service using the Oracle Cloud Infrastructure Cloud Shell, and then log in to the StackGres UI.

  1. From Cloud Shell, edit the service configuration file by changing the Type field from ClusterIP to LoadBalancer:
    kubectl edit services stackgres-restapi -n stackgres
    The console loads the configuration file into the default text editor, such as vi. Under spec: locate the type: field and change the value to LoadBalancer. In vi, press the Esc key and then type :wq to save the file.
  2. Get the reference name of the service:
    kubectl get pods -n stackgres –w
    copy the name of the stackgres-restapi pod. For example, stackgres-restapi-684df1e9b-gx455.
  3. Expose the service to access the web console:
    kubectl expose pod your_stackgres-restapi-pod -n stackgres --type LoadBalancer --port 9443 --name admin-console
    The console output should be service/admin-console exposed.
  4. Get the IP and access port for the service:
    kubectl get services -n stackgres –w
    The console output will include a line for admin-console. Copy the values for the external-IP and the port. You can access the console using the url https://<external-ip>:<port>/admin/index.html
  5. Generate a username and password for the console by using the get secret commands provided when you ran the install:

    kubectl get secret -n stackgres stackgres-restapi --template '{{ printf "username = %s\n" (.data.k8sUsername | base64decode) }}'

    kubectl get secret -n stackgres stackgres-restapi --template '{{ printf "password = %s\n" (.data.clearPassword | base64decode) }}'

    Copy the username and password.
  6. Log in to the StackGres console. Navigate to the console using the URL you created in Step 4, and log in using the username and password you generated in Step 5.
  7. In the Select a namespace dropdown, select the namespace you created during installation. For example, stackgres.
You can manage your StackGres instance from the StackGres console.

Create a Database

Create and access a database in your StackGres cluster by using the StackGres console.

  1. From the StackGres console, select StackGres Clusters. Then click the link create a new one? in the table.
  2. In the Create Cluster wizard, enter values for your PostgreSQL database instances and then click Create Cluster. For example, to create three instances for a highly-available production environment:
    When the clusters are created, they are shown in the console with the status Active.
  3. Click View Connection Info to see some useful commands, including the kubectl commands for connecting to the Postgres client psql in Cloud Shell. For example:
    kubectl -n stackgres exec -ti prod-0 -c postgres-util – psql
Your PostgreSQL deployment is now up and running on OCI.