Consul on Kubernetes: How to use/test Consul-Template from all nodes

1/21/2020

I have created a 3-node (1 master and 2 workers) Kubernetes cluster using k3s and Multipass on my Mac:

NAME    STATUS   ROLES    AGE     VERSION
node3   Ready    <none>   3d20h   v1.17.0+k3s.1
node2   Ready    <none>   3d20h   v1.17.0+k3s.1
node1   Ready    master   3d20h   v1.17.0+k3s.1

I have also installed Consul with 1 server on the cluster:

NAME                                                              READY   STATUS      RESTARTS   AGE
svclb-dashboard-service-load-balancer-kww4m                       0/1     Pending     0          3d20h
svclb-dashboard-service-load-balancer-xh2v8                       0/1     Pending     0          3d20h
svclb-dashboard-service-load-balancer-k8wkl                       0/1     Pending     0          3d20h
dns-jwszw                                                         0/1     Completed   0          18h
hashicorp-consul-connect-injector-webhook-deployment-84589vtj5n   1/1     Running     5          3d20h
dnsutils                                                          1/1     Running     7          20h
hashicorp-consul-server-0                                         1/1     Running     5          3d20h
hashicorp-consul-z7q9m                                            1/1     Running     5          3d20h
hashicorp-consul-4v9v4                                            1/1     Running     5          3d20h
hashicorp-consul-hzrh9                                            1/1     Running     5          3d20h
counting                                                          3/3     Running     15         3d20h
dashboard                                                         3/3     Running     15         3d20h

Now, I have installed consul-template and trying to test it out to make sure that it allows me to auto-sync my config files from all of the nodes with Consul's KV store. I believe the best way is to submit a job to the cluster and check out the result similar to the script below which queries the DNS server:

apiVersion: batch/v1
kind: Job
metadata:
  name: dns
spec:
  template:
    spec:
      containers:
      - name: dns
        image: anubhavmishra/tiny-tools
        command: ["dig",  "counting.service.consul"]
      restartPolicy: Never
  backoffLimit: 4

but I am not sure how to do it. I have followed many tutorials but none of them focus on Kubernetes with Consul server. Any help is much appreciated.

-- HemOdd
consul
consul-template
kubernetes

0 Answers