You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by as...@apache.org on 2018/08/08 12:28:41 UTC
[incubator-servicecomb-service-center] branch master updated:
SCB-815 Support deploy in Kubernetes (#411)
This is an automated email from the ASF dual-hosted git repository.
asifdxtreme pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new e5a485e SCB-815 Support deploy in Kubernetes (#411)
e5a485e is described below
commit e5a485e3e04ab9ecf152f52bccfd64c12914951d
Author: little-cui <su...@qq.com>
AuthorDate: Wed Aug 8 20:28:39 2018 +0800
SCB-815 Support deploy in Kubernetes (#411)
---
docs/README.md | 10 ++-
integration/docker/README.md | 20 +++++
integration/docker/docker-compose.yml | 53 ++++++++++++++
integration/docker/prometheus.yml | 33 +++++++++
integration/k8s/README.md | 52 +++++++++++++
integration/k8s/service-center/.helmignore | 21 ++++++
integration/k8s/service-center/Chart.yaml | 4 +
.../k8s/service-center/charts/etcd/Chart.yaml | 4 +
.../charts/etcd/templates/_helpers.tpl | 16 ++++
.../charts/etcd/templates/deployment.yaml | 20 +++++
.../k8s/service-center/charts/etcd/values.yaml | 24 ++++++
integration/k8s/service-center/templates/NOTES.txt | 19 +++++
.../k8s/service-center/templates/_helpers.tpl | 16 ++++
.../k8s/service-center/templates/deployment.yaml | 85 ++++++++++++++++++++++
.../k8s/service-center/templates/ingress.yaml | 32 ++++++++
.../k8s/service-center/templates/service.yaml | 47 ++++++++++++
integration/k8s/service-center/values.yaml | 51 +++++++++++++
scripts/build/tools.sh | 7 +-
scripts/docker/build-frontend-image/start.sh | 2 +-
scripts/docker/build-image/start.sh | 4 +-
server/api.go | 35 ++++++++-
server/core/proto/services.go | 4 -
server/server.go | 31 ++------
23 files changed, 551 insertions(+), 39 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 5a9f8aa..eb144af 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -14,9 +14,15 @@
- [Making Front-end Image](/scripts/docker/build-frontend-image)
-#### Deploy Service-Center
+#### Deploy Service-Center Locally
-- [Cluster Deployment](/docs/sc-cluster.md)
+- [In Docker](/integration/docker)
+
+#### Deploy Service-Center Cluster
+
+- [In Kubernetes Cluster](/integration/k8s)
+
+- [In VM](/docs/sc-cluster.md)
- [Deploy with TLS](/docs/security-tls.md)
diff --git a/integration/docker/README.md b/integration/docker/README.md
new file mode 100644
index 0000000..c55d1b1
--- /dev/null
+++ b/integration/docker/README.md
@@ -0,0 +1,20 @@
+# Integrate with Docker
+
+A simple demo to deploy ServiceCenter in docker environment.
+
+## Quick Start
+
+```bash
+cd $PROJECT_ROOT/integration/docker
+docker-compose up
+```
+This will start up ServiceCenter listening on `:30100` for handling requests and Dashboard listening on `:30103`.
+
+## Confirm ServiceCenter is Running
+
+You can also point your browser to `http://${NODE}:30103` to view the dashboard of ServiceCenter.
+
+## Next
+
+ServiceCenter already integrate with Prometheus,
+you can get more metrics of ServiceCenter in Grafana, [see](/docs/integration-grafana.md)
\ No newline at end of file
diff --git a/integration/docker/docker-compose.yml b/integration/docker/docker-compose.yml
new file mode 100644
index 0000000..6fd50b7
--- /dev/null
+++ b/integration/docker/docker-compose.yml
@@ -0,0 +1,53 @@
+version: '3'
+services:
+ prometheus:
+ depends_on:
+ - service-center
+ image: 'prom/prometheus:latest'
+ # restart: always
+ volumes:
+ - ./prometheus.yml:/etc/prometheus/prometheus.yml
+ ports:
+ - "9090:9090"
+
+ grafana:
+ depends_on:
+ - prometheus
+ image: 'grafana/grafana:latest'
+ # restart: always
+ ports:
+ - "3000:3000"
+ volumes:
+ - grafana_data:/var/lib/grafana
+
+ etcd:
+ image: 'quay.io/coreos/etcd:latest'
+ # restart: always
+ environment:
+ ETCD_ADVERTISE_CLIENT_URLS: http://etcd:2379
+ ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
+ ETCD_INITIAL_ADVERTISE_PEER_URLS: http://etcd:2380
+ ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
+ ETCD_INITIAL_CLUSTER: default=http://etcd:2380
+
+ service-center:
+ depends_on:
+ - etcd
+ image: 'servicecomb/service-center:latest'
+ # restart: always
+ ports:
+ - "30100:30100"
+ environment:
+ BACKEND_ADDRESS: etcd:2379
+
+ scfrontend:
+ depends_on:
+ - service-center
+ image: 'servicecomb/scfrontend:latest'
+ # restart: always
+ ports:
+ - "30103:30103"
+ environment:
+ BACKEND_ADDRESS: http://service-center:30100
+volumes:
+ grafana_data:
diff --git a/integration/docker/prometheus.yml b/integration/docker/prometheus.yml
new file mode 100644
index 0000000..514df3b
--- /dev/null
+++ b/integration/docker/prometheus.yml
@@ -0,0 +1,33 @@
+# my global config
+global:
+ scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
+ evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
+ # scrape_timeout is set to the global default (10s).
+
+# Alertmanager configuration
+alerting:
+ alertmanagers:
+ - static_configs:
+ - targets:
+ # - alertmanager:9093
+
+# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
+rule_files:
+ # - "first_rules.yml"
+ # - "second_rules.yml"
+
+# A scrape configuration containing exactly one endpoint to scrape:
+# Here it's Prometheus itself.
+scrape_configs:
+ # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
+ - job_name: 'prometheus'
+
+ # metrics_path defaults to '/metrics'
+ # scheme defaults to 'http'.
+
+ static_configs:
+ - targets: ['prometheus:9090']
+
+ - job_name: 'service-center'
+ static_configs:
+ - targets: ['service-center:30100']
diff --git a/integration/k8s/README.md b/integration/k8s/README.md
new file mode 100644
index 0000000..2398882
--- /dev/null
+++ b/integration/k8s/README.md
@@ -0,0 +1,52 @@
+# Integrate with Kubernetes
+
+A simple demo to deploy ServiceCenter Cluster in Kubernetes.
+
+## Quick Start
+
+### Requirements
+
+1. There is a Kubernetes cluster.
+1. Already install `kubectl` and `helm client` in your local machine.
+1. (Optional) Already deploy helm tiller on Kubernetes.
+
+### 1. Use Kubectl
+
+You can use the command `kubectl apply` to deploy ServiceCenter cluster.
+
+```bash
+cd ${PROJECT_ROOT}/integration/k8s
+kubectl apply -f <(helm template --name servicecomb --namespace default service-center/)
+```
+
+### 2. Use Helm Install
+
+You can also use the helm commands to deploy ServiceCenter cluster if you already deploy helm tiller.
+
+```bash
+cd ${PROJECT_ROOT}/integration/k8s
+helm install --name servicecomb --namespace default service-center/
+```
+
+### Confirm the deploy is ok
+
+By default, the ServiceCenter frontend use `NodePort` service type to deploy in Kubernetes.
+
+1. You can execute the command `kubectl get pod`, to check all pods are running.
+1. You can also point your browser to `http://${NODE}:30103` to view the dashboard of ServiceCenter.
+
+## Clean up
+
+If you use the kubectl to deploy
+
+```bash
+cd ${PROJECT_ROOT}/integration/k8s
+kubectl delete -f <(helm template --name servicecomb --namespace default service-center/)
+```
+
+If you use helm tiller to deploy
+
+```bash
+cd ${PROJECT_ROOT}/k8s
+helm delete --purge servicecomb
+```
\ No newline at end of file
diff --git a/integration/k8s/service-center/.helmignore b/integration/k8s/service-center/.helmignore
new file mode 100644
index 0000000..f0c1319
--- /dev/null
+++ b/integration/k8s/service-center/.helmignore
@@ -0,0 +1,21 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
diff --git a/integration/k8s/service-center/Chart.yaml b/integration/k8s/service-center/Chart.yaml
new file mode 100644
index 0000000..ca77875
--- /dev/null
+++ b/integration/k8s/service-center/Chart.yaml
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: service-center
+version: 0.1.0
diff --git a/integration/k8s/service-center/charts/etcd/Chart.yaml b/integration/k8s/service-center/charts/etcd/Chart.yaml
new file mode 100644
index 0000000..7b56bd9
--- /dev/null
+++ b/integration/k8s/service-center/charts/etcd/Chart.yaml
@@ -0,0 +1,4 @@
+apiVersion: v1
+description: A Helm chart for Kubernetes
+name: etcd
+version: 0.1.0
diff --git a/integration/k8s/service-center/charts/etcd/templates/_helpers.tpl b/integration/k8s/service-center/charts/etcd/templates/_helpers.tpl
new file mode 100644
index 0000000..823660b
--- /dev/null
+++ b/integration/k8s/service-center/charts/etcd/templates/_helpers.tpl
@@ -0,0 +1,16 @@
+{{/* vim: set filetype=mustache: */}}
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "etcd.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+*/}}
+{{- define "etcd.fullname" -}}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
diff --git a/integration/k8s/service-center/charts/etcd/templates/deployment.yaml b/integration/k8s/service-center/charts/etcd/templates/deployment.yaml
new file mode 100644
index 0000000..ac3dddd
--- /dev/null
+++ b/integration/k8s/service-center/charts/etcd/templates/deployment.yaml
@@ -0,0 +1,20 @@
+apiVersion: "etcd.database.coreos.com/v1beta2"
+kind: "EtcdCluster"
+metadata:
+ ## Adding this annotation make this cluster managed by clusterwide operators
+ ## namespaced operators ignore it
+ # annotations:
+ # etcd.database.coreos.com/scope: clusterwide
+ annotations:
+ {{- range $key, $value := .Values.cluster.annotations }}
+ {{ $key }}: {{ $value | quote }}
+ {{- end }}
+ name: {{ template "etcd.fullname" . }}
+ labels:
+ app: {{ template "etcd.name" . }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ size: {{ .Values.etcdCluster.size }}
+version: {{ .Values.etcdCluster.version }}
diff --git a/integration/k8s/service-center/charts/etcd/values.yaml b/integration/k8s/service-center/charts/etcd/values.yaml
new file mode 100644
index 0000000..f14c902
--- /dev/null
+++ b/integration/k8s/service-center/charts/etcd/values.yaml
@@ -0,0 +1,24 @@
+# Default values for etcd.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+etcdOperator:
+ image:
+ pullPolicy: IfNotPresent
+backupOperator:
+ image:
+ pullPolicy: IfNotPresent
+restoreOperator:
+ image:
+ pullPolicy: IfNotPresent
+etcdCluster:
+ name: etcd-cluster
+ size: 3
+ version: 3.2.13
+ image:
+ pullPolicy: IfNotPresent
+cluster:
+ annotations:
+ ## Adding this annotation make this cluster managed by clusterwide operators
+ ## namespaced operators ignore it
+ # annotations:
+ # etcd.database.coreos.com/scope: clusterwide
diff --git a/integration/k8s/service-center/templates/NOTES.txt b/integration/k8s/service-center/templates/NOTES.txt
new file mode 100644
index 0000000..478cddb
--- /dev/null
+++ b/integration/k8s/service-center/templates/NOTES.txt
@@ -0,0 +1,19 @@
+1. Get the application URL by running these commands:
+{{- if .Values.sc.ingress.enabled }}
+{{- range .Values.sc.ingress.hosts }}
+ http://{{ . }}
+{{- end }}
+{{- else if contains "NodePort" .Values.sc.service.type }}
+ export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "service-center.fullname" . }})
+ export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
+ echo http://$NODE_IP:$NODE_PORT
+{{- else if contains "LoadBalancer" .Values.sc.service.type }}
+ NOTE: It may take a few minutes for the LoadBalancer IP to be available.
+ You can watch the status of by running 'kubectl get svc -w {{ template "service-center.fullname" . }}'
+ export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "service-center.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
+ echo http://$SERVICE_IP:{{ .Values.sc.service.externalPort }}
+{{- else if contains "ClusterIP" .Values.sc.service.type }}
+ export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "service-center.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
+ echo "Visit http://127.0.0.1:8080 to use your application"
+ kubectl port-forward $POD_NAME 8080:{{ .Values.sc.service.internalPort }}
+{{- end }}
diff --git a/integration/k8s/service-center/templates/_helpers.tpl b/integration/k8s/service-center/templates/_helpers.tpl
new file mode 100644
index 0000000..654de69
--- /dev/null
+++ b/integration/k8s/service-center/templates/_helpers.tpl
@@ -0,0 +1,16 @@
+{{/* vim: set filetype=mustache: */}}
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "service-center.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+*/}}
+{{- define "service-center.fullname" -}}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
diff --git a/integration/k8s/service-center/templates/deployment.yaml b/integration/k8s/service-center/templates/deployment.yaml
new file mode 100644
index 0000000..d253799
--- /dev/null
+++ b/integration/k8s/service-center/templates/deployment.yaml
@@ -0,0 +1,85 @@
+{{- $serviceName := include "service-center.fullname" . -}}
+{{- $servicePort := .Values.sc.service.externalPort -}}
+---
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+ name: {{ template "service-center.fullname" . }}
+ labels:
+ app: {{ template "service-center.name" . }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ replicas: {{ .Values.sc.replicaCount }}
+ template:
+ metadata:
+ labels:
+ app: {{ template "service-center.name" . }}
+ release: {{ .Release.Name }}
+ spec:
+ containers:
+ - name: {{ .Chart.Name }}
+ image: "{{ .Values.sc.image.repository }}:{{ .Values.sc.image.tag }}"
+ imagePullPolicy: {{ .Values.sc.image.pullPolicy }}
+ ports:
+ - containerPort: {{ .Values.sc.service.internalPort }}
+ env:
+ - name: BACKEND_ADDRESS
+ value: http://{{ .Release.Name }}-etcd-client:2379
+ livenessProbe:
+ httpGet:
+ path: /
+ port: {{ .Values.sc.service.internalPort }}
+ readinessProbe:
+ httpGet:
+ path: /
+ port: {{ .Values.sc.service.internalPort }}
+ resources:
+{{ toYaml .Values.sc.resources | indent 12 }}
+ {{- if .Values.sc.nodeSelector }}
+ nodeSelector:
+{{ toYaml .Values.sc.nodeSelector | indent 8 }}
+ {{- end }}
+
+---
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+ name: {{ template "service-center.fullname" . }}-frontend
+ labels:
+ app: {{ template "service-center.name" . }}-frontend
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ replicas: {{ .Values.frontend.replicaCount }}
+ template:
+ metadata:
+ labels:
+ app: {{ template "service-center.name" . }}-frontend
+ release: {{ .Release.Name }}
+ spec:
+ containers:
+ - name: {{ .Chart.Name }}-frontend
+ image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}"
+ imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
+ ports:
+ - containerPort: {{ .Values.frontend.service.internalPort }}
+ env:
+ - name: BACKEND_ADDRESS
+ value: http://{{ $serviceName }}:{{ $servicePort }}
+ livenessProbe:
+ httpGet:
+ path: /
+ port: {{ .Values.frontend.service.internalPort }}
+ readinessProbe:
+ httpGet:
+ path: /
+ port: {{ .Values.frontend.service.internalPort }}
+ resources:
+{{ toYaml .Values.frontend.resources | indent 12 }}
+ {{- if .Values.frontend.nodeSelector }}
+ nodeSelector:
+{{ toYaml .Values.frontend.nodeSelector | indent 8 }}
+ {{- end }}
diff --git a/integration/k8s/service-center/templates/ingress.yaml b/integration/k8s/service-center/templates/ingress.yaml
new file mode 100644
index 0000000..58ca39e
--- /dev/null
+++ b/integration/k8s/service-center/templates/ingress.yaml
@@ -0,0 +1,32 @@
+{{- if .Values.sc.ingress.enabled -}}
+{{- $serviceName := include "service-center.fullname" . -}}
+{{- $servicePort := .Values.sc.service.externalPort -}}
+apiVersion: extensions/v1beta1
+kind: Ingress
+metadata:
+ name: {{ template "service-center.fullname" . }}
+ labels:
+ app: {{ template "service-center.name" . }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+ annotations:
+ {{- range $key, $value := .Values.sc.ingress.annotations }}
+ {{ $key }}: {{ $value | quote }}
+ {{- end }}
+spec:
+ rules:
+ {{- range $host := .Values.sc.ingress.hosts }}
+ - host: {{ $host }}
+ http:
+ paths:
+ - path: /v4/
+ backend:
+ serviceName: {{ $serviceName }}
+ servicePort: {{ $servicePort }}
+ {{- end -}}
+ {{- if .Values.sc.ingress.tls }}
+ tls:
+{{ toYaml .Values.sc.ingress.tls | indent 4 }}
+ {{- end -}}
+{{- end -}}
diff --git a/integration/k8s/service-center/templates/service.yaml b/integration/k8s/service-center/templates/service.yaml
new file mode 100644
index 0000000..1a0e9a4
--- /dev/null
+++ b/integration/k8s/service-center/templates/service.yaml
@@ -0,0 +1,47 @@
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ template "service-center.fullname" . }}
+ labels:
+ app: {{ template "service-center.name" . }}
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ type: {{ .Values.sc.service.type }}
+ ports:
+ - port: {{ .Values.sc.service.externalPort }}
+ targetPort: {{ .Values.sc.service.internalPort }}
+ {{ if eq .Values.sc.service.type "NodePort" }}
+ nodePort: {{ .Values.sc.service.externalPort }}
+ {{ end }}
+ protocol: TCP
+ name: {{ .Values.sc.service.name }}
+ selector:
+ app: {{ template "service-center.name" . }}
+ release: {{ .Release.Name }}
+
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ template "service-center.fullname" . }}-frontend
+ labels:
+ app: {{ template "service-center.name" . }}-frontend
+ chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
+ release: {{ .Release.Name }}
+ heritage: {{ .Release.Service }}
+spec:
+ type: {{ .Values.frontend.service.type }}
+ ports:
+ - port: {{ .Values.frontend.service.externalPort }}
+ targetPort: {{ .Values.frontend.service.internalPort }}
+ {{ if eq .Values.frontend.service.type "NodePort" }}
+ nodePort: {{ .Values.frontend.service.externalPort }}
+ {{ end }}
+ protocol: TCP
+ name: {{ .Values.frontend.service.name }}
+ selector:
+ app: {{ template "service-center.name" . }}-frontend
+ release: {{ .Release.Name }}
diff --git a/integration/k8s/service-center/values.yaml b/integration/k8s/service-center/values.yaml
new file mode 100644
index 0000000..52e8cef
--- /dev/null
+++ b/integration/k8s/service-center/values.yaml
@@ -0,0 +1,51 @@
+# Default values for service-center.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+frontend:
+ replicaCount: 2
+ image:
+ repository: servicecomb/scfrontend
+ tag: latest
+ pullPolicy: IfNotPresent
+ service:
+ name: scfrontend
+ type: NodePort
+ externalPort: 30103
+ internalPort: 30103
+
+sc:
+ replicaCount: 2
+ image:
+ repository: servicecomb/service-center
+ tag: latest
+ pullPolicy: IfNotPresent
+ service:
+ name: service-center
+ type: ClusterIP
+ externalPort: 30100
+ internalPort: 30100
+
+ ingress:
+ enabled: false
+ # Used to create an Ingress record.
+ hosts:
+ - service-center.local
+ annotations:
+ # kubernetes.io/ingress.class: nginx
+ # kubernetes.io/tls-acme: "true"
+ tls:
+ # Secrets must be manually created in the namespace.
+ # - secretName: chart-example-tls
+ # hosts:
+ # - chart-example.local
+ resources: {}
+ # We usually recommend not to specify default resources and to leave this as a conscious
+ # choice for the user. This also increases chances charts run on environments with little
+ # resources, such as Minikube. If you do want to specify resources, uncomment the following
+ # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
+ # limits:
+ # cpu: 100m
+ # memory: 128Mi
+ # requests:
+ # cpu: 100m
+ # memory: 128Mi
diff --git a/scripts/build/tools.sh b/scripts/build/tools.sh
index b964359..5933711 100644
--- a/scripts/build/tools.sh
+++ b/scripts/build/tools.sh
@@ -102,11 +102,8 @@ package() {
local app=$PACKAGE_PREFIX-$PACKAGE-$GOOS-$GOARCH
cp -r etc/conf $app/
- sed -i 's/# manager_name = \"sc-0\"/manager_name = \"sr-0\"/g' $app/conf/app.conf
- sed -i 's/# manager_addr = \"http:\/\/127.0.0.1:2380\"/manager_addr = \"http:\/\/127.0.0.1:2380\"/g' $app/conf/app.conf
- sed -i 's/# manager_cluster = \"sc-0=http:\/\/127.0.0.1:2380\"/manager_cluster = \"sr-0=http:\/\/127.0.0.1:2380\"/g' $app/conf/app.conf
- sed -i 's/manager_cluster = \"127.0.0.1:2379\"/# manager_cluster = \"127.0.0.1:2379\"/g' $app/conf/app.conf
- sed -i 's/registry_plugin = etcd/registry_plugin = embeded_etcd/g' $app/conf/app.conf
+ sed -i 's/^manager_cluster.*=.*/manager_name = \"sr-0\"\nmanager_addr = \"http:\/\/127.0.0.1:2380\"\nmanager_cluster = \"sr-0=http:\/\/127.0.0.1:2380\"/g' $app/conf/app.conf
+ sed -i 's/^registry_plugin.*=.*/registry_plugin = embeded_etcd/g' $app/conf/app.conf
## Copy the Service-Center Releases
cp -r scripts/release/LICENSE $app/
diff --git a/scripts/docker/build-frontend-image/start.sh b/scripts/docker/build-frontend-image/start.sh
index 6093469..3163dd0 100644
--- a/scripts/docker/build-frontend-image/start.sh
+++ b/scripts/docker/build-frontend-image/start.sh
@@ -21,7 +21,7 @@ umask 027
cd /opt/frontend
-sed -i 's/^frontend_host_ip.*=.*$/frontend_host_ip = 0.0.0.0/g' conf/app.conf
+sed -i "s/^frontend_host_ip.*=.*$/frontend_host_ip = $(hostname)/g" conf/app.conf
sc_ip_port=${BACKEND_ADDRESS#*//}
sc_ip=${sc_ip_port%:*}
diff --git a/scripts/docker/build-image/start.sh b/scripts/docker/build-image/start.sh
index 02ab677..b960105 100644
--- a/scripts/docker/build-image/start.sh
+++ b/scripts/docker/build-image/start.sh
@@ -21,11 +21,11 @@ umask 027
cd /opt/service-center
-sed -i 's/^httpaddr.*=.*$/httpaddr = 0.0.0.0/g' conf/app.conf
+sed -i "s/^httpaddr.*=.*$/httpaddr = $(hostname)/g" conf/app.conf
if [ ! -z "${BACKEND_ADDRESS}" ]; then
sed -i "s|^registry_plugin.*=.*$|registry_plugin = etcd|g" conf/app.conf
- sed -i "s|^# manager_cluster.*=.*$|manager_cluster = ${BACKEND_ADDRESS}|g" conf/app.conf
+ sed -i "s|^manager_cluster.*=.*$|manager_cluster = ${BACKEND_ADDRESS}|g" conf/app.conf
fi
./service-center
\ No newline at end of file
diff --git a/server/api.go b/server/api.go
index 8783d51..7f7bdcb 100644
--- a/server/api.go
+++ b/server/api.go
@@ -27,6 +27,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/rpc"
"github.com/apache/incubator-servicecomb-service-center/server/service"
"golang.org/x/net/context"
+ "net"
"strconv"
"time"
)
@@ -207,6 +208,30 @@ func (s *APIServer) MarkForked() {
s.forked = true
}
+func (s *APIServer) AddListener(t APIType, ip, port string) {
+ if s.Listeners == nil {
+ s.Listeners = map[APIType]string{}
+ }
+ if len(ip) == 0 {
+ return
+ }
+ s.Listeners[t] = net.JoinHostPort(ip, port)
+}
+
+func (s *APIServer) AddEndpoint(t APIType, ipPort string) {
+ if s.Endpoints == nil {
+ s.Endpoints = map[APIType]string{}
+ }
+ if len(ipPort) == 0 {
+ return
+ }
+ address := fmt.Sprintf("%s://%s/", t, ipPort)
+ if core.ServerInfo.Config.SslEnabled {
+ address += "?sslEnabled=true"
+ }
+ s.Endpoints[t] = address
+}
+
func (s *APIServer) startRESTServer() (err error) {
addr, ok := s.Listeners[REST]
if !ok {
@@ -216,7 +241,10 @@ func (s *APIServer) startRESTServer() (err error) {
if err != nil {
return
}
- util.Logger().Infof("listen address: %s://%s, host: %s.", REST, addr, s.HostName)
+ util.Logger().Infof("listen address: %s://%s, host: %s.",
+ REST, s.restSrv.Listener.Addr().String(), s.HostName)
+
+ s.AddEndpoint(REST, s.restSrv.Listener.Addr().String())
s.goroutine.Do(func(_ context.Context) {
err := s.restSrv.Serve()
@@ -239,7 +267,10 @@ func (s *APIServer) startRPCServer() (err error) {
if err != nil {
return
}
- util.Logger().Infof("listen address: %s://%s, host: %s.", RPC, addr, s.HostName)
+ util.Logger().Infof("listen address: %s://%s, host: %s.",
+ RPC, s.rpcSrv.Listener.Addr().String(), s.HostName)
+
+ s.AddEndpoint(RPC, s.rpcSrv.Listener.Addr().String())
s.goroutine.Do(func(_ context.Context) {
err := s.rpcSrv.Serve()
diff --git a/server/core/proto/services.go b/server/core/proto/services.go
index ff89bb3..60a3e44 100644
--- a/server/core/proto/services.go
+++ b/server/core/proto/services.go
@@ -114,10 +114,6 @@ type ServerConfig struct {
PluginsDir string `json:"-"`
}
-func (c *ServerConfig) LogPrint() {
-
-}
-
type ServerInformation struct {
Version string `json:"version"`
Config ServerConfig `json:"-"`
diff --git a/server/server.go b/server/server.go
index 6999228..fec8d08 100644
--- a/server/server.go
+++ b/server/server.go
@@ -28,10 +28,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/version"
"github.com/astaxie/beego"
"golang.org/x/net/context"
- "net"
- "net/url"
"os"
- "strings"
"time"
)
@@ -156,27 +153,15 @@ func (s *ServiceCenterServer) startApiServer() {
rpcIp := beego.AppConfig.DefaultString("rpcaddr", "")
rpcPort := beego.AppConfig.DefaultString("rpcport", "")
- s.apiServer.HostName = fmt.Sprintf("%s_%s", core.ServerInfo.Config.LoggerName,
- strings.Replace(restIp, ".", "_", -1))
- s.addEndpoint(REST, restIp, restPort)
- s.addEndpoint(RPC, rpcIp, rpcPort)
- s.apiServer.Start()
-}
-
-func (s *ServiceCenterServer) addEndpoint(t APIType, ip, port string) {
- if s.apiServer.Endpoints == nil {
- s.apiServer.Listeners = map[APIType]string{}
- s.apiServer.Endpoints = map[APIType]string{}
- }
- if len(ip) == 0 {
- return
- }
- address := fmt.Sprintf("%s://%s/", t, net.JoinHostPort(url.PathEscape(ip), port))
- if core.ServerInfo.Config.SslEnabled {
- address += "?sslEnabled=true"
+ host, err := os.Hostname()
+ if err != nil {
+ host = restIp
+ util.Logger().Errorf(err, "parse hostname failed")
}
- s.apiServer.Listeners[t] = net.JoinHostPort(ip, port)
- s.apiServer.Endpoints[t] = address
+ s.apiServer.HostName = host
+ s.apiServer.AddListener(REST, restIp, restPort)
+ s.apiServer.AddListener(RPC, rpcIp, rpcPort)
+ s.apiServer.Start()
}
func (s *ServiceCenterServer) Stop() {