Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

Chapter 6. Using Vagrant CDK Plugins


The CDK comes with several plugins that provide added features you can use with your CDK Vagrant boxes. Here are descriptions of those plugins and ways you might use them.

6.1. Using the vagrant-service-manager Plugin

With the vagrant-service-manager plugin, you can display and import environment variables needed to access the Docker, Kubernetes, and OpenShift features inside of your Vagrant CDK Red Hat Enterprise Linux VM from the desktop system. Here are examples of how to see and use that information:

$ cd $HOME/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/
$ vagrant service-manager env docker
    # Copying TLS certificates to /home/chris/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/.vagrant/machines/default/libvirt/docker
    # Set the following environment variables to enable access to the
    # docker daemon running inside of the vagrant virtual machine:
    export DOCKER_HOST=tcp://192.168.121.160:2376
    export DOCKER_CERT_PATH=/home/chris/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/.vagrant/machines/default/libvirt/docker
    export DOCKER_TLS_VERIFY=1
    export DOCKER_MACHINE_NAME=be03562
    # run following command to configure your shell:
    # eval "$(vagrant service-manager env docker)"
Copy to Clipboard Toggle word wrap

In the above example, you can see that the Docker service is exposed from the IP address 192.168.121.160:2376 and TCP port 2376. A docker command or Eclipse IDE platform running on the local desktop could use that information to connect to the Docker service inside the VM. To have those values actually set inside your current shell, type the following:

$ cd $HOME/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/
$ eval "$(vagrant service-manager env docker)"
Copy to Clipboard Toggle word wrap

To see useful information to provide manually to the oc command or OpenShift Web UI on the host, you can use the vagrant-service-manager plugin as follows:

$ cd $HOME/cdk/components/rhel/rhel-ose/
$ vagrant service-manager env openshift
   # You can access the OpenShift console on: https://192.168.121.122:8443/console
   # To use OpenShift CLI, run: oc login https://192.168.121.122:8443
Copy to Clipboard Toggle word wrap

So you would type https://192.168.121.122:8443/console into the location box in your web browser to access the OpenShift Web UI from your desktop. Run oc login https://192.168.121.122:8443 from the command line on your desktop to connect to the OpenShift service with the oc command.

6.2. Using the vagrant-registration Plugin

With the vagrant-registration plugin, you can manage the Red Hat subscriptions for your Red Hat Enterprise Linux VMs through Vagrant. The plugin is capable of managing subscriptions with the type of subscription service that is available on the guest. However, at the moment it supports only Red Hat Enterprise Linux Suscription Manager (subscription-manager and related commands) and the older rhn_register command.

If you did not register your Red Hat Enterprise Linux VM when you started it with vagrant up, you should register it now. Registering your Red Hat Enterprise Linux system is highly recommended. Until you register, you cannot use the official Red Hat repositories to:

  • Upgrade the software in your Red Hat Enterprise Linux virtual machine.
  • Add more software packages to your Red Hat Enterprise Linux virtual machine.
  • Add software packages to the Red Hat Enterprise Linux containers you build or run on that VM

Red Hat Enterprise Linux base container images are configured to have Docker use the credentials of the host system. So when you try to install packages inside of a container, the yum command uses the host credentials to gain access to those packages from Red Hat. Without a valid Red Hat subscription, you will not have a fully-functioning setup for building Red Hat Enterprise Linux containers.

The process of registering your CDK virtual machine with Red Hat is automated using a Vagrant plugin, vagrant-registration. By default, when a Vagrant box is started, you are prompted to enter your username and password for the Red Hat Customer Portal. The registration plugin automatically attaches the Vagrant box to an available subscription.

When a Red Hat Enterprise Linux VM is registered in the CDK, an identity and time-limited entitlement is created for that VM. Once it is registered, the VM does not need to be re-registered until the CDK entitlement expires. Once the time limit is up, that container loses access to the Red Hat software repositories (CDN).

You can register your CDK system with a valid Red Hat Enterprise Linux Developer Subscription or Developer Suite. Joining the Red Hat Developers program provides a path to getting the CDK. Once you register a CDK VM, you get a new entitlement that lasts for 90 days that does not come out of your pool. If you re-register the same VM, you will get a new 90 day entitlement. You can do this over and over.

There are a few things you should know about releasing a subscription:

  • When you stop the Vagrant box, using either vagrant halt or vagrant destroy, the plugin automatically releases the Red Hat subscription.
  • If you stop the box by some other means, such as a reboot of the host system, you may need to manually remove the subscription in order to use it on another box. Use subscription management on the Red Hat Customer Portal Subscriptions to find and delete the virtual system that is no longer being used.
  • If you do not want to unregister a system when it is halted, you can set config.registration.unregister_on_halt = false in the selected Vagrantfile. In that case, the subscription will still be intact the next time you run vagrant up on that Vagrantfile.
  • For more information on configuring the vagrant-registration plugin, see the vagrant-registration GitHub page.

If you do not have a Red Hat Enterprise Linux subscription, there are plans in the works to offer free entitlements to the Red Hat Enterprise Linux Developer Suite. Those entitlements will let you download and register a Red Hat Enterprise Linux host in the CDK. Keep an eye on the Red Hat Developer’s site for details.

6.2.1. Automating the Registration Process (Saving Your Credentials)

It is recommended that you store your Red Hat credentials, so that you do not have to answer the prompts every time you bring up a Vagrant box. This is mandatory for complex Vagrantfiles that bring up multiple virtual machines from a single Vagrantfile.

To store your credentials, the following lines should be added to the per-user Vagrantfile. The path to that file is different for the different platforms:

  • Windows: %USERPROFILE%\.vagrant.d\Vagrantfile
  • Fedora, Red Hat Enterprise Linux, or Mac OS X: ~/.vagrant.d/Vagrantfile

The configuration will be available to all boxes started under that user ID. The per-user Vagrantfile is not created automatically.

Vagrant.configure('2') do |config|
 config.registration.username = '<your Red Hat username>'
 config.registration.password = '<your Red Hat password>'
end
Copy to Clipboard Toggle word wrap

Alternatively, if you prefer not to store your Red Hat credential details in the file system, you can use the following configuration to retrieve them from environment variables. Remember to store your username in the $SUB_USERNAME environment variable (SUB_USERNAME for Windows) and your password in the $SUB_PASSWORD environment variable (SUB_PASSWORD for Windows) before starting Vagrant.

Vagrant.configure('2') do |config|
  config.registration.username = ENV['SUB_USERNAME']
  config.registration.password = ENV['SUB_PASSWORD']
end
Copy to Clipboard Toggle word wrap

These settings may also be used in a specific Vagrantfile that will override the settings in the per-user ~/.vagrant.d/Vagrantfile. In an existing Vagrantfile, there will already be a block that begins with Vagrant.configure('2') do |config|, so just add the two config.registration lines (see above) in the existing block.

For more information, see the vagrant-registration-README.md file in the ~/cdk/plugins directory of the ZIP file containing the CDK software components.

6.3. Using the vagrant-sshfs Plugin

The vagrant-sshfs plugin allows you to mount a folder from your host system inside the CDK virtual machine for the purpose of sharing files between those two environment. The shared file system relies on the SSH File Tranfer Protocol for sharing files. Although this is not the fastest or most efficient for file sharing today, the common availability of the SSH service makes this a popular way to share files between systems that don’t require high volume of file copies between systems.

The vagrant-sshfs plugin works on all systems supported by the CDK (Windows, Mac, Fedora, and Red Hat Enterprise Linux). It also integrates with all CDK-supported virtualization technologies (Virtualbox and Libvirt). Here are the steps for configuring the vagrant-sshfs plugin to share files between your CDK host system and a CDK virtual machine running on that host.

  1. Install the vagrant-sshfs plugin: If you haven’t already done so, go to the plugin directory that you copied from the CDK zip file and install the plugin as follows:

    $ cd ~/cdk/plugins
    $ vagrant plugin install ./vagrant-sshfs
    Copy to Clipboard Toggle word wrap
  2. Edit Vagrantfile: Using any text editor, open the Vagrantfile you want to modify (OSE or Kubernetes) and add a config.vm.synced_folder entry.

    Here is an example of what that entry might look like for a Red Hat Enterprise Linux or Fedora system:

    config.vm.synced_folder "/home/joe", "/mnt/joefiles", type: "sshfs"
    Copy to Clipboard Toggle word wrap

    In this example, when you run vagrant up, the /mnt/joefiles directory is created within the virtual machine and the /home/joe directory from the host is mount on that /mnt/joefiles directory inside the container. Any files you place in the /home/joe directory on the host will be accessible from /mnt/joefiles within the host.

    Here is an entry for a Windows system:

    config.vm.synced_folder 'c:\Users\chuck', "/mnt/host_home", type: 'sshfs', sshfs_opts_append: '-o umask=000 -o uid=1000 -o gid=1000'
    Copy to Clipboard Toggle word wrap

    This example shares the user chuck’s home directory (c:\Users\chuck) to the /mnt/host_home directory on the host. The umask options sets the default permissions set on files created on the shared directory (wide open permission), while uid=1000 and gid=1000 sets the user and group IDs that will be assigned to files created in the shared directory.

  3. Start the Vagrant virtual machines: Use the vagrant up command to start the CDK virtual machine from the Vagrantfile in the selected directory:

    $ cd ~/cdk/components/rhel/rhel-ose
    $ vagrant up
    ...
    ==> default: Rsyncing folder: /home/joe/cdk/components/rhel/rhel-ose/ => /vagrant
    ==> default: Mounting SSHFS shared folders...
    ==> default: Mounting folder via SSHFS: /home/joe/ => /mnt/joefiles
    ==> default: Checking Mount..
    Warning: Permanently added '192.168.121.125' (ECDSA) to the list of known hosts.
    ==> default: Folder Successfully Mounted!
    ...
    Copy to Clipboard Toggle word wrap

    At this point, any files copied to the /home/joe directory on the host will be accessible from the /mnt/joefiles directory within the CDK virtual machines. Some reasons why this might fail include that you may have forgotten to install the plugin or the local ssh service may not be running.

For more details on how to configure the vagrant-sshfs service, refer to the vagrant-sshfs GitHub documentation.

Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat