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 = "openshift.cdk.vm"
config.landrush.enabled = true
config.landrush.host_ip_address = "#{PUBLIC_ADDRESS}"
config.landrush.tld = "openshift.cdk.vm"
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 "shell", inline: <<-SHELL
  sudo systemctl enable openshift
  sudo systemctl start openshift</pre>
  sudo sed -i 's/subdomain: <a href="http://openshift.cdk.vm.10.1.2.2.xip.io/subdomain" target="_blank">openshift.cdk.vm.10.1.2.2.xip.<wbr />io/subdomain</a>: openshift.cdk.vm/' /var/lib/openshift/openshift.<wbr />local.config/master/master-<wbr />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!

Last updated: January 19, 2023