From eb05be95f056bcbdba85769956e94fd7edf5dc15 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 7 Jun 2017 09:11:05 -0500 Subject: [PATCH] feat: add k8s config. (#237) --- README.md | 45 ++++++++++++++++++++++++++++++++ k8s/gorush-deployment.yaml | 27 +++++++++++++++++++ k8s/gorush-service.yaml | 16 ++++++++++++ k8s/redis-master-deployment.yaml | 18 +++++++++++++ k8s/redis-master-service.yaml | 16 ++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 k8s/gorush-deployment.yaml create mode 100644 k8s/gorush-service.yaml create mode 100644 k8s/redis-master-deployment.yaml create mode 100644 k8s/redis-master-service.yaml diff --git a/README.md b/README.md index 433dd60..e620b36 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ A push notification micro server using [Gin](https://github.com/gin-gonic/gin) f - [Android Example](#android-example) - [Response body](#response-body) - [Run gorush in Docker](#run-gorush-in-docker) +- [Run gorush in Kubernetes](#run-gorush-in-kubernetes) - [License](#license) ## Support Platform @@ -673,6 +674,50 @@ $ http -v --verify=no --json GET http://your.docker.host/api/stat/go ![statue screenshot](screenshot/status.png) +## Run gorush in Kubernetes + +Please make sure you are install [Minikube](https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/) first. + +### Create a Minikube cluster + +```sh +$ minikube start --vm-driver=xhyve +``` + +### Quick Start + +Start the gorush with one command: + +```sh +$ kubectl create -f k8s +deployment "frontend" created +service "frontend" created +deployment "redis-master" created +service "redis-master" created +``` + +Then, list all your Services: + +```sh +$ kubectl get services +NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE +frontend 10.0.0.156 8088:32517/TCP 30s +kubernetes 10.0.0.1 443/TCP 14d +redis-master 10.0.0.67 6379/TCP 30s +``` + +### view the gorush home page + +```sh +$ minikube service frontend +``` + +### Clean up the gorush: + +```sh +$ kubectl delete -f k8s +``` + ## License Copyright 2016 Bo-Yi Wu [@appleboy](https://twitter.com/appleboy). diff --git a/k8s/gorush-deployment.yaml b/k8s/gorush-deployment.yaml new file mode 100644 index 0000000..5d01002 --- /dev/null +++ b/k8s/gorush-deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: 3 + template: + metadata: + labels: + app: gorush + tier: frontend + spec: + containers: + - name: gorush + image: appleboy/gorush + command: ["/gorush"] + args: ["-c", "config.yml", "-e", "redis", "--redis-addr", "redis-master:6379"] + env: + - name: GET_HOSTS_FROM + # value: dns + # If your cluster config does not include a dns service, then to + # instead access environment variables to find service host + # info, comment out the 'value: dns' line above, and uncomment the + # line below: + value: env + ports: + - containerPort: 8088 diff --git a/k8s/gorush-service.yaml b/k8s/gorush-service.yaml new file mode 100644 index 0000000..546d00c --- /dev/null +++ b/k8s/gorush-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: frontend + labels: + app: gorush + tier: frontend +spec: + # if your cluster supports it, uncomment the following to automatically create + # an external load-balanced IP for the frontend service. + type: LoadBalancer + ports: + - port: 8088 + selector: + app: gorush + tier: frontend diff --git a/k8s/redis-master-deployment.yaml b/k8s/redis-master-deployment.yaml new file mode 100644 index 0000000..9646255 --- /dev/null +++ b/k8s/redis-master-deployment.yaml @@ -0,0 +1,18 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: redis-master +spec: + replicas: 1 + template: + metadata: + labels: + app: redis + role: master + tier: backend + spec: + containers: + - name: master + image: redis + ports: + - containerPort: 6379 diff --git a/k8s/redis-master-service.yaml b/k8s/redis-master-service.yaml new file mode 100644 index 0000000..a484014 --- /dev/null +++ b/k8s/redis-master-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: redis-master + labels: + app: redis + role: master + tier: backend +spec: + ports: + - port: 6379 + targetPort: 6379 + selector: + app: redis + role: master + tier: backend