Previous blog posts of "GitLab + K3S"

🇬🇧 GitLab + K3S: How to use DNSMasq instead

Last time, the service was down, and my services unavailable, so I searched an alternative. Some friends pointed me DNSMasq. I struggled several days with it, but finally today, I succeeded, and in fact, it's simple (but when your skills are not network oriented, the learning could be hard 😉).

My use case: right now, the url of my services is build like that: http://<service-name><branch-name> (where is the IP address of my K3S cluster).

Now, I would like something like that: http://<service-name><branch-name>.demo.g33k

Install and configuration

First, install DNSMasq (I'm on OSX, but I'm sure my 🐧 friends will adapt this):

brew install dnsmasq

Next, create a file like this one below, with an entry corresponding to your "wildcard" DNS and the IP address of the cluster:

echo "address=/.demo.g33k/" > /usr/local/etc/dnsmasq.d/development.conf

Then, update the network settings of your Mac, adding (and as DNS:

alt k9s

Click on Ok then on Apply

Restart DNSMasq:

sudo brew services restart dnsmasq

Now, create a "resolver" linked to your domain:

sudo bash -c 'echo "nameserver" > /etc/resolver/demo.g33k'

Check the routing:

dig hey.demo.g33k @

You should get something like this:

; <<>> DiG 9.10.6 <<>> hey.demo.k33g @
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7844
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 4096
;hey.demo.k33g.              IN      A

hey.demo.k33g.       0       IN      A

;; Query time: 0 msec
;; WHEN: Mon Mar 23 16:02:39 CET 2020
;; MSG SIZE  rcvd: 61

Check the ping:

ping hey.demo.k33g

You should get something like that:

PING hey.demo.g33k ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.232 ms
64 bytes from icmp_seq=1 ttl=64 time=0.324 ms

Of course, you have started the K3S cluster

So, now you need to change something with your deployment (in .gitlab-ci.yml):




export HOST="${APPLICATION_NAME}.${BRANCH}.demo.g33k"

And the environment url:



url: http://${CI_PROJECT_NAME}.${CI_COMMIT_REF_SLUG}.demo.g33k

And now, you just had to restart your CI.

That's all ğŸŽ‰ (for the moment) 😉

Last Articles

Last Updated: 3/23/2020, 5:05:47 PM