# Kubernetes Operator - Expose DB to outside users

**URL:** <https://forums.percona.com/t/kubernetes-operator-expose-db-to-outside-users/14196>\
**Category:** Percona Operator for PostgreSQL\
**Created:** [February 1, 2022, 7:27pm UTC](https://forums.percona.com/t/kubernetes-operator-expose-db-to-outside-users/14196 "2022-02-01T19:27:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason123](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jason123](https://forums.percona.com/u/jason123)\
**Post date:** [February 1, 2022, 7:27pm UTC](https://forums.percona.com/t/kubernetes-operator-expose-db-to-outside-users/14196/1 "2022-02-01T19:27:18Z")

</div>

If I wanted to connect to the DB from outside of kubernetes aka another machine, what would the best way to handle it be? Do outside users connect to the operator in order to make queries? I just followed [Generic Kubernetes installation - Percona Operator for PostgreSQL](https://www.percona.com/doc/kubernetes-operator-for-postgresql/kubernetes.html) and for step 6, i just connected to the database with the command below. Should I expose the kubernetes operator port for other users to connect to the database or should I use a load balancer like HAProxy? Thanks!

```auto
$ kubectl run -i --rm --tty pg-client --image=perconalab/percona-distribution-postgresql:13.2 --restart=Never -- bash -il
[postgres@pg-client /]$ PGPASSWORD='pguser_password' psql -h cluster1-pgbouncer -p 5432 -U pguser pgdb

```

Also is there documentation on the 4 containers in the operator pod? apiserver, operator, scheduler, event?

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [February 2, 2022, 8:20am UTC](https://forums.percona.com/t/kubernetes-operator-expose-db-to-outside-users/14196/2 "2022-02-02T08:20:01Z")

</div>

Hello @jason123 ,

Operator is just tracking the Custom Resources and creates necessary k8s primitives to create the database.  
To connect to database you should expose pgbouncer.

```auto
  pgBouncer:
    image: perconalab/percona-postgresql-operator:main-ppg14-pgbouncer
# imagePullPolicy: Always
    size: 3
    resources:
      requests:
        cpu: "1"
        memory: "128Mi"
      limits:
        cpu: "2"
        memory: "512Mi"
    expose:
      serviceType: LoadBalancer

```

This will create a LoadBalancer service for pgbouncer. You can also expose it as a NodePort.

For me on GKE it looks like this:

```auto
$ kubectl get services
cluster1-pgbouncer LoadBalancer 10.52.9.49 35.238.XX.YY 5432:32508/TCP 26m

```

So now I connect from my machine to my PG cluster:

```auto
PGPASSWORD='pguser_password' psql -h 35.238.XX.YY -p 5432 -U pguser pgdb

```

Please let me know if it helps.
