kube-consul-registrator is the service that can handle consul registration and deregistration while kube-consul-registrator run into the Kubernetes cluster.
- Kubernetes cluster
- Consul server : docker-compose example
Envrionment variable | Explaination | Example |
---|---|---|
CONSUL_ADDRESS | Consul address in the cluster | "consul:8500" |
KUBE_ALLOWED_NAMESPACES | Namespaces to register pods | "default,namespace1" |
These are annotation samples when you want to add a pod in the consul. You should add this annotations on the metadata of a pod. (Do not add this on the metadata of Deployment, ReplicaSet, StatefulSet, and DaemonSet)
consul-registrator/enabled: <true|false>
consul-registrator/service-id: <string>
consul-registrator/service-name: <string>
consul-registrator/service-port: <string>
consul-registrator/service-tag: <string[]>
consul-registrator/service-meta-<key>: <value>
Kubernetes definistion example
apiVersion: apps/v1
kind: Deployment
metadata:
name: consul-register-deployment
namespace: default
spec:
selector:
matchLabels:
component: consul-register
replicas: 1
template:
metadata:
labels:
component: consul-register
annotations:
consul-registrator/enabled: true
consul-registrator/service-id: foo
consul-registrator/service-name: bar
consul-registrator/service-port: 80
consul-registrator/service-tag: "tag1,tag2" # comma separated string
consul-registrator/service-meta-type: "test" # add metadata [type:test]
spec:
serviceAccountName: consul-register
containers:
- name: consul-register
image: coolexplorer/kube-consul-registrator:latest
imagePullPolicy: Always
ports:
- containerPort: 80
env:
- name: CONSUL_ADDRESS
value: "consul:8500"
- name: KUBE_ALLOWED_NAMESPACES
value: "qe-tools,monitoring"
- name : Logging__LogLevel__Default
value: "Debug"
To use this service, you need to create kube-consul-registrator pod with authorization to get the cluster information from the cluster. Please refer to the files that I added in the repository.
- Deployment definition
- Service definition
- Service Account definition
- ClusterRoleBinding definition
- ClusterRole
- Allen Kim - Initial work - coolexplorer
This project is licensed under the MIT License - see the LICENSE.md file for details