# First steps

> Deploy and verify a Trino cluster with Stackable Operator. Access via CLI or web interface, and clean up after testing.

After going through the [Installation](https://docs.stackable.tech/home/stable/trino/getting_started/installation/index.md) section and having installed all the operators, you will now deploy a Trino cluster and the required dependencies. Afterwards you can [verify that it works](https://docs.stackable.tech/home/stable/trino/getting_started/first_steps/index.md) by running some queries against Trino or visit the Trino web interface.

## Setup Trino

A working Trino cluster and its web interface require only the commons, secret and listener operators to work. Simple tests are possible without an external data source (e.g. PostgreSQL, Hive or S3), as internal data can be used.

Create a file named `trino.yaml` with the following content:

```yaml
---
apiVersion: trino.stackable.tech/v1alpha1
kind: TrinoCluster
metadata:
  name: simple-trino
spec:
  image:
    productVersion: "481"
  clusterConfig:
    catalogLabelSelector:
      matchLabels:
        trino: simple-trino
  coordinators:
    roleConfig:
      listenerClass: external-unstable
    roleGroups:
      default:
        replicas: 1
  workers:
    roleGroups:
      default:
        replicas: 1
```

and apply it:

```bash
kubectl apply -f trino.yaml
```

Wait for the Trino cluster to get ready:

```bash
kubectl rollout status --watch --timeout=5m statefulset/simple-trino-coordinator-default
kubectl rollout status --watch --timeout=5m statefulset/simple-trino-worker-default
```

## Verify that it works

At first, make sure the StatefulSets are ready:

```bash
kubectl get statefulset
```

The output should show all pods in the StatefulSets ready:

```
NAME                                 READY   AGE
simple-trino-coordinator-default     1/1     5m
simple-trino-worker-default          1/1     5m
```

Create a port-forward for the coordinator to access Trino easily in the next steps:

```bash
kubectl port-forward svc/simple-trino-coordinator 8443 2>&1 >/dev/null &
```

### Access the Trino cluster via CLI tool

We use the [Trino CLI tool](https://trino.io/download.html) to access the Trino cluster. This link points to the latest Trino version. In this guide we keep Trino cluster and client versions in sync and download the CLI tool from the [Stackable repository](https://repo.stackable.tech/):

```bash
curl --fail --output trino.jar https://repo.stackable.tech/repository/packages/trino-cli/trino-cli-481
```

We need to make the CLI tool executable:

```bash
chmod +x trino.jar
```

Now, run some queries against the coordinator. Show available catalogs:

```bash
./trino.jar --insecure --output-format=CSV_UNQUOTED --server https://localhost:8443 --user admin --execute "SHOW CATALOGS"
```

which should output:

```
system
```

Check how many workers are connected to the coordinator:

```bash
./trino.jar --insecure --output-format=CSV_UNQUOTED --server https://localhost:8443 --user admin --execute "SELECT COUNT(*) as nodes FROM system.runtime.nodes WHERE coordinator=false AND state='active'"
```

which should output:

```
1
```

Congratulations, you set up your first Stackable Trino cluster successfully.

### Access the Trino web interface

To open the Trino UI in your browser you either have to start a port forwarding process or use `stackablectl` to obtain the node URL. Either way, log in with the `admin` user name. Since no authentication is enabled you do not need to enter a password.

With the port-forward still active, you can connect to the Trino web interfaceby pointing your browser to `[https://localhost:8443/ui](https://localhost:8443/ui)`.

Using `stackablectl` you can obtain the direct Trino endpoint like this:

```bash
❯ stackablectl stacklet list

┌─────────┬──────────────┬───────────┬───────────────────────────────────────────────┬─────────────────────────────────┐
│ PRODUCT ┆ NAME         ┆ NAMESPACE ┆ ENDPOINTS                                     ┆ CONDITIONS                      │
╞═════════╪══════════════╪═══════════╪═══════════════════════════════════════════════╪═════════════════════════════════╡
│ trino   ┆ simple-trino ┆ default   ┆ coordinator-https  https://192.168.49.2:32129 ┆ Available, Reconciling, Running │
└─────────┴──────────────┴───────────┴───────────────────────────────────────────────┴─────────────────────────────────┘----
```

In this case, point your browser to `[https://192.168.49.2:32129](https://192.168.49.2:32129)`.

> **Warning:** Your browser will probably show a security risk warning because it does not trust the self generated TLS certificates. Just ignore that and continue.

After logging in you should see the Trino web interface:

![trino web ui](https://docs.stackable.tech/home/stable/trino/_images/trino-web-ui.png)

If you mark the `Finished` button in the `Query Details` section, you should see the two queries that were sent earlier via the CLI tool:

![trino web ui finished](https://docs.stackable.tech/home/stable/trino/_images/trino-web-ui-finished.png)

## Clean up

In order to remove the previously downloaded CLI tool, you can safely remove it from your system:

```
rm trino.jar
```

## What’s next

Have a look at the [Usage guide](https://docs.stackable.tech/home/stable/trino/usage-guide/index.md) to find out more about how to configure a Trino cluster.
