Integrate Kubernetes with Tiger Cloud
Automate deployment, scaling, and management of your containerized workloads
Kubernetes is an open-source container orchestration system that automates the deployment, scaling, and management of containerized applications. You can connect Kubernetes to Tiger Cloud, and deploy TimescaleDB within your Kubernetes clusters.
This guide explains how to connect a Kubernetes cluster to Tiger Cloud, configure persistent storage, and deploy TimescaleDB in your kubernetes cluster.
Prerequisites
Section titled “Prerequisites”To follow the steps on this page:
- Self-managed Kubernetes or a Kubernetes Turnkey Cloud Solution.
- kubectl for command-line interaction with your cluster.
Integrate TimescaleDB in a Kubernetes cluster
Section titled “Integrate TimescaleDB in a Kubernetes cluster”To connect your Kubernetes cluster to your Tiger Cloud service:
-
Create a default namespace for your Tiger Cloud components
-
Create a namespace:
Terminal window kubectl create namespace timescale -
Set this namespace as the default for your session:
Terminal window kubectl config set-context --current --namespace=timescale
For more information, see Kubernetes Namespaces.
-
-
Create a Kubernetes secret that stores your Tiger Cloud service credentials
Update the following command with your connection details, then run it:
Terminal window kubectl create secret generic timescale-secret \--from-literal=PGHOST=<host> \--from-literal=PGPORT=<port> \--from-literal=PGDATABASE=<dbname> \--from-literal=PGUSER=<user> \--from-literal=PGPASSWORD=<password> -
Configure network access to Tiger Cloud
-
Managed Kubernetes: outbound connections to external databases like Tiger Cloud work by default. Make sure your cluster’s security group or firewall rules allow outbound traffic to Tiger Cloud IP.
-
Self-hosted Kubernetes: If your cluster is behind a firewall or running on-premise, you may need to allow egress traffic to Tiger Cloud. Test connectivity using your connection details:
Terminal window nc -zv <host> <port>If the connection fails, check your firewall rules.
-
-
Create a Kubernetes deployment that can access your Tiger Cloud
Run the following command to apply the deployment:
Terminal window kubectl apply -f - <<EOFapiVersion: apps/v1kind: Deploymentmetadata:name: timescale-appspec:replicas: 1selector:matchLabels:app: timescale-apptemplate:metadata:labels:app: timescale-appspec:containers:- name: timescale-containerimage: postgres:latestenvFrom:- secretRef:name: timescale-secretEOF -
Test the connection
-
Create and run a pod that uses the connection details you added to
timescale-secretin thetimescalenamespace:Terminal window kubectl run test-pod --image=postgres --restart=Never \--env="PGHOST=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGHOST}' | base64 --decode)" \--env="PGPORT=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGPORT}' | base64 --decode)" \--env="PGDATABASE=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGDATABASE}' | base64 --decode)" \--env="PGUSER=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGUSER}' | base64 --decode)" \--env="PGPASSWORD=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGPASSWORD}' | base64 --decode)" \-- sleep infinity -
Launch a psql shell in the
test-podyou just created:Terminal window kubectl exec -it test-pod -- bash -c "psql -h \$PGHOST -U \$PGUSER -d \$PGDATABASE"
You start a
psqlsession connected to your Tiger Cloud service. -
Running TimescaleDB on Kubernetes is similar to running PostgreSQL. This procedure outlines the steps for a non-distributed system.
To connect your Kubernetes cluster to self-hosted TimescaleDB running in the cluster:
- Create a default namespace for Tiger Data components
-
Create the Tiger Data namespace:
Terminal window kubectl create namespace tigerdata -
Set this namespace as the default for your session:
Terminal window kubectl config set-context --current --namespace=tigerdata
For more information, see Kubernetes Namespaces.
-
- Set up a persistent volume claim (PVC) storage
To manually set up a persistent volume and claim for self-hosted Kubernetes, run the following command:
kubectl apply -f - <<EOFapiVersion: v1kind: PersistentVolumeClaimmetadata:name: tigerdata-pvcspec:accessModes:- ReadWriteOnceresources:requests:storage: 10GiEOF - Deploy TimescaleDB as a StatefulSet
By default, the TimescaleDB HA Docker image you are installing on Kubernetes uses the default PostgreSQL database, user and password. This image includes TimescaleDB and TimescaleDB Toolkit. To deploy TimescaleDB on Kubernetes, run the following command:
kubectl apply -f - <<EOFapiVersion: apps/v1kind: StatefulSetmetadata:name: timescaledbspec:serviceName: timescaledbreplicas: 1selector:matchLabels:app: timescaledbtemplate:metadata:labels:app: timescaledbspec:containers:- name: timescaledbimage: 'timescale/timescaledb-ha:pg18'env:- name: POSTGRES_USERvalue: postgres- name: POSTGRES_PASSWORDvalue: postgres- name: POSTGRES_DBvalue: postgres- name: PGDATAvalue: /var/lib/postgresql/data/pgdataports:- containerPort: 5432volumeMounts:- mountPath: /var/lib/postgresql/dataname: tigerdata-storagevolumes:- name: tigerdata-storagepersistentVolumeClaim:claimName: tigerdata-pvcEOF - Allow applications to connect by exposing TimescaleDB within Kuberneteskubectl apply -f - <<EOFapiVersion: v1kind: Servicemetadata:name: timescaledbspec:selector:app: timescaledbports:- protocol: TCPport: 5432targetPort: 5432type: ClusterIPEOF
- Create a Kubernetes secret to store the database credentials
Terminal window kubectl create secret generic tigerdata-secret \--from-literal=PGHOST=timescaledb \--from-literal=PGPORT=5432 \--from-literal=PGDATABASE=postgres \--from-literal=PGUSER=postgres \--from-literal=PGPASSWORD=postgres - Deploy an application that connects to TimescaleDB
Terminal window kubectl apply -f - <<EOFapiVersion: apps/v1kind: Deploymentmetadata:name: tigerdata-appspec:replicas: 1selector:matchLabels:app: tigerdata-apptemplate:metadata:labels:app: tigerdata-appspec:containers:- name: tigerdata-containerimage: postgres:latestenvFrom:- secretRef:name: tigerdata-secretEOF - Test the database connection
-
Create and run a pod to verify database connectivity using your connection details saved in
tigerdata-secret:Terminal window kubectl run test-pod --image=postgres --restart=Never \--env="PGHOST=$(kubectl get secret tigerdata-secret -o=jsonpath='{.data.PGHOST}' | base64 --decode)" \--env="PGPORT=$(kubectl get secret tigerdata-secret -o=jsonpath='{.data.PGPORT}' | base64 --decode)" \--env="PGDATABASE=$(kubectl get secret tigerdata-secret -o=jsonpath='{.data.PGDATABASE}' | base64 --decode)" \--env="PGUSER=$(kubectl get secret tigerdata-secret -o=jsonpath='{.data.PGUSER}' | base64 --decode)" \--env="PGPASSWORD=$(kubectl get secret tigerdata-secret -o=jsonpath='{.data.PGPASSWORD}' | base64 --decode)" \-- sleep infinity -
Launch the PostgreSQL interactive shell within the created
test-pod:Terminal window kubectl exec -it test-pod -- bash -c "psql -h \$PGHOST -U \$PGUSER -d \$PGDATABASE"
You see the PostgreSQL interactive terminal.
-
You have successfully integrated Kubernetes with Tiger Cloud.