diff --git a/k8s/README.md b/k8s/README.md new file mode 100644 index 000000000..09da200d1 --- /dev/null +++ b/k8s/README.md @@ -0,0 +1,15 @@ +This document is a short guide about running the dockerized version of Routr Server on Kubernetes. + +## Run in Kubernetes + +To run Routr in Kubernetes, you must set your ROUTR_EXTERN_ADDR in `k8s/routr.yml`. + +> This variable must be set to the public address(if running Routr locally, use your host address) + +Additionally, you must create the following Kubernetes resources: + +```bash +kubectl create -f k8s/configmaps.yml +kubectl create -f k8s/redis.yml +kubectl create -f k8s/routr.yml +``` diff --git a/k8s/boostrap.yaml b/k8s/configmaps.yml similarity index 70% rename from k8s/boostrap.yaml rename to k8s/configmaps.yml index d2b61fc37..24272ce43 100644 --- a/k8s/boostrap.yaml +++ b/k8s/configmaps.yml @@ -1,7 +1,20 @@ apiVersion: v1 kind: ConfigMap metadata: - name: routr-bootstrap + name: entrypoint +data: + entrypoint.sh: |- + while ! nc -z redis 6379; do sleep 0.1; done # Wait for Redis + cd /opt/routr + ./run.sh & + while ! nc -z localhost 4567; do sleep 0.1; done # Wait for Sip I/O + ./rctl create -f bootstrap.yml + while sleep 3600; do :; done +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: bootstrap data: bootstrap.yml: |- - apiVersion: v1draft1 diff --git a/k8s/gcs/config.yaml b/k8s/gcs/config.yaml deleted file mode 100644 index e2e24f5ae..000000000 --- a/k8s/gcs/config.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: routr-config -data: - config.yml: |- - apiVersion: v1draft1 - spec: - recordRoute: true - registrarIntf: Internal - useToAsAOR: true - transport: - - protocol: udp - port: 5060 - - protocol: tcp - port: 5060 - logging: - traceLevel: 0 diff --git a/k8s/gcs/entrypoint.yaml b/k8s/gcs/entrypoint.yaml deleted file mode 100644 index dd3c77074..000000000 --- a/k8s/gcs/entrypoint.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: routr-entrypoint -data: - entrypoint.sh: |- - ./opt/routr/run.sh & - while ! nc -z localhost 4567; do sleep 0.1; done - ./opt/routr/rctl create -f /opt/routr/bootstrap.yml - while sleep 3600; do :; done diff --git a/k8s/gcs/service.yaml b/k8s/gcs/service.yaml deleted file mode 100644 index 15ed52b56..000000000 --- a/k8s/gcs/service.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: routr - labels: - app: routr -spec: - type: LoadBalancer - externalTrafficPolicy: Local # This will cause the load balancer to send the client ip - ports: - - name: sip - port: 5060 - - name: https - port: 443 - targetPort: 4567 - selector: - app: routr - tier: signaling diff --git a/k8s/redis.yml b/k8s/redis.yml new file mode 100644 index 000000000..9ca89063f --- /dev/null +++ b/k8s/redis.yml @@ -0,0 +1,36 @@ +apiVersion: v1 +kind: Service +metadata: + name: redis + labels: + app: routr +spec: + ports: + - port: 6379 + selector: + app: routr + tier: database + clusterIP: None +--- +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: redis + labels: + app: routr +spec: + strategy: + type: Recreate + template: + metadata: + labels: + app: routr + tier: database + spec: + containers: + - name: redis + image: redis:4.0.5-alpine + imagePullPolicy: Always + ports: + - containerPort: 6379 + name: redis diff --git a/k8s/gcs/deployment.yaml b/k8s/routr.yml similarity index 53% rename from k8s/gcs/deployment.yaml rename to k8s/routr.yml index 6d954ed59..0e2b2a01d 100644 --- a/k8s/gcs/deployment.yaml +++ b/k8s/routr.yml @@ -1,3 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: + name: routr + labels: + app: routr +spec: + type: NodePort + externalTrafficPolicy: Local # This will cause the load balancer to send the client ip + externalIPs: + - 192.168.1.127 + ports: + - name: sip + port: 5060 + - name: https + port: 4567 + selector: + app: routr + tier: sip +--- apiVersion: extensions/v1beta1 kind: Deployment metadata: @@ -11,7 +31,7 @@ spec: metadata: labels: app: routr - tier: signaling + tier: sip spec: containers: - name: routr @@ -20,35 +40,28 @@ spec: command: ["/bin/sh"] args: ["-c", "sh /opt/routr/entrypoint.sh"] env: - # Uncommend to point to an external redis - #- name: ROUTR_DS_PROVIDER - # value: 'redis_data_provider' - #- name: ROUTR_DS_PARAMETERS - # value: 'host=redis,port=6379' + - name: ROUTR_DS_PROVIDER + value: redis_data_provider + - name: ROUTR_DS_PARAMETERS + value: 'host=redis,port=6379' - name: ROUTR_EXTERN_ADDR - value: '35.231.210.78' # This must be set manually (for now...) + value: '192.168.1.127' ports: - containerPort: 5060 name: sip - containerPort: 4567 name: https volumeMounts: - - name: routr-config - mountPath: /opt/routr/config/config.yml - subPath: config.yml - - name: routr-entrypoint + - name: entrypoint mountPath: /opt/routr/entrypoint.sh subPath: entrypoint.sh - - name: routr-bootstrap + - name: bootstrap mountPath: /opt/routr/bootstrap.yml subPath: bootstrap.yml volumes: - - name: routr-config - configMap: - name: routr-config - - name: routr-entrypoint + - name: entrypoint configMap: - name: routr-entrypoint - - name: routr-bootstrap + name: entrypoint + - name: bootstrap configMap: - name: routr-bootstrap + name: bootstrap