问题描述
我正在尝试通过Kubernetes,头盔图表, https://www进行Consul设置.consul.io/docs/k8s/helm
I am trying to do Consul setup via Kubernetes, helm chart, https://www.consul.io/docs/k8s/helm
基于我对Kubernetes的了解:服务,通过Consul Agent使用Consul访问,在每个主机上运行并在主机IP上监听
Based on my pre-Kubernetes knowledge: services, using Consul access via Consul Agent, running on each host and listening on hosts IP
现在,我通过Helm图表将其部署到Kubernetes集群.首先会误解术语,这种设置中的Consul Agent vs Client?我想是一样的
Now, I deployed via Helm chart to Kubernetes cluster. First misunderstanding the terminology, Consul Agent vs Client in this setup? I presume it is the same
现在,设置:
头盔图表配置(Terraform片段),对于客户端/代理及其服务没有特定的定义:
Helm chart config (Terraform fragment), nothing specific to Clients/Agent's and their service:
global:
name: "consul"
datacenter: "${var.consul_config.datacenter}"
server:
storage: "${var.consul_config.storage}"
connect: false
syncCatalog:
enabled: true
default: true
k8sAllowNamespaces: ['*']
k8sDenyNamespaces: [${join(",", var.consul_config.k8sDenyNamespaces)}]
Pod,客户端/代理是DaemonSet,不在主机网络模式下
Pods, client/agent ones are DaemonSet, not in host network mode
kubectl get pods
NAME READY STATUS RESTARTS AGE
consul-8l587 1/1 Running 0 11h
consul-cfd8z 1/1 Running 0 11h
consul-server-0 1/1 Running 0 11h
consul-server-1 1/1 Running 0 11h
consul-server-2 1/1 Running 0 11h
consul-sync-catalog-8b688ff9b-klqrv 1/1 Running 0 11h
consul-vrmtp 1/1 Running 0 11h
服务
kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
consul ExternalName <none> consul.service.consul <none> 11h
consul-dns ClusterIP 172.20.124.238 <none> 53/TCP,53/UDP 11h
consul-server ClusterIP None <none> 8500/TCP,8301/TCP,8301/UDP,8302/TCP,8302/UDP,8300/TCP,8600/TCP,8600/UDP 11h
consul-ui ClusterIP 172.20.131.29 <none> 80/TCP 11h
问题1 :针对客户端(代理)容器而不是服务器的容器的服务在哪里?我在头盔图中错过了吗?
Question 1 Where is a service, to target Client (Agent) pods, but not Server's pods ? Did I miss it in helm chart?
我的计划是,当我不使用主机(Kubernetes节点)网络时:
My plan is, while I am not going to use Host (Kubernetes node) networking:
- 找到客户/代理服务或自行创建.因此,它将由领事的用户使用.例如,我将为Consul模板的Consul模板init pod指定此服务地址.在使用配置的应用程序中
kubectl get pods --selector app=consul,component=client,release=consul
consul-8l587 1/1 Running 0 11h
consul-cfd8z 1/1 Running 0 11h
consul-vrmtp 1/1 Running 0 11h
- 可选:将在代理服务中添加一个topologyKeys,这样每个使用者都不会越过主机边界
问题2 是正确的方法吗?还是Consul Kubernetes部署不同
Question 2 Is it right approach? Or it is different for Consul Kubernetes deployments
推荐答案
您可以使用Kubernetes向下API注入主机IP作为Pod的环境变量.
You can use the Kubernetes downward API to inject the IP of host as an environment variable for your pod.
apiVersion: v1
kind: Pod
metadata:
name: consul-example
spec:
containers:
- name: example
image: 'consul:latest'
env:
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
command:
- '/bin/sh'
- '-ec'
- |
export CONSUL_HTTP_ADDR="${HOST_IP}:8500"
consul kv put hello world
restartPolicy: Never
请参见 https://www.consul.io/docs/k8s/installation/install#accessing-the-consul-http-api 了解更多信息.
这篇关于Hashicorp Consul,代理/客户访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!