Use Vagrant Landrush to add DNS features to your OpenShift CDK Machine

With the release of the Red Hat Container Development Kit (CDK), it’s been easier to set up a development environment with OpenShift to create, develop and test your own containerized applications, and easier evaluate different CI/CD strategies with Jenkins — strategies that reflect your team’s unique culture.

However, when you want to access applications by their DNS names, you cannot do so because there is no DNS server pointing to that name. That is, of course, until now!

Vagrant provides a very nice plugin that can use dnsmasq to create a DNS caching server to provide this access.

Vagrant Landrush plugin

The Vagrant Landrush plugin is used to create a small DNS server to redirect traffic to your server. DNS entries are automatically updated as the VMs are created and destroyed by Vagrant.

This plugin is available in https://github.com/vagrant-landrush/landrush.

Installing Vagrant Landrush plugin

Vagrant landrush can be installed with the following command:

vagrant plugin install landrush

After that, you can run landrush direclty from vagrant command. To check if landrush is running, you can type the following command:

vagrant landrush status

If landrush service is not started just run:

vagrant landrush start

And now landrush is running!

$ vagrant landrush status
Daemon status: running pid=6841

Since landrush acts like a DNS server, you can see the DNS records stored in landrush with the following command:

$ vagrant landrush ls
2.2.1.10.in-addr.arpa          openshift.cdk.vm
1.42.17.172.in-addr.arpa       openshift.cdk.vm
openshift.cdk.vm               10.1.2.2

Also, you can add the records with the following command:

vagrant landrush set <fqdn> <ip-address>

And now you have Vagrant Landrush up and running. Now we need to configure dnsmasq to query for Vagrant Landrush records. You must run the following commands to configure dnsmasq:

sudo sh -c 'echo "server=/cdk.vm/127.0.0.1#10053" > /etc/dnsmasq.d/vagrant-landrush'

And dnsmasq will forward all DNS queries related to cdk.vm to Vagrant Landrush process. Although I’m using cdk.vm as the domain name, the default value is vagrant.test, however in the next section I’ll show how to configure your virtual machine to use custom DNS names.

If you are using the NetworkManager service, you must run the same command, changed slightly for use with NetworkManager:

sudo sh -c 'echo "server=/cdk.vm/127.0.0.1#10053" > /etc/NetworkManager/vagrant-landrush'

And you must set the dns auto-configuration to use dnsmasq. To do so, edit /etc/NetworkManager/NetworkManager.conf and set the following values:

[main]
plugins=ifcfg-rh,ibft
dns=dnsmasq

Configuring your OpenShift CDK machine

Now you need to add the Vagrant Landrush configuration in the Vagrantfile of your OpenShift CDK Machine. Add the following content to enable Vagrant Landrush:

config.vm.hostname = &quot;openshift.cdk.vm&quot;
config.landrush.enabled = true
config.landrush.host_ip_address = &quot;#{PUBLIC_ADDRESS}&quot;
config.landrush.tld = &quot;openshift.cdk.vm&quot;
config.landrush.guest_redirect_dns = false

This snippet will:

  • Set the hostname to openshift.cdk.vm
  • Enable Vagrant Landrush on the machine
  • Set the IP Address to the same IP assigned to OpenShift CDK Machine (generally the IP address is 10.1.2.2)
  • Set a TLD name to openshift.cdk.vm (that way all DNS names with openshift.cdk.vm suffix will resolve to the same IP address)
  • Proxy all DNS requests

After this configuration, all you need to do is bring up your OpenShift Virtual Machine with the command vagrant up and you’ll be able to access your OpenShift Machine using the URL https://openshift.cdk.vm:8443.

What about my OpenShift applications?

One of the good things about Vagrant Landrush is that it can accept wildcard domains, meaning that anything under the specified TLD can resolve to the Virtual Machine address.

In this case, everything under openshift.cdk.vm can be resolved to 10.1.2.2 address (which is exactly what we need to resolve DNS names for our applications). However, in the provisioning phase, Vagrant sets OpenShift to use cdk.vm as the routing subdomain, which will create all routes under .cdk.vm and you will need to fix them manually.

One thing to solve this issue is add some lines in the provision snippet of the Vagrantfile to reconfigure OpenShift to resolve to the correct subdomain:

config.vm.provision &quot;shell&quot;, inline: &lt;&lt;-SHELL
  sudo systemctl enable openshift
  sudo systemctl start openshift&lt;/pre&gt;
  sudo sed -i 's/subdomain: &lt;a href=&quot;http://openshift.cdk.vm.10.1.2.2.xip.io/subdomain&quot; target=&quot;_blank&quot;&gt;openshift.cdk.vm.10.1.2.2.xip.&lt;wbr /&gt;io/subdomain&lt;/a&gt;: openshift.cdk.vm/' /var/lib/openshift/openshift.&lt;wbr /&gt;local.config/master/master-&lt;wbr /&gt;config.yaml
  sudo systemctl restart openshift SHELL 

With this configuration, all your applications will automatically create a route with a DNS name inside openshift.cdk.vm. Now, enjoy access your applications using a special DNS name!


Join Red Hat Developers, a developer program for you to learn, share, and code faster – and get access to Red Hat software for your development.  The developer program and software are both free!

 


For more information about Red Hat OpenShift and other related topics, visit: OpenShift, OpenShift Online.

  1. Great post!
    Just an addition. I had some issues with Firewalld on RHEL 7. Landrush listens on #10053 port (TCP and UDP). I had to explicitly open #10053 port on RHEL7 Firewalld config service.

    1. Hi rafaeltuelho, I didn’t have that problem. I believe most traffic is happening local so the firewall shouldn’t be an issue? Perhaps the issue below that I found was your problem as well?

      The other issue I saw: the dnsmasq process that gets kicked off by NetworkManager has this command line:

      “`
      /usr/sbin/dnsmasq –no-resolv –keep-in-foreground –no-hosts –bind-interfaces –pid-file=/var/run/NetworkManager/dnsmasq.pid –listen-address=127.0.0.1 –conf-file=/var/run/NetworkManager/dnsmasq.conf –cache-size=400 –proxy-dnssec –conf-dir=/etc/NetworkManager/dnsmasq.d
      “`

      Which means that we need to put our configuration into `/etc/NetworkManager/dnsmasq.d/vagrant-landrush` instead to get things to work. Author is that right? Can we get this updated?

      Author, please update the article to indicate the `sh -c` command needs to be run with sudo and editing the `/etc/NetworkManager/NetworkManager.conf` file requires root privs.

Leave a Reply