diff --git a/kubernetes/README.md b/kubernetes/README.md new file mode 100644 index 0000000000..a928715ff1 --- /dev/null +++ b/kubernetes/README.md @@ -0,0 +1,60 @@ +# Habitica in Kubernetes +This is a set of sample Kubernetes configuration files to launch Habitica under AWS, both as a single-node web frontend as well as a multi-node web frontend. + +## Prerequisites +* An AWS account. +* A working Kubernetes installation. +* A basic understanding of how to use Kubernetes. https://kubernetes.io/ +* A persistent volume for MongoDB data. +* Docker images of Habitica. + + You can use your own, or use the one included in the YAML files. + + If you use your own, you'll need a fork of the Habitica GitHub repo and your own Docker Hub repo, both of which are free. + +## Before you begin +1. Set up Kubernetes. +2. Create an EBS volume for MongoDB data. + + Make a note of the name, you'll need it later. + +## Starting MongoDB +1. Edit mongo.yaml + + Find the volumeID line. + + Change the volume to the one created in the section above. +2. Run the following commands: + + `kubectl.sh create -f mongo.yaml` + + `kubectl.sh create -f mongo-service.yaml` +3. Wait for the MongoDB pod to start up. + +## Starting a Single Web Frontend + +1. Run the following commands: + + `kubectl.sh create -f habitica.yaml` + + `kubectl.sh create -f habitica-service.yaml` +2. Wait for the frontend to start up. + +## Starting Multi-node Web Frontend +1. Run the following commands : + + `kubectl.sh create -f habitica-rc.yaml` + + `kubectl.sh create -f habitica-service.yaml` +2. Wait for the frontend to start up. + +## Accessing Your Habitica web interface +Using `kubectl describe svc habiticaweb` get the hostname generated for the Habitica service. Open a browser and go to http://hostname:3000 to access the web front-end for the installations above. + +## Shutting down +Shutting down is basically done by reversing the steps above: ++ `kubectl.sh delete -f habitica-service.yaml` ++ `kubectl.sh delete -f habitica.yaml (or habitica-rc.yaml)` ++ `kubectl.sh delete -f mongo-service.yaml` ++ `kubectl.sh delete -f mongo.yaml` + +You can also just shut down all of Kubernetes as well. + +## Notes ++ MongoDB data will be persistent! If you need to start with a fresh database, you'll need to remove the volume and re-create it. ++ On AWS, you probably want to use at least t2.medium minion nodes for Kubernetes. The default t2.small is too small for more than two Habitica nodes. + +## Future Plans ++ Multi-node MongoDB. ++ Monitoring ++ Instructions for a better hostname. The default generated ones stink. ++ More to come.... diff --git a/kubernetes/habitica-rc.yaml b/kubernetes/habitica-rc.yaml new file mode 100644 index 0000000000..3049e5db77 --- /dev/null +++ b/kubernetes/habitica-rc.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: habitica + labels: + name: habitica +spec: + replicas: 4 + selector: + name: habitica + template: + metadata: + labels: + name: habitica + spec: + containers: + - name: habitica + image: ksonney/habitrpg:latest + env: + - name: NODE_DB_URI + value: mongodb://mongosvc/habitrpg + ports: + - containerPort: 3000 + hostPort: 3000 + name: habitica diff --git a/kubernetes/habitica-service.yaml b/kubernetes/habitica-service.yaml new file mode 100644 index 0000000000..e582e9cead --- /dev/null +++ b/kubernetes/habitica-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: habiticaweb + name: habiticaweb +spec: + ports: + # the port that this service should serve on + - port: 3000 + # label keys and values that must match in order to receive traffic for this service + selector: + name: habitica + type: LoadBalancer diff --git a/kubernetes/habitica.yaml b/kubernetes/habitica.yaml new file mode 100644 index 0000000000..e8ff29ea3c --- /dev/null +++ b/kubernetes/habitica.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Pod +metadata: + name: habitica + labels: + name: habitica +spec: + containers: +# - image: mongo:latest +# name: mongo +# ports: +# - containerPort: 27017 +# name: mongo + - image: ksonney/habitrpg:latest + name: habitica + env: + - name: NODE_DB_URI + value: mongodb://mongosvc/habitrpg + ports: + - containerPort: 3000 + hostPort: 3000 + name: habitica diff --git a/kubernetes/mongo-service.yaml b/kubernetes/mongo-service.yaml new file mode 100644 index 0000000000..743fd25676 --- /dev/null +++ b/kubernetes/mongo-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: mongosvc + name: mongosvc +spec: + ports: + # the port that this service should serve on + - port: 27017 + # label keys and values that must match in order to receive traffic for this service + selector: + name: mongodb diff --git a/kubernetes/mongo.yaml b/kubernetes/mongo.yaml new file mode 100644 index 0000000000..a769acefd0 --- /dev/null +++ b/kubernetes/mongo.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mongodb + labels: + name: mongodb +spec: + containers: + - resources: + limits : + cpu: 0.5 + image: mongo + name: mongodb + ports: + - containerPort: 27017 + hostPort: 27017 + name: mongo + volumeMounts: +# # name must match the volume name below + - name: mongo-persistent-storage +# # mount path within the container + mountPath: /data/db + volumes: + - name: mongo-persistent-storage + awsElasticBlockStore: + volumeID: aws://YOUR-REGION/YOUR-VOLNAME + fsType: ext3 +