-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
本地启动helm部署bcs-webconsole 教程文档 (#2013)
Co-authored-by: ifooth <[email protected]>
- Loading branch information
1 parent
23b4306
commit 74ed692
Showing
11 changed files
with
625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apiVersion: v2 | ||
name: bcs-webconsole | ||
description: A Helm chart for Kubernetes | ||
|
||
# A chart can be either an 'application' or a 'library' chart. | ||
# | ||
# Application charts are a collection of templates that can be packaged into versioned archives | ||
# to be deployed. | ||
# | ||
# Library charts provide useful utilities or functions for the chart developer. They're included as | ||
# a dependency of application charts to inject those utilities and functions into the rendering | ||
# pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.1.0 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "latest" | ||
dependencies: | ||
- name: redis | ||
version: 17.7.3 | ||
repository: https://charts.bitnami.com/bitnami | ||
- name: etcd | ||
version: 8.7.3 | ||
repository: https://charts.bitnami.com/bitnami |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# 本地启动helm部署bcs-webconsole 教程文档 | ||
|
||
使用helm chart部署cluster-webconsole应用 | ||
|
||
#### 部署环境 | ||
|
||
``` | ||
操作系统环境:CentOS Linux 7 (Core) | ||
golang: go1.17 | ||
docker环境:20.10.23 | ||
Kubernetes:v1.23.8 | ||
helm: v3.11.0 | ||
``` | ||
|
||
#### 构建**bcs-webconsole**镜像 | ||
|
||
- **拉取[bk-bcs](https://github.com/Tencent/bk-bcs)项目,拉取完成后找到bcs-webconsole项目目录** | ||
|
||
``` | ||
git clone https://github.com/Tencent/bk-bcs.git | ||
cd bk-bcs/bcs-services/bcs-webconsole/ | ||
``` | ||
|
||
- 构建bcs-webconsol项目镜像 | ||
|
||
``` | ||
// Build the binary | ||
make build | ||
// Build a docker image | ||
make docker | ||
``` | ||
|
||
#### 使用helm chart部署bcs-webconsole项目 | ||
|
||
- **返回到bk-bcs项目根目录,找到部署bcs-webconsole项目的chart包** | ||
|
||
``` | ||
cd install/helm/bcs-webconsole | ||
``` | ||
|
||
- **bcs-webconsole chart配置参数都在Value.yaml** | ||
|
||
*bcs-webconsole配置* | ||
|
||
| **Name** | Description | Value | | ||
| -------------------------- | ------------------------------------------------------------ | -------------- | | ||
| mage.repository | 镜像名称 | bcs-webconsole | | ||
| image.pullPolicy | 镜像拉取策略,由于本地存在bcs-webconsole项目镜像所以默认Never | Never | | ||
| image.tag | 镜像版本 | latest | | ||
| svcConf.base_conf.app_code | | false | | ||
| svcConf.bcs_conf.host | | | | ||
| envs | 环境变量,DEMO: "test" | | | ||
|
||
*redis配置参数* | ||
|
||
| **Name** | Description | Value | | ||
| ------------------ | ---------------------------------------------- | ---------- | | ||
| redis.architecture | redis架构。允许值:`standalone`或`replication` | standalone | | ||
| redis.auth.enabled | 启用密码验证 | false | | ||
|
||
*etcd配置参数* | ||
|
||
| **Name** | Description | Value | | ||
| --------------------- | ----------------------------------------- | ------ | | ||
| etcd.replicaCount | 要部署的etcd副本的数量 | 3 | | ||
| etcd.auth.rbac.create | 启用RBAC认证 | false | | ||
| etcd.auth.token.type | 认证令牌类型。允许的值。'simple'或'jwt'。 | simple | | ||
|
||
- **安装bcs-webconsole chart包** | ||
|
||
``` | ||
// 找到bcs-webconsole chart目录 | ||
// 安装chart包, 执行helm install(部署到默认的命名空间或者加上 -n 名称,指定命名空间) | ||
helm install bcs-webconsole ./bcs-webconsole -n default | ||
// 首次部署该chart会提示需要依赖,执行一下 | ||
helm dependency build ./bcs-webconsole | ||
// 再执行安装 | ||
helm install bcs-webconsole ./bcs-webconsole -n default | ||
// 查看部署的状态 | ||
helm status bcs-webconsole -n default | ||
// 卸载该应用 | ||
helm uninstall bcs-webconsole -n default | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
1. Get the application URL by running these commands: | ||
{{- if .Values.ingress.enabled }} | ||
{{- range $host := .Values.ingress.hosts }} | ||
{{- range .paths }} | ||
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} | ||
{{- end }} | ||
{{- end }} | ||
{{- else if contains "NodePort" .Values.service.type }} | ||
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "bcs-webconsole.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.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 --namespace {{ .Release.Namespace }} svc -w {{ include "bcs-webconsole.fullname" . }}' | ||
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "bcs-webconsole.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") | ||
echo http://$SERVICE_IP:{{ .Values.service.port }} | ||
{{- else if contains "ClusterIP" .Values.service.type }} | ||
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bcs-webconsole.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") | ||
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") | ||
echo "Visit http://127.0.0.1:8080 to use your application" | ||
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "bcs-webconsole.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). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "bcs-webconsole.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "bcs-webconsole.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "bcs-webconsole.labels" -}} | ||
helm.sh/chart: {{ include "bcs-webconsole.chart" . }} | ||
{{ include "bcs-webconsole.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "bcs-webconsole.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "bcs-webconsole.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "bcs-webconsole.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "bcs-webconsole.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "bcs-webconsole.envs" -}} | ||
- name: POD_IPs # ipv6双栈 | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: status.podIPs | ||
- name: POD_IP | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: status.podIP | ||
- name: BK_APP_CODE | ||
value: {{ .Values.svcConf.base_conf.app_code }} | ||
- name: BK_APP_SECRET | ||
value: {{ .Values.svcConf.base_conf.app_secret }} | ||
- name: BK_PAAS_HOST | ||
value: {{ .Values.svcConf.base_conf.bk_paas_host }} | ||
- name: BK_IAM_HOST | ||
value: {{ .Values.svcConf.auth_conf.host }} | ||
- name: REDIS_PASSWORD | ||
value: {{ .Values.svcConf.redis.password }} | ||
- name: BCS_APIGW_TOKEN | ||
value: {{ .Values.svcConf.bcs_conf.token }} | ||
- name: BCS_APIGW_PUBLIC_KEY | ||
value: {{ .Values.svcConf.bcs_conf.jwt_public_key }} | ||
{{- range $key, $val := .Values.envs }} | ||
- name: {{ $key }} | ||
value: {{ $val | quote }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "bcs-webconsole.confName" -}} | ||
{{- printf "%s-%s" (include "bcs-webconsole.fullname" .) "conf" }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{- if .Values.enabled -}} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "bcs-webconsole.confName" . }} | ||
labels: | ||
{{- include "bcs-webconsole.labels" . | nindent 4 }} | ||
data: | ||
config.yaml: |- | ||
{{- toYaml .Values.svcConf | nindent 4 }} | ||
credentials.yaml: |- | ||
{{- toYaml .Values.svcCR | nindent 4 }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{{- if .Values.enabled -}} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "bcs-webconsole.fullname" . }} | ||
labels: | ||
{{- include "bcs-webconsole.labels" . | nindent 4 }} | ||
spec: | ||
{{- if not .Values.autoscaling.enabled }} | ||
replicas: {{ .Values.replicaCount }} | ||
{{- end }} | ||
selector: | ||
matchLabels: | ||
{{- include "bcs-webconsole.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
{{- with .Values.podAnnotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "bcs-webconsole.selectorLabels" . | nindent 8 }} | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
serviceAccountName: {{ include "bcs-webconsole.serviceAccountName" . }} | ||
securityContext: | ||
{{- toYaml .Values.podSecurityContext | nindent 8 }} | ||
containers: | ||
- name: {{ .Chart.Name }} | ||
securityContext: | ||
{{- toYaml .Values.securityContext | nindent 12 }} | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
env: | ||
{{- include "bcs-webconsole.envs" . | trim | nindent 12 }} | ||
command: ["./bcs-webconsole"] | ||
args: | ||
- "--server-address=$(POD_IP)" | ||
- "--server-port=8083" | ||
- "--config=/data/etc/config.yaml" | ||
- "--credential-config=/data/etc/credentials.yaml" | ||
ports: | ||
- name: http | ||
containerPort: 8083 | ||
protocol: TCP | ||
resources: | ||
{{- toYaml .Values.resources | nindent 12 }} | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /data/etc | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: {{ include "bcs-webconsole.confName" . }} | ||
items: | ||
- key: "config.yaml" | ||
path: "config.yaml" | ||
- key: "credentials.yaml" | ||
path: "credentials.yaml" | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{- if .Values.autoscaling.enabled }} | ||
apiVersion: autoscaling/v2beta1 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: {{ include "bcs-webconsole.fullname" . }} | ||
labels: | ||
{{- include "bcs-webconsole.labels" . | nindent 4 }} | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: {{ include "bcs-webconsole.fullname" . }} | ||
minReplicas: {{ .Values.autoscaling.minReplicas }} | ||
maxReplicas: {{ .Values.autoscaling.maxReplicas }} | ||
metrics: | ||
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }} | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} | ||
{{- end }} | ||
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} | ||
- type: Resource | ||
resource: | ||
name: memory | ||
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} | ||
{{- end }} | ||
{{- end }} |
Oops, something went wrong.