说明
本次部署初始使用了 consul,但是最终因为大 key 导致放弃 consul,consul 默认 512KB 的 key,但还是把这个组件的部署方式放出来
安装
添加 repo:
# helm repo add hashicorp https://helm.releases.hashicorp.com
# helm repo update
查看版本:
# helm search repo hashicorp/consul
NAME CHART VERSION APP VERSION DESCRIPTION
hashicorp/consul 0.26.0 1.8.5 Official HashiCorp Consul Chart
下载包:
# helm pull hashicorp/consul --version=0.26.0
查看可以自定义的字段:
# helm show values consul-0.26.0.tgz
创建自定义配置文件:
参考:https://www.consul.io/docs/k8s/helm.html#v-global
# cat > consul-config.yaml <<EOF
global:
# If true, servers, clients, Consul DNS and the Consul UI will be enabled.
enabled: true
name: consul
# The domain Consul will answer DNS queries for (see -domain) and the domain services synced from Consul into Kubernetes will have, e.g. service-name.service.consul.
domain: consul
datacenter: dc1
#image: "consul:1.8.4"
image: "harbor.sit.hupu.io/k8s/consul:1.8.4"
# The name (and tag) of the consul-k8s Docker image that is used for functionality such the catalog sync.
#imageK8S: "hashicorp/consul-k8s:0.19.0"
#The default envoy image to use for ingress and terminating gateways.
#imageEnvoy: "envoyproxy/envoy-alpine:v1.14.4"
enablePodSecurityPolicies: false
gossipEncryption:
secretName: ""
secretKey: ""
tls:
enabled: false
enableAutoEncrypt: false
acls:
bootstrapToken:
secretName: null
secretKey: null
createReplicationToken: false
replicationToken:
secretName: null
secretKey: null
federation:
enabled: false
createFederationSecret: false
server:
enabled: true
image: null
replicas: 3
# Should <= replicas count
bootstrapExpect: 3
storage: 20Gi
storageClass: alicloud-disk-efficiency-cn-hangzhou-g
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 100m
memory: 200Mi
disruptionBudget:
enabled: true
maxUnavailable: null
affinity: |
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: {{ template "consul.name" . }}
release: "{{ .Release.Name }}"
component: server
topologyKey: kubernetes.io/hostname
externalServers:
# If true, the Helm chart will be configured to talk to the external servers.
# If setting this to true, you must also set server.enabled to false.
enabled: false
client:
enabled: false
dns:
enabled: true
ui:
enabled: true
EOF
创建 consul 集群:
# kubectl create ns consul
# helm install consul consul-0.26.0.tgz --set global.name=consul -f consul-config.yaml --namespace consul
NAME: consul
LAST DEPLOYED: Wed Nov 11 18:53:35 2020
NAMESPACE: consul
STATUS: deployed
REVISION: 1
NOTES:
Thank you for installing HashiCorp Consul!
Now that you have deployed Consul, you should look over the docs on using
Consul with Kubernetes available here:
https://www.consul.io/docs/platform/k8s/index.html
Your release is named consul.
To learn more about the release if you are using Helm 2, run:
$ helm status consul
$ helm get consul
To learn more about the release if you are using Helm 3, run:
$ helm status consul
$ helm get all consul
查看:
# helm list -n consul -n consul
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
consul consul 1 2020-11-11 18:59:09.010549253 +0800 CST deployed consul-0.25.0 1.8.4
# kubectl get pod,svc -l app=consul -n consul
NAME READY STATUS RESTARTS AGE
pod/consul-server-0 1/1 Running 0 44s
pod/consul-server-1 1/1 Running 0 44s
pod/consul-server-2 1/1 Running 0 44s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/consul-dns ClusterIP 172.31.61.228 <none> 53/TCP,53/UDP 44s
service/consul-server ClusterIP None <none> 8500/TCP,8301/TCP,8301/UDP,8302/TCP,8302/UDP,8300/TCP,8600/TCP,8600/UDP 44s
service/consul-ui ClusterIP 172.31.63.134 <none> 80/TCP 44s
创建 Ingress:
# cat > consul-ui-ingress.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik
name: consul
namespace: consul
spec:
rules:
- host: consul.sit.hupu.io
http:
paths:
- backend:
serviceName: consul-ui
servicePort: 80
path: /
EOF
# kubectl apply -f consul-ui-ingress.yaml
访问 consul web:
http://consul.sit.hupu.io