github.com/openshift/installer@v1.4.17/docs/dev/libvirt/README.md (about) 1 # Libvirt Support Update 2 3 OpenShift Installer has stopped support for the libvirt platform starting 4.16. You can still use it with versions 4 4.15 and older. 5 6 # Libvirt HOWTO 7 8 Launching clusters via libvirt is especially useful for operator development. 9 10 **NOTE:** Some aspects of the installation can be customized through the 11 `install-config.yaml` file. See 12 [how to create an install-config.yaml file](../../user/overview.md#multiple-invocations) and [the libvirt platform customization](customization.md) documents. 13 14 ## One-time setup 15 16 It's expected that you will create and destroy clusters often in the course of development. These steps only need to be run once. 17 18 Before you begin, install the [build dependencies](../dependencies.md). 19 20 ### Enable KVM 21 22 Make sure you have KVM enabled by checking for the device: 23 24 ```console 25 $ ls -l /dev/kvm 26 crw-rw-rw-+ 1 root kvm 10, 232 Oct 31 09:22 /dev/kvm 27 ``` 28 29 If it is missing, try some of the ideas [here][kvm-install]. 30 31 ### Install and Enable Libvirt 32 33 On CentOS 7, first enable the 34 [kvm-common](http://mirror.centos.org/centos/7/virt/x86_64/kvm-common/) 35 repository to ensure you get a new enough version of qemu-kvm. 36 37 On Fedora, CentOS/RHEL: 38 39 ```sh 40 sudo dnf install libvirt-devel libvirt-daemon-kvm libvirt-client 41 ``` 42 43 Then start libvirtd: 44 45 ```sh 46 sudo systemctl enable --now libvirtd 47 ``` 48 49 ### Pick names 50 51 In this example, we'll set the base domain to `tt.testing` and the cluster name to `test1`. 52 53 ### Clone the project 54 55 ```sh 56 git clone https://github.com/openshift/installer.git 57 cd installer 58 ``` 59 60 ### Enable IP Forwarding 61 62 Libvirt creates a bridged connection to the host machine, but in order for the 63 network bridge to work IP forwarding needs to be enabled. The following command 64 will tell you if forwarding is enabled: 65 66 ```sh 67 sysctl net.ipv4.ip_forward 68 ``` 69 70 If the command output is: 71 72 ```sh 73 net.ipv4.ip_forward = 0 74 ``` 75 76 then forwarding is disabled and proceed with the rest of this section. If IP 77 forwarding is enabled then skip the rest of this section. 78 79 To enable IP forwarding for the current boot: 80 81 ```sh 82 sysctl net.ipv4.ip_forward=1 83 ``` 84 85 or to persist the setting across reboots (recommended): 86 87 ```sh 88 echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf 89 sudo sysctl -p /etc/sysctl.d/99-ipforward.conf 90 ``` 91 92 ### Configure libvirt to accept TCP connections 93 94 The Kubernetes [cluster-api](https://github.com/kubernetes-sigs/cluster-api) 95 components drive deployment of worker machines. The libvirt cluster-api 96 provider will run inside the local cluster, and will need to connect back to 97 the libvirt instance on the host machine to deploy workers. 98 99 In order for this to work, you'll need to enable unauthenticated TCP 100 connections for libvirt. 101 102 **NOTE:** The following configuration disables all encryption and authentication 103 options in libvirtd and causes it to listen on all network interfaces and IP 104 addresses. **A connection to this privileged libvirtd gives the client 105 privileges equivalent to those of a root shell.** This configuration has a 106 security impact on a par with running a telnet server with no root password set. 107 It is critical to follow the steps below to **configure the firewall to prevent 108 access to libvirt from other hosts on the LAN/WAN**. 109 110 #### For systemd activated libvirt 111 112 This applies only if the libvirt daemon is configured to use socket activation. 113 This is currently the case on Fedora 31 (and later) and Arch Linux. 114 115 First, you need to start the libvirtd TCP socket, which is managed by systemd: 116 117 ```sh 118 sudo systemctl start libvirtd-tcp.socket 119 ``` 120 121 To make this change persistent across reboots you can optionally enable it: 122 123 ```sh 124 sudo systemctl enable libvirtd-tcp.socket 125 ``` 126 127 Then to enable TCP access to libvirtd, modify `/etc/libvirt/libvirtd.conf` and 128 set the following: 129 130 ``` 131 auth_tcp = "none" 132 ``` 133 134 Then restart libvirt: 135 136 ```sh 137 sudo systemctl restart libvirtd 138 ``` 139 140 #### For permanently running libvirt daemon 141 142 This applies only if the libvirt daemon is started only through 143 `libvirtd.service` and without making use of systemd socket activation (through 144 `libvirtd.socket` and similar systemd units). 145 146 147 For RHEL/CentOS, make sure that the following is set in 148 `/etc/sysconfig/libvirtd`: 149 150 ``` 151 LIBVIRTD_ARGS="--listen" 152 ``` 153 154 For Debian based distros, make sure that the following is set in 155 `/etc/default/libvirtd`: 156 157 ``` 158 libvirtd_opts="--listen" 159 ``` 160 161 Then to enable TCP access to libvirtd, modify `/etc/libvirt/libvirtd.conf` and 162 set the following: 163 164 ``` 165 listen_tls = 0 166 listen_tcp = 1 167 auth_tcp = "none" 168 tcp_port = "16509" 169 ``` 170 171 Then restart libvirt: 172 173 ```sh 174 sudo systemctl restart libvirtd 175 ``` 176 177 #### Configure qemu.conf 178 179 On Debian/Ubuntu it might be needed to configure security driver for qemu. 180 Installer uses terraform libvirt, and it has a known issue, that might cause 181 unexpected `Could not open '/var/lib/libvirt/images/<FILE_NAME>': Permission denied` 182 errors. Double check that `security_driver = "none"` line is present in 183 `/etc/libvirt/qemu.conf` and not commented out. 184 185 #### Firewall 186 187 Finally, if you have a firewall, you may have to allow connections to the 188 libvirt daemon from the IP range used by your cluster nodes. 189 190 The following examples use the default cluster IP range of `192.168.126.0/24` (which is currently not configurable) and a libvirt `default` subnet of `192.168.122.0/24`, which might be different in your configuration. 191 If you're uncertain about the libvirt *default* subnet you should be able to see its address using the command `ip -4 a show dev virbr0` or by inspecting `virsh --connect qemu:///system net-dumpxml default`. 192 Ensure the cluster IP range does not overlap your `virbr0` IP address. 193 194 #### iptables 195 196 ```sh 197 sudo iptables -I INPUT -p tcp -s 192.168.126.0/24 -d 192.168.122.1 --dport 16509 -j ACCEPT -m comment --comment "Allow insecure libvirt clients" 198 ``` 199 200 #### Firewalld 201 202 If using `firewalld`, the specifics will depend on how your distribution has set 203 up the various zones. The following instructions should work as is for Fedora, 204 CentOS, RHEL and Arch Linux. 205 206 First, as we don't want to expose the libvirt port externally, we will need to 207 actively block it: 208 209 ```sh 210 sudo firewall-cmd --add-rich-rule "rule service name="libvirt" reject" 211 ``` 212 213 For systems with libvirt version 5.1.0 and later, libvirt will set new bridged 214 network interfaces in the `libvirt` zone. We thus need to allow `libvirt` 215 traffic from the VMs to reach the host: 216 217 ```sh 218 sudo firewall-cmd --zone=libvirt --add-service=libvirt 219 ``` 220 221 For system with an older libvirt, we will move the new bridge interface to a 222 dedicated network zone and enable incoming libvirt, DNS & DHCP traffic: 223 224 ```sh 225 sudo firewall-cmd --zone=dmz --change-interface=tt0 226 sudo firewall-cmd --zone=dmz --add-service=libvirt 227 sudo firewall-cmd --zone=dmz --add-service=dns 228 sudo firewall-cmd --zone=dmz --add-service=dhcp 229 ``` 230 231 NOTE: When the firewall rules are no longer needed, `sudo firewall-cmd --reload` 232 will remove the changes made as they were not permanently added. For persistence, 233 add `--permanent` to the `firewall-cmd` commands and run them a second time. 234 235 ### Set up DNS 236 237 This step allows installer and users to resolve cluster-internal hostnames from your host. 238 239 #### Using systemd-resolved 240 241 If your system is using `systemd-resolved` (the default since Fedora 33), then you can setup DNS without using `dnsmasq`. 242 243 Just point `resolvectl` to use `192.168.126.1` for your `baseDomain`. Replace `baseDomain` in the example accordingly. 244 245 ```sh 246 sudo resolvectl dns tt0 192.168.126.1 247 sudo resolvectl domain tt0 ~<baseDomain> 248 ``` 249 250 Your cluster might run on a different network interface. To find which one it is, either check your `install-config.yaml` 251 or run `nmcli` and find the interface that's running the `192.168.126.0/24` net. 252 253 Please note that this is not persistent across libvirt network creation/deletion of the tt0 interface. Once the tt0 interface is deleted and recreated, it will need to be updated again with the proper resolver. 254 255 #### Using NetworkManager DNS overlay 256 257 1. Tell NetworkManager to use `dnsmasq`: 258 259 ```sh 260 echo -e "[main]\ndns=dnsmasq" | sudo tee /etc/NetworkManager/conf.d/openshift.conf 261 ``` 262 263 2. Tell dnsmasq to use your cluster. The syntax is `server=/<baseDomain>/<firstIP>`. 264 265 For this example: 266 267 ```sh 268 echo server=/tt.testing/192.168.126.1 | sudo tee /etc/NetworkManager/dnsmasq.d/openshift.conf 269 ``` 270 271 3. Reload NetworkManager to pick up the `dns` configuration change: `sudo systemctl reload NetworkManager` 272 273 ## Build the installer 274 275 Set `TAGS=libvirt` to add support for libvirt; this is not enabled by default because libvirt is [development only](../../../README.md#supported-platforms). 276 277 ```sh 278 TAGS=libvirt hack/build.sh 279 ``` 280 281 ## Run the installer 282 283 With [libvirt configured](#install-and-enable-libvirt), you can proceed with [the usual quick-start](../../../README.md#quick-start). 284 285 ## Cleanup 286 287 To remove resources associated with your cluster, run: 288 289 ```sh 290 openshift-install destroy cluster 291 ``` 292 293 You can also use [`virsh-cleanup.sh`](../../../scripts/maintenance/virsh-cleanup.sh), but note that it will currently destroy *all* libvirt resources. 294 295 ### Firewall 296 297 With the cluster removed, you no longer need to allow libvirt nodes to reach your `libvirtd`. Restart 298 `firewalld` to remove your temporary changes as follows: 299 300 ```sh 301 sudo firewall-cmd --reload 302 ``` 303 304 ## Exploring your cluster 305 306 Some things you can do: 307 308 ### SSH access 309 310 The bootstrap node, e.g. `test1-bootstrap.tt.testing`, runs the bootstrap process. You can watch it: 311 312 ```sh 313 ssh "core@${CLUSTER_NAME}-bootstrap.${BASE_DOMAIN}" 314 sudo journalctl -f -u bootkube -u openshift 315 ``` 316 317 You'll have to wait for etcd to reach quorum before this makes any progress. 318 319 Using the domain names above will only work if you [set up the DNS overlay](#set-up-networkmanager-dns-overlay) or have otherwise configured your system to resolve cluster domain names. 320 Alternatively, if you didn't set up DNS on the host, you can use: 321 322 ```sh 323 virsh -c "${LIBVIRT_URI}" domifaddr "${CLUSTER_NAME}-master-0" # to get the master IP 324 ssh core@$MASTER_IP 325 ``` 326 327 Here `LIBVIRT_URI` is the libvirt connection URI which you [passed to the installer](../../../README.md#quick-start). 328 329 ### Inspect the cluster with kubectl 330 331 You'll need a `kubectl` binary on your path and [the kubeconfig from your `cluster` call](../../../README.md#connect-to-the-cluster). 332 333 ```sh 334 export KUBECONFIG="${DIR}/auth/kubeconfig" 335 kubectl get --all-namespaces pods 336 ``` 337 338 Alternatively, you can run `kubectl` from the bootstrap or master nodes. 339 Use `scp` or similar to transfer your local `${DIR}/auth/kubeconfig`, then [SSH in](#ssh-access) and run: 340 341 ```sh 342 export KUBECONFIG=/where/you/put/your/kubeconfig 343 kubectl get --all-namespaces pods 344 ``` 345 346 ## FAQ 347 348 ### Libvirt vs. AWS 349 350 1. There isn't a load balancer on libvirt. 351 352 ## Troubleshooting 353 354 If following the above steps hasn't quite worked, please review this section for well known issues. 355 356 ### Console doesn't come up 357 358 In case of libvirt there is no wildcard DNS resolution and console depends on the route which is created by auth operator ([Issue #1007](https://github.com/openshift/installer/issues/1007)). 359 To make it work we need to first create the manifests and edit the `domain` for ingress config, before directly creating the cluster. 360 361 - Add another domain entry in the openshift.conf which used by dnsmasq. 362 Here `tt.testing` is the domain which I choose when running the installer. 363 Here the IP in the address belong to one of the worker node. 364 365 ```console 366 $ cat /etc/NetworkManager/dnsmasq.d/openshift.conf 367 server=/tt.testing/192.168.126.1 368 address=/.apps.tt.testing/192.168.126.51 369 ``` 370 371 - An alternate method to specify the dnsmasq option, if the system is using libvirt version 5.6.0+, is to specify the option in the install config under the platform's network section in the following way. 372 373 ``` 374 platform: 375 libvirt: 376 network: 377 dnsmasqOptions: 378 - name: "address" 379 value: "/.apps.tt.testing/192.168.126.51" 380 if: tt0 381 ``` 382 383 - Make sure you restart the NetworkManager after change in `openshift.conf`: 384 385 ```console 386 $ sudo systemctl restart NetworkManager 387 ``` 388 389 - Create the manifests: 390 391 ```console 392 $ openshift-install --dir $INSTALL_DIR create manifests 393 ``` 394 395 - Domain entry in cluster-ingress-02-config.yml file should not contain cluster name: 396 397 ```console 398 # Assuming `test1` as cluster name 399 $ sed -i 's/test1.//' $INSTALL_DIR/manifests/cluster-ingress-02-config.yml 400 ``` 401 402 - Start the installer to create the cluster: 403 404 ```console 405 $ openshift-install --dir $INSTALL_DIR create cluster 406 ``` 407 408 ### Install throws an `Unable to resolve address 'localhost'` error 409 410 If you're seeing an error similar to 411 412 ``` 413 Error: Error refreshing state: 1 error(s) occurred: 414 415 * provider.libvirt: virError(Code=38, Domain=7, Message='Unable to resolve address 'localhost' service '-1': Servname not supported for ai_socktype') 416 417 418 FATA[0019] failed to run Terraform: exit status 1 419 ``` 420 421 it is likely that your install configuration contains three backslashes after the protocol (e.g. `qemu+tcp:///...`), when it should only be two. 422 423 ### Random domain creation errors due to libvirt race condition 424 425 Depending on your libvirt version you might encounter [a race condition][bugzilla_libvirt_race] leading to an error similar to: 426 427 ``` 428 * libvirt_domain.master.0: Error creating libvirt domain: virError(Code=43, Domain=19, Message='Network not found: no network with matching name 'test1'') 429 ``` 430 This is also being [tracked on the libvirt-terraform-provider][tfprovider_libvirt_race] but is likely not fixable on the client side, which is why you should upgrade libvirt to >=4.5 or a patched version, depending on your environment. 431 432 ### MacOS support currently broken 433 434 * Support for libvirt on Mac OS [is currently broken and being worked on][brokenmacosissue201]. 435 436 ### Error with firewall initialization on Arch Linux 437 438 If you're on Arch Linux and get an error similar to 439 440 ``` 441 libvirt: “Failed to initialize a valid firewall backend” 442 ``` 443 444 or 445 446 ``` 447 error: Failed to start network default 448 error: internal error: Failed to initialize a valid firewall backend 449 ``` 450 451 please check out [this thread on superuser][arch_firewall_superuser]. 452 453 ### GitHub Issue Tracker 454 455 You might find other reports of your problem in the [Issues tab for this repository][issues_libvirt] where we ask you to provide any additional information. 456 If your issue is not reported, please do. 457 458 [arch_firewall_superuser]: https://superuser.com/questions/1063240/libvirt-failed-to-initialize-a-valid-firewall-backend 459 [brokenmacosissue201]: https://github.com/openshift/installer/issues/201 460 [bugzilla_libvirt_race]: https://bugzilla.redhat.com/show_bug.cgi?id=1576464 461 [issues_libvirt]: https://github.com/openshift/installer/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+libvirt 462 [libvirt_selinux_issues]: https://github.com/dmacvicar/terraform-provider-libvirt/issues/142#issuecomment-409040151 463 [tfprovider_libvirt_race]: https://github.com/dmacvicar/terraform-provider-libvirt/issues/402#issuecomment-419500064 464 [kvm-install]: http://www.linux-kvm.org/page/FAQ#Preparing_to_use_KVM