Local Django on Kubernetes with Minikube

Bill Prin
Bill Prin
Dec 13, 2016 · 6 min read
Image for post
Image for post
Minikube

Minikube tips

$ minikube start --vm-driver=xhyve
$ minikube config set vm-driver=xhyve
$ eval $(minikube docker-env)
$ gcloud container cluster get-credentials mycluster # Container Engine context$ kubectl config use-context minikube # Minikube context

Persistent Volumes and Persistent Volume Claims

volumes:
- name: postgresdata
gcePersistentDisk:
# your disk name here
pdName: pg-data
fsType: ext4
- name: secrets
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
volumes:
- name: postgresdata
persistentVolumeClaim:
claimName:
postgres-data
apiVersion: v1
kind: PersistentVolume
metadata:
name:
pv0001
spec:
accessModes:
- ReadWriteOnce
capacity:
storage:
5Gi
gcePersistentDisk:
pdName:
pg-data
fsType: ext4
apiVersion: v1
kind: PersistentVolume
metadata:
name:
pv0001
spec:
accessModes:
- ReadWriteOnce
capacity:
storage:
5Gi
hostPath:
path:
/data/pv0001/

Load Balancers

$ kubectl get services
$ minikube service guestbook

Port forwarding

$ kubectl port-forward <posgtres-pod> 5432:5432 &$ kubectl port-forward <redis-pod> 6379:6379 &

Hot reloads via host mounts

gunicorn --reload -b :$PORT mysite.wsgi
# in guestbook container volumeMounts:
- name: reload
mountPath: /app
volumes:
- name: reload
hostPath:
path: /Users/waprin/code/django_postgres_redis/guestbook

Getting In Touch

Google Cloud - Community

Google Cloud community articles and blogs

Bill Prin

Written by

Bill Prin

Python, Data,Infrastructure, etc.

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Bill Prin

Written by

Bill Prin

Python, Data,Infrastructure, etc.

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store