Skip to content

Commit 91c0b81

Browse files
committed
First commit with all basics of how to setup Metaflow for Kubernetes.
0 parents  commit 91c0b81

15 files changed

+424
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scripts/

Metaflow_service/Readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Metaflow Service
2+
3+
- Creates the Pods and Services for the Metaflow metadata service.
4+
- Setups:
5+
- Postgres : Service, Deployment, Persistant Volume and Persistant Volume
6+
- Metaflow_Service : Deployment,service
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: apps/v1
2+
kind: Deployment # Type of the kubernetes resource
3+
metadata:
4+
name: metaflow-database # Name of the deployment
5+
labels: # Labels applied to this deployment
6+
app: metaflow-database
7+
spec:
8+
selector:
9+
matchLabels: # This deployment applies to the Pods matching the specified labels
10+
app: metaflow-database
11+
tier: postgres
12+
replicas: 1
13+
template: # Template for the Pods in this deployment
14+
metadata:
15+
labels: # Labels to be applied to the Pods in this deployment
16+
app: metaflow-database
17+
tier: postgres
18+
spec: # The spec for the containers that will be run inside the Pods in this deployment
19+
containers:
20+
- image: postgres:latest # The container image
21+
name: postgres
22+
imagePullPolicy: "IfNotPresent"
23+
envFrom: # Get the environmental variables from a secret file whose name is "postgres-secret"
24+
- secretRef:
25+
name: postgres-secret
26+
27+
ports:
28+
- containerPort: 5432 # The port that the container exposes
29+
name: postgres
30+
volumeMounts:
31+
- mountPath: /var/lib/postgresql/data
32+
name: postgres-persistent-storage # This name should match the name specified in `volumes.name`
33+
volumes: # A PersistentVolume is mounted as a volume to the Pod
34+
- name: postgres-persistent-storage
35+
persistentVolumeClaim:
36+
claimName: postgres-pv-claim
37+
38+
39+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: PersistentVolume # Create a PV
3+
metadata:
4+
name: postgres-pv-volume
5+
labels:
6+
type: local
7+
app: metaflow-database
8+
spec:
9+
storageClassName: manual # Storage class. A PV Claim requesting the same storageClass can be bound to this volume.
10+
capacity:
11+
storage: 5Gi
12+
accessModes:
13+
- ReadWriteMany
14+
hostPath: # hostPath PersistentVolume is used for development and testing. It uses a file/directory on the Node to emulate network-attached storage
15+
path: "/mnt/data"
16+
persistentVolumeReclaimPolicy: Retain # Retain the PV even after PVC is deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim # Create a PersistentVolumeClaim to request a PersistentVolume storage
3+
metadata: # Claim name and lab-pv-claim
4+
name: postgres-pv-claim
5+
labels:
6+
app: metaflow-database
7+
spec: # Access mode and resource limits
8+
storageClassName: manual # Request a certain storage class
9+
accessModes:
10+
- ReadWriteMany # ReadWriteMany means the volume can be mounted as read-write by many Nodes
11+
resources:
12+
requests:
13+
storage: 5Gi
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1 # API version
2+
kind: Service # Type of kubernetes resource
3+
metadata:
4+
name: metaflow-database # Name of the resource
5+
labels: # Labels that will be applied to the resource
6+
app: metaflow-database
7+
spec:
8+
type: NodePort
9+
ports:
10+
- port: 5432
11+
selector: # Selects any Pod with labels `app=fullstack-postgres,tier=postgres`
12+
app: metaflow-database
13+
tier: postgres

Metaflow_service/deleter.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kubectl delete -f postgres-secret.yaml
2+
3+
# $ Create the PG Db in the Kube Cluster.
4+
kubectl delete -f database/postgres-db-pv.yaml
5+
kubectl delete -f database/postgres-db-pvc.yaml
6+
kubectl delete -f database/postgres-db-deployment.yaml
7+
kubectl delete -f database/postgres-db-service.yaml
8+
9+
# $ Create the service once the app is created.
10+
kubectl delete -f service_app/metaflow-metadata-service-deployment.yaml
11+
kubectl delete -f service_app/metaflow-metadata-service.yaml
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: postgres-secret
5+
type: Opaque
6+
stringData: # We dont need to worry about converting to base64
7+
POSTGRES_USER: 'metaflow_service'
8+
POSTGRES_PASSWORD: 'r4nd0mp455w07d'
9+
POSTGRES_DB: 'metaflow'
10+
MF_METADATA_DB_NAME: 'metaflow'
11+
MF_METADATA_DB_HOST: 'metaflow-database'
12+
MF_METADATA_DB_PORT: '5432'
13+
API_SECRET: '98hbun98h'
14+
MF_METADATA_DB_USER: 'metaflow_service'
15+
MF_METADATA_DB_PSWD: 'r4nd0mp455w07d'
16+
DB_NAME: 'metaflow'
17+
DB_PORT: '5432'
18+

Metaflow_service/runner.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kubectl create -f postgres-secret.yaml
2+
3+
# $ Create the PG Db in the Kube Cluster.
4+
kubectl apply -f database/postgres-db-pv.yaml
5+
kubectl apply -f database/postgres-db-pvc.yaml
6+
kubectl apply -f database/postgres-db-deployment.yaml
7+
kubectl apply -f database/postgres-db-service.yaml
8+
9+
# $ Create the service once the app is created.
10+
kubectl apply -f service_app/metaflow-metadata-service-deployment.yaml
11+
kubectl apply -f service_app/metaflow-metadata-service.yaml
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: apps/v1
2+
kind: Deployment # Type of the kubernetes resource
3+
metadata:
4+
name: metaflow-metadata-service # Name of the Kubernetes resource
5+
labels:
6+
app: metaflow-metadata-service
7+
spec:
8+
replicas: 1 # Number of pods to run at any given time
9+
selector:
10+
matchLabels:
11+
app: metaflow-metadata-service # This deployment applies to any Pods matching the specified label
12+
template: # This deployment will create a set of pods using the configurations in this template
13+
metadata:
14+
labels: # The labels that will be applied to all of the pods in this deployment
15+
app: metaflow-metadata-service
16+
spec: # Spec for the container which will run in the Pod
17+
containers:
18+
- name: metaflow-metadata-service
19+
image: netflixoss/metaflow_metadata_service # The image we are getting from dockerhub
20+
imagePullPolicy: IfNotPresent # If we have not pulled it before, get it from dockerhub
21+
ports:
22+
- name: http
23+
containerPort: 8080 # Should match the port number that the Go application listens on
24+
envFrom:
25+
- secretRef:
26+
name: postgres-secret # Name of the secret environmental variable file to load
27+
28+

0 commit comments

Comments
 (0)