1. 部署
不用改变参数,直接安装就行了
2. 部署情况
部署以后,各个模块的数据
应用:
服务:
这里有2个服务:consul-headless/consul-ui, consul-headless是主服务,后面测试会用到
工作负载:
容器:
3. 测试
在 KubeSphere 上搭建的 Consul 集群,可以使用以下方式测试是否正常工作:
3.1. 创建测试pod
可以使用以下 YAML 文件创建一个测试 Pod:
apiVersion: v1
kind: Pod
metadata:
name: consul-client
spec:
containers:
- name: consul-client
image: consul:1.10.2
command: [ "sleep", "3600" ]
imagePullPolicy: IfNotPresent
restartPolicy: Never
将该文件保存为 consul-client.yaml,然后使用以下命令创建一个名为 consul-client 的测试 Pod:
kubectl apply -f consul-client.yaml -n beta-api
创建以后:
看到容器起来了
3.2. 连接到 Consul Agent
使用以下命令进入测试 Pod 的 shell:
kubectl exec -it consul-client -n <consul-namespace>— /bin/sh
在测试 Pod 的 shell 中运行以下命令连接到 Consul Agent:
consul agent -node=client-1 -join=<consul-server-service-name>.<consul-namespace>.svc.cluster.local:8301 -data-dir=<data-dir>
将 <consul-datacenter> 替换为 Consul 集群的数据中心名称,<consul-server-service-name> 替换为 Consul Server 的 Service 名称,<consul-namespace> 替换为 Consul 集群所在的命名空间。<data-dir> 替换为本地目录的路径
如果 Consul Agent 成功连接到 Consul Server,将显示类似以下的输出:
bash-5.1# kubectl exec -it consul-client -n beta-api -- /bin/sh
/ #
/ # consul agent -node=client-1 -join=consul-headless.beta-api.svc.cluster.local:8301 -data-dir=.
==> Starting Consul agent...
Version: '1.10.2'
Node ID: 'ae7758b6-d1f5-8c25-a2c9-83b9ecfaf64f'
Node name: 'client-1'
Datacenter: 'dc1' (Segment: '')
Server: false (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: -1, DNS: 8600)
Cluster Addr: 172.31.26.83 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
==> Log data will now stream in as it occurs:
2023-07-04T09:27:24.815Z [INFO] agent.client.serf.lan: serf: EventMemberJoin: client-1 172.31.26.83
2023-07-04T09:27:24.815Z [INFO] agent.router: Initializing LAN area manager
2023-07-04T09:27:24.815Z [INFO] agent: Started DNS server: address=127.0.0.1:8600 network=udp
2023-07-04T09:27:24.815Z [WARN] agent.client.serf.lan: serf: Failed to re-join any previously known node
2023-07-04T09:27:24.815Z [INFO] agent: Started DNS server: address=127.0.0.1:8600 network=tcp
2023-07-04T09:27:24.816Z [INFO] agent: Starting server: address=127.0.0.1:8500 network=tcp protocol=http
2023-07-04T09:27:24.816Z [WARN] agent: DEPRECATED Backwards compatibility with pre-1.9 metrics enabled. These metrics will be removed in a future version of Consul. Set `telemetry { disable_compat_1.9 = true }` to disable them.
2023-07-04T09:27:24.816Z [INFO] agent: Joining cluster
2023-07-04T09:27:24.816Z [INFO] agent: (LAN) joining: lan_addresses=[consul-headless.beta-api.svc.cluster.local:8301]
2023-07-04T09:27:24.827Z [INFO] agent.client.serf.lan: serf: EventMemberJoin: consul-0 172.31.40.44
2023-07-04T09:27:24.828Z [INFO] agent.client.serf.lan: serf: EventMemberJoin: consul-1 172.31.25.158
2023-07-04T09:27:24.828Z [INFO] agent.client.serf.lan: serf: EventMemberJoin: consul-2 172.31.39.136
2023-07-04T09:27:24.828Z [INFO] agent.client: adding server: server="consul-0 (Addr: tcp/172.31.40.44:8400) (DC: dc1)"
2023-07-04T09:27:24.829Z [INFO] agent.client: adding server: server="consul-1 (Addr: tcp/172.31.25.158:8400) (DC: dc1)"
2023-07-04T09:27:24.829Z [INFO] agent.client: adding server: server="consul-2 (Addr: tcp/172.31.39.136:8400) (DC: dc1)"
2023-07-04T09:27:24.837Z [INFO] agent: (LAN) joined: number_of_nodes=3
2023-07-04T09:27:24.837Z [INFO] agent: Join completed. Initial agents synced with: agent_count=3
2023-07-04T09:27:24.837Z [INFO] agent: started state syncer
2023-07-04T09:27:24.837Z [INFO] agent: Consul agent running!
2023-07-04T09:27:24.855Z [INFO] agent: Synced node info
2023-07-04T09:27:35.419Z [INFO] agent: Newer Consul version available: new_version=1.16.0 current_version=1.10.2
这意味着 Consul Agent 已经成功连接到 Consul Server,并且正在运行。
3.3. 使用 Consul KV 存储进行测试
再建立一个连接到consul-client那个容器
在测试 Pod 的 shell 中运行以下命令,使用 Consul KV 存储写入一个键值对:
bash:consul kv put foo bar
然后,可以使用以下命令从 Consul KV 存储中读取该键值对:
consul kv get foo
将输出 bar
,表示键 foo
的值为 bar
。
这样就完成了 Consul 集群的测试。如果以上步骤中任何一步出现问题,请检查相应的命令参数是否正确,并确保 Consul 集群已经正常运行。
bash-5.1# kubectl exec -it consul-client -n beta-api -- /bin/sh
/ #
/ # consul kv put foo bar
'Success! Data written to: foo
/ # consul kv get foo
bar
/ #
标签:27,07,kubesphere,agent,04T09,2023,consul,搭建 From: https://www.cnblogs.com/zhanchenjin/p/17526438.html