Kubernetes
Deploying RestBI in Kubernetes
Kubernetes is a powerful orchestration tool for managing containerized applications at scale. Below is an example of how to deploy RestBI using Kubernetes.
Create a Kubernetes Deployment
Create a restbi-deployment.yaml
file with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: restbi-deployment
spec:
replicas: 2
selector:
matchLabels:
app: restbi
template:
metadata:
labels:
app: restbi
spec:
containers:
- name: restbi
image: restbi/restbi-server:latest
ports:
- containerPort: 3000
env:
- name: DB_HOST
value: "postgres-service"
- name: DB_PORT
value: "5432"
- name: DB_USER
value: "youruser"
- name: DB_PASSWORD
value: "yourpassword"
- name: DB_NAME
value: "chinook"
- name: CORS_WHITELIST
value: "http://example.com,http://anotherdomain.com"
volumeMounts:
- name: custom-functions
mountPath: /app/custom-functions
volumes:
- name: custom-functions
hostPath:
path: /path/to/custom/functions
---
apiVersion: v1
kind: Service
metadata:
name: restbi-service
spec:
selector:
app: restbi
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer
The restbi-deployment.yaml
file sets up the RestBI server within a Kubernetes cluster. Here's what it does:
Deployment:
Replicas: Runs two instances (pods) of the RestBI server for redundancy.
Container:
Image: Uses
restbi/restbi-server:latest
.Ports: Exposes port 3000.
Environment Variables:
DB_HOST: Points to the PostgreSQL service (
postgres-service
).DB_PORT: Set to
5432
.DB_USER, DB_PASSWORD, DB_NAME: Database credentials.
CORS_WHITELIST: Specifies allowed domains for CORS.
Volume Mount: Mounts custom functions from the host to
/app/custom-functions
.
Service:
Type:
LoadBalancer
, making RestBI accessible externally.Ports: Maps incoming traffic on port 80 to port 3000 on the pods.
How It Works:
PostgreSQL Connection: RestBI connects to a PostgreSQL service (
postgres-service
) defined elsewhere in Kubernetes.High Availability: Two replicas ensure redundancy and basic load balancing.
Customization: Users can add custom functions via a mounted volume.
External Access: The LoadBalancer exposes RestBI to the outside world.
Apply the Deployments
To deploy the RestBI server on Kubernetes, run the following commands:
kubectl apply -f restbi-deployment.yaml
Last updated