diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PrefixPathController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PrefixPathController.java index 67e2c0f2c12..3ca40f6a218 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PrefixPathController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PrefixPathController.java @@ -1,18 +1,30 @@ package com.ctrip.framework.apollo.portal.controller; +import com.google.common.base.Strings; +import javax.servlet.ServletContext; import org.springframework.beans.factory.annotation.Value; - import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class PrefixPathController { + private final ServletContext servletContext; + + // We suggest users use server.servlet.context-path to configure the prefix path instead + @Deprecated @Value("${prefix.path:}") private String prefixPath; + public PrefixPathController(ServletContext servletContext) { + this.servletContext = servletContext; + } + @GetMapping("/prefix-path") - public String getPrefixPath(){ + public String getPrefixPath() { + if (Strings.isNullOrEmpty(prefixPath)) { + return servletContext.getContextPath(); + } return prefixPath; } diff --git a/scripts/helm/README.md b/scripts/helm/README.md index 7b63c865412..36d6eb1648c 100644 --- a/scripts/helm/README.md +++ b/scripts/helm/README.md @@ -20,7 +20,7 @@ $ helm search repo apollo ## 4. Deployments of apollo-configservice and apollo-adminservice -### 4.1 Installation +### 4.1 Install apollo-configservice and apollo-adminservice should be installed per environment, so it is suggested to indicate environment in the release name, e.g. `apollo-service-dev` @@ -32,21 +32,22 @@ $ helm install apollo-service-dev \ --set configdb.service.enabled=true \ --set configService.replicaCount=1 \ --set adminService.replicaCount=1 \ + -n your-namespace \ apollo/apollo-service ``` Or customize it with values.yaml ```bash -$ helm install apollo-service-dev -f values.yaml apollo/apollo-service +$ helm install apollo-service-dev -f values.yaml -n your-namespace apollo/apollo-service ``` -### 4.2 Uninstallation +### 4.2 Uninstall To uninstall/delete the `apollo-service-dev` deployment: ```bash -$ helm uninstall apollo-service-dev +$ helm uninstall -n your-namespace apollo-service-dev ``` ### 4.3 Configuration @@ -64,7 +65,7 @@ The following table lists the configurable parameters of the apollo-service char | `configdb.service.enabled` | Whether to create a Kubernetes Service for `configdb.host` or not. Set it to `true` if `configdb.host` is an endpoint outside of the kubernetes cluster | `false` | | `configdb.service.fullNameOverride` | Override the service name for apollo config db | `nil` | | `configdb.service.port` | The port for the service of apollo config db | `3306` | -| `configdb.service.type` | The service type of apollo config db: `ClusterIP` or `ExternalName` | `ClusterIP` | +| `configdb.service.type` | The service type of apollo config db: `ClusterIP` or `ExternalName`. If the host is a DNS name, please specify `ExternalName` as the service type, e.g. xxx.mysql.rds.aliyuncs.com | `ClusterIP` | | `configService.fullNameOverride` | Override the deployment name for apollo-configservice | `nil` | | `configService.replicaCount` | Replica count of apollo-configservice | `2` | | `configService.containerPort` | Container port of apollo-configservice | `8080` | @@ -79,6 +80,7 @@ The following table lists the configurable parameters of the apollo-service char | `configService.liveness.periodSeconds` | The period seconds of liveness probe | `10` | | `configService.readiness.initialDelaySeconds` | The initial delay seconds of readiness probe | `30` | | `configService.readiness.periodSeconds` | The period seconds of readiness probe | `5` | +| `configService.config.profiles` | specify the spring profiles to activate | `github,kubernetes` | | `configService.config.configServiceUrlOverride` | Override `apollo.config-service.url`: config service url to be accessed by apollo-client | `nil` | | `configService.config.adminServiceUrlOverride` | Override `apollo.admin-service.url`: admin service url to be accessed by apollo-portal | `nil` | | `configService.env` | Environment variables passed to the container, e.g.
`JAVA_OPTS: -Xss256k` | `{}` | @@ -101,6 +103,7 @@ The following table lists the configurable parameters of the apollo-service char | `adminService.liveness.periodSeconds` | The period seconds of liveness probe | `10` | | `adminService.readiness.initialDelaySeconds` | The initial delay seconds of readiness probe | `30` | | `adminService.readiness.periodSeconds` | The period seconds of readiness probe | `5` | +| `adminService.config.profiles` | specify the spring profiles to activate | `github,kubernetes` | | `adminService.env` | Environment variables passed to the container, e.g.
`JAVA_OPTS: -Xss256k` | `{}` | | `adminService.strategy` | The deployment strategy of apollo-adminservice | `{}` | | `adminService.resources` | The resources definition of apollo-adminservice | `{}` | @@ -108,9 +111,47 @@ The following table lists the configurable parameters of the apollo-service char | `adminService.tolerations` | The tolerations definition of apollo-adminservice | `[]` | | `adminService.affinity` | The affinity definition of apollo-adminservice | `{}` | +### 4.4 Sample + +1. ConfigDB host is an IP outside of kubernetes cluster + +```yaml +configdb: + host: 1.2.3.4 + dbName: ApolloConfigDBName + userName: someUserName + password: somePassword + connectionStringProperties: characterEncoding=utf8&useSSL=false + service: + enabled: true +``` + +2. ConfigDB host is a dns name outside of kubernetes cluster + +```yaml +configdb: + host: xxx.mysql.rds.aliyuncs.com + dbName: ApolloConfigDBName + userName: someUserName + password: somePassword + connectionStringProperties: characterEncoding=utf8&useSSL=false + service: + enabled: true + type: ExternalName +``` +3. ConfigDB host is a kubernetes service + +```yaml +configdb: + host: apollodb-mysql.mysql + dbName: ApolloConfigDBName + userName: someUserName + password: somePassword + connectionStringProperties: characterEncoding=utf8&useSSL=false +``` ## 5. Deployments of apollo-portal -### 5.1 Installation +### 5.1 Install To install the apollo-portal chart with the release name `apollo-portal`: @@ -124,13 +165,14 @@ $ helm install apollo-portal \ --set config.metaServers.dev=http://apollo-service-dev-apollo-configservice:8080 \ --set config.metaServers.pro=http://apollo-service-pro-apollo-configservice:8080 \ --set replicaCount=1 \ + -n your-namespace \ apollo/apollo-portal ``` Or customize it with values.yaml ```bash -$ helm install apollo-portal -f values.yaml apollo/apollo-portal +$ helm install apollo-portal -f values.yaml -n your-namespace apollo/apollo-portal ``` ### 5.2 Uninstallation @@ -138,7 +180,7 @@ $ helm install apollo-portal -f values.yaml apollo/apollo-portal To uninstall/delete the `apollo-portal` deployment: ```bash -$ helm uninstall apollo-portal +$ helm uninstall -n your-namespace apollo-portal ``` ### 5.3 Configuration @@ -173,8 +215,11 @@ The following table lists the configurable parameters of the apollo-portal chart | `nodeSelector` | The node selector definition of apollo-portal | `{}` | | `tolerations` | The tolerations definition of apollo-portal | `[]` | | `affinity` | The affinity definition of apollo-portal | `{}` | +| `config.profiles` | specify the spring profiles to activate | `github,auth` | | `config.envs` | specify the env names, e.g. dev,pro | `nil` | +| `config.contextPath` | specify the context path, e.g. `/apollo`, then users could access portal via `http://{portal_address}/apollo` | `nil` | | `config.metaServers` | specify the meta servers, e.g.
`dev: http://apollo-configservice-dev:8080`
`pro: http://apollo-configservice-pro:8080` | `{}` | +| `config.files` | specify the extra config files for apollo-portal, e.g. application-ldap.yml | `{}` | | `portaldb.host` | The host for apollo portal db | `nil` | | `portaldb.port` | The port for apollo portal db | `3306` | | `portaldb.dbName` | The database name for apollo portal db | `ApolloPortalDB` | @@ -184,4 +229,130 @@ The following table lists the configurable parameters of the apollo-portal chart | `portaldb.service.enabled` | Whether to create a Kubernetes Service for `portaldb.host` or not. Set it to `true` if `portaldb.host` is an endpoint outside of the kubernetes cluster | `false` | | `portaldb.service.fullNameOverride` | Override the service name for apollo portal db | `nil` | | `portaldb.service.port` | The port for the service of apollo portal db | `3306` | -| `portaldb.service.type` | The service type of apollo portal db: `ClusterIP` or `ExternalName` | `ClusterIP` | +| `portaldb.service.type` | The service type of apollo portal db: `ClusterIP` or `ExternalName`. If the host is a DNS name, please specify `ExternalName` as the service type, e.g. xxx.mysql.rds.aliyuncs.com | `ClusterIP` | + +### 5.4 Sample + +1. PortalDB host is an IP outside of kubernetes cluster + +```yaml +portaldb: + host: 1.2.3.4 + dbName: ApolloPortalDBName + userName: someUserName + password: somePassword + connectionStringProperties: characterEncoding=utf8&useSSL=false + service: + enabled: true +``` + +2. PortalDB host is a dns name outside of kubernetes cluster + +```yaml +portaldb: + host: xxx.mysql.rds.aliyuncs.com + dbName: ApolloPortalDBName + userName: someUserName + password: somePassword + connectionStringProperties: characterEncoding=utf8&useSSL=false + service: + enabled: true + type: ExternalName +``` +3. PortalDB host is a kubernetes service + +```yaml +portaldb: + host: apollodb-mysql.mysql + dbName: ApolloPortalDBName + userName: someUserName + password: somePassword + connectionStringProperties: characterEncoding=utf8&useSSL=false +``` + +4. Specify environments + +```yaml +config: + envs: dev,pro + metaServers: + dev: http://apollo-service-dev-apollo-configservice:8080 + pro: http://apollo-service-pro-apollo-configservice:8080 +``` + +5. Expose service as Load Balancer + +```yaml +service: + type: LoadBalancer +``` + +6. Expose service as Ingress + +```yaml +ingress: + enabled: true + hosts: + - paths: + - / +``` + +7. Expose service as Ingress with custom path `/apollo` + +```yaml +# use /apollo as root, should specify config.contextPath as /apollo +ingress: + enabled: true + hosts: + - paths: + - /apollo + +config: + ... + contextPath: /apollo + ... +``` + +8. Expose service as Ingress with session affinity + +```yaml +ingress: + enabled: true + annotations: + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/affinity: "cookie" + nginx.ingress.kubernetes.io/affinity-mode: "persistent" + nginx.ingress.kubernetes.io/session-cookie-conditional-samesite-none: "true" + nginx.ingress.kubernetes.io/session-cookie-expires: "172800" + nginx.ingress.kubernetes.io/session-cookie-max-age: "172800" + hosts: + - host: xxx.somedomain.com # host is required to make session affinity work + paths: + - / +``` + +9. Enable LDAP support + +```yaml +config: + ... + profiles: github,ldap + ... + files: + application-ldap.yml: | + spring: + ldap: + base: "dc=example,dc=org" + username: "cn=admin,dc=example,dc=org" + password: "password" + searchFilter: "(uid={0})" + urls: + - "ldap://xxx.somedomain.com:389" + + ldap: + mapping: + objectClass: "inetOrgPerson" + loginId: "uid" + userDisplayName: "cn" + email: "mail" +``` \ No newline at end of file diff --git a/scripts/helm/apollo-portal/templates/deployment-portal.yaml b/scripts/helm/apollo-portal/templates/deployment-portal.yaml index ea6af29c59d..bf588046418 100644 --- a/scripts/helm/apollo-portal/templates/deployment-portal.yaml +++ b/scripts/helm/apollo-portal/templates/deployment-portal.yaml @@ -13,10 +13,17 @@ data: {{- if .Values.config.envs }} apollo.portal.envs = {{ .Values.config.envs }} {{- end }} + {{- if .Values.config.contextPath }} + server.servlet.context-path = {{ .Values.config.contextPath }} + {{- end }} apollo-env.properties: | {{- range $env, $address := .Values.config.metaServers }} {{ $env }}.meta = {{ $address }} {{- end }} +{{- range $fileName, $content := .Values.config.files }} +{{ $fileName | indent 2 }}: | +{{ $content | indent 4 }} +{{- end }} --- kind: Deployment @@ -52,6 +59,10 @@ spec: path: application-github.properties - key: apollo-env.properties path: apollo-env.properties + {{- range $fileName, $content := .Values.config.files }} + - key: {{ $fileName }} + path: {{ $fileName }} + {{- end }} defaultMode: 420 containers: - name: {{ .Values.name }} @@ -61,13 +72,13 @@ spec: - name: http containerPort: {{ .Values.containerPort }} protocol: TCP - {{- with .Values.env }} env: - {{- range $key, $value := . }} + - name: SPRING_PROFILES_ACTIVE + value: {{ .Values.config.profiles | quote }} + {{- range $key, $value := .Values.env }} - name: {{ $key }} value: {{ $value }} {{- end }} - {{- end }} volumeMounts: - name: configmap-{{ $portalFullName }} mountPath: /apollo-portal/config/application-github.properties @@ -75,6 +86,11 @@ spec: - name: configmap-{{ $portalFullName }} mountPath: /apollo-portal/config/apollo-env.properties subPath: apollo-env.properties + {{- range $fileName, $content := .Values.config.files }} + - name: configmap-{{ $portalFullName }} + mountPath: /apollo-portal/config/{{ $fileName }} + subPath: {{ $fileName }} + {{- end }} livenessProbe: tcpSocket: port: {{ .Values.containerPort }} @@ -82,7 +98,7 @@ spec: periodSeconds: {{ .Values.liveness.periodSeconds }} readinessProbe: httpGet: - path: /health + path: {{ .Values.config.contextPath }}/health port: {{ .Values.containerPort }} initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }} periodSeconds: {{ .Values.readiness.periodSeconds }} diff --git a/scripts/helm/apollo-portal/values.yaml b/scripts/helm/apollo-portal/values.yaml index b8143d3a5bc..991bd327430 100644 --- a/scripts/helm/apollo-portal/values.yaml +++ b/scripts/helm/apollo-portal/values.yaml @@ -34,12 +34,18 @@ tolerations: [] affinity: {} config: + # spring profiles to activate + profiles: "github,auth" # specify the env names, e.g. dev,pro envs: "" # specify the meta servers, e.g. # dev: http://apollo-configservice-dev:8080 # pro: http://apollo-configservice-pro:8080 metaServers: {} + # specify the context path, e.g. /apollo + contextPath: "" + # extra config files for apollo-portal, e.g. application-ldap.yml + files: {} portaldb: name: apollo-portaldb diff --git a/scripts/helm/apollo-service/templates/deployment-adminservice.yaml b/scripts/helm/apollo-service/templates/deployment-adminservice.yaml index 8dcc9db3f8d..547bd1c8d43 100644 --- a/scripts/helm/apollo-service/templates/deployment-adminservice.yaml +++ b/scripts/helm/apollo-service/templates/deployment-adminservice.yaml @@ -54,7 +54,7 @@ spec: protocol: TCP env: - name: SPRING_PROFILES_ACTIVE - value: 'github,kubernetes' + value: {{ .Values.adminService.config.profiles | quote }} {{- range $key, $value := .Values.adminService.env }} - name: {{ $key }} value: {{ $value }} diff --git a/scripts/helm/apollo-service/templates/deployment-configservice.yaml b/scripts/helm/apollo-service/templates/deployment-configservice.yaml index faec8f7aef5..501e7dfa629 100644 --- a/scripts/helm/apollo-service/templates/deployment-configservice.yaml +++ b/scripts/helm/apollo-service/templates/deployment-configservice.yaml @@ -56,7 +56,7 @@ spec: protocol: TCP env: - name: SPRING_PROFILES_ACTIVE - value: 'github,kubernetes' + value: {{ .Values.configService.config.profiles | quote }} {{- range $key, $value := .Values.configService.env }} - name: {{ $key }} value: {{ $value }} diff --git a/scripts/helm/apollo-service/values.yaml b/scripts/helm/apollo-service/values.yaml index 58a5eeb4a90..9c7197a77ae 100644 --- a/scripts/helm/apollo-service/values.yaml +++ b/scripts/helm/apollo-service/values.yaml @@ -37,6 +37,8 @@ configService: initialDelaySeconds: 30 periodSeconds: 5 config: + # spring profiles to activate + profiles: "github,kubernetes" # override apollo.config-service.url: config service url to be accessed by apollo-client configServiceUrlOverride: "" # override apollo.admin-service.url: admin service url to be accessed by apollo-portal @@ -69,6 +71,9 @@ adminService: readiness: initialDelaySeconds: 30 periodSeconds: 5 + config: + # spring profiles to activate + profiles: "github,kubernetes" # environment variables passed to the container, e.g. JAVA_OPTS env: {} strategy: {}