Skip to content

Instantly share code, notes, and snippets.

@nowylie
Created April 9, 2020 01:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowylie/d97f9907012ee6006951b524b0cb9734 to your computer and use it in GitHub Desktop.
Save nowylie/d97f9907012ee6006951b524b0cb9734 to your computer and use it in GitHub Desktop.

The following sets up a local k3d cluster and deploys Postgres and Hasura GraphQL Engine.

NOTE: All data will be lost when containers restart

# Create the cluster mapping NodePorts to Host ports and set KUBECONFIG
k3d create --publish 5432:30032 --publish 8080:30080 --workers 2
export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')"

# Deploy postgres
kubectl apply -f postgres.yaml

# Deploy graphql-engine
kubectl apply -f graphql-engine.yaml

# Check that it works
hasura console
# Hasura CLI config
endpoint: http://localhost:8080
admin_secret: myadminsecretkey
apiVersion: apps/v1
kind: Deployment
metadata:
name: graphql-engine
labels:
app: graphql-engine
spec:
replicas: 1
selector:
matchLabels:
app: graphql-engine
template:
metadata:
labels:
app: graphql-engine
spec:
containers:
- name: graphql-engine
image: hasura/graphql-engine:v1.1.1
env:
- name: HASURA_GRAPHQL_DATABASE_URL
value: postgres://postgres:password@postgres:5432/postgres
- name: HASURA_GRAPHQL_ADMIN_SECRET
value: myadminsecretkey
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: graphql-engine
spec:
selector:
app: graphql-engine
type: NodePort
ports:
- nodePort: 30080
port: 8080
targetPort: 8080
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:12-alpine
env:
- name: POSTGRES_DB
value: postgres
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_PASSWORD
value: password
ports:
- containerPort: 5432
---
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
selector:
app: postgres
type: NodePort
ports:
- nodePort: 30032
port: 5432
targetPort: 5432
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment