Friday, April 26, 2024
spot_img

KubeVirt virtual machine initialization configuration

spot_img
spot_img

After the virtual machine is created, a lot of tedious and repetitive configuration work needs to be done each time. These tasks can also be completed by the cloud-init initialization tool. Currently, all public cloud platforms support the use of cloud-init to configure virtual machines. KubeVirt also supports cloud-init. Cloud images are basically installed with the cloud-init tool. Let’s take a look at how the KubeVirt virtual machine initializes the virtual machine.

NIC static IP

          networkData: |
            network:
              version: 1
              config:
                - type: physical
                  name: eth0
                  mac_addres: "00:00:00:d8:90:08"
                  subnets:
                    - type: static
                      address: 172.16.3.197
                      netmask: 255.255.255.0
                      routes:
                        - network: 0.0.0.0
                          netmask: 0.0.0.0
                          gateway: 172.16.3.2

system time zone

          userData: |-
            #cloud-config
            timezone: Asia/Kathmandu

Allow password login

          userData: |-
            #cloud-config
            ssh_pwauth: True

Set user password

          userData: |-
            #cloud-config
            chpasswd:
              list: |
                root:password
                centos:password
              expire: False

Configure hostname

          userData: |-
            #cloud-config
            hostname: website.sukai.com.np

Create a file

          userData: |-
            #cloud-config
            write_files:
            - path: "/etc/selinux/config"
              encoding: base64
              content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4IG9uIHRoZSBzeXN0ZW0uCiMgU0VMSU5VWD0gY2FuIHRha2Ugb25lIG9mIHRoZXNlIHRocmVlIHZhbHVlczoKIyAgICAgZW5mb3JjaW5nIC0gU0VMaW51eCBzZWN1cml0eSBwb2xpY3kgaXMgZW5mb3JjZWQuCiMgICAgIHBlcm1pc3NpdmUgLSBTRUxpbnV4IHByaW50cyB3YXJuaW5ncyBpbnN0ZWFkIG9mIGVuZm9yY2luZy4KIyAgICAgZGlzYWJsZWQgLSBObyBTRUxpbnV4IHBvbGljeSBpcyBsb2FkZWQuClNFTElOVVg9ZGlzYWJsZWQKIyBTRUxJTlVYVFlQRT0gY2FuIHRha2Ugb25lIG9mIHRocmVlIHZhbHVlczoKIyAgICAgdGFyZ2V0ZWQgLSBUYXJnZXRlZCBwcm9jZXNzZXMgYXJlIHByb3RlY3RlZCwKIyAgICAgbWluaW11bSAtIE1vZGlmaWNhdGlvbiBvZiB0YXJnZXRlZCBwb2xpY3kuIE9ubHkgc2VsZWN0ZWQgcHJvY2Vzc2VzIGFyZSBwcm90ZWN0ZWQuIAojICAgICBtbHMgLSBNdWx0aSBMZXZlbCBTZWN1cml0eSBwcm90ZWN0aW9uLgpTRUxJTlVYVFlQRT10YXJnZXRlZAoKCg==
            - path: /etc/rc.local
              permissions: "0755"
              owner: root
              content: |
                #!/bin/bash
                touch /var/lock/subsys/local
                arp -s 172.16.3.2 b8:69:f4:e6:5a:51

Excuting an order

          userData: |-
            #cloud-config
            runcmd:
            - echo 172.16.3.197 website.sukai.com.np >> /etc/hosts
            - [ chmod, +x, /etc/rc.d/rc.local]
            - [ arp, -s, 172.16.3.2, 'b8:69:f4:e6:5a:51']
            - echo nameserver 103.98.131.106 >> /etc/resolv.conf
            - [ sed, -i, -e, '/192.168.122.1/d', /etc/resolv.conf]
            - [ yum, -t, -y, update]
            - [ yum, -t, -y, install, screen, wget]
            - [ reboot]

Full configuration

      - name: cloudinitdisk
        cloudInitNoCloud:
          networkData: |
            network:
              version: 1
              config:
                - type: physical
                  name: eth0
                  mac_addres: "00:00:00:d8:90:08"
                  subnets:
                    - type: static
                      address: 172.16.3.197
                      netmask: 255.255.255.0
                      routes:
                        - network: 0.0.0.0
                          netmask: 0.0.0.0
                          gateway: 172.16.3.2
          userData: |-
            #cloud-config
            ssh_pwauth: True
            timezone: Asia/Kathmandu
            chpasswd:
              list: |
                root:password
                centos:password
              expire: False
            hostname: website.sukai.com.np
            write_files:
            - path: "/etc/selinux/config"
              encoding: base64
              content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4IG9uIHRoZSBzeXN0ZW0uCiMgU0VMSU5VWD0gY2FuIHRha2Ugb25lIG9mIHRoZXNlIHRocmVlIHZhbHVlczoKIyAgICAgZW5mb3JjaW5nIC0gU0VMaW51eCBzZWN1cml0eSBwb2xpY3kgaXMgZW5mb3JjZWQuCiMgICAgIHBlcm1pc3NpdmUgLSBTRUxpbnV4IHByaW50cyB3YXJuaW5ncyBpbnN0ZWFkIG9mIGVuZm9yY2luZy4KIyAgICAgZGlzYWJsZWQgLSBObyBTRUxpbnV4IHBvbGljeSBpcyBsb2FkZWQuClNFTElOVVg9ZGlzYWJsZWQKIyBTRUxJTlVYVFlQRT0gY2FuIHRha2Ugb25lIG9mIHRocmVlIHZhbHVlczoKIyAgICAgdGFyZ2V0ZWQgLSBUYXJnZXRlZCBwcm9jZXNzZXMgYXJlIHByb3RlY3RlZCwKIyAgICAgbWluaW11bSAtIE1vZGlmaWNhdGlvbiBvZiB0YXJnZXRlZCBwb2xpY3kuIE9ubHkgc2VsZWN0ZWQgcHJvY2Vzc2VzIGFyZSBwcm90ZWN0ZWQuIAojICAgICBtbHMgLSBNdWx0aSBMZXZlbCBTZWN1cml0eSBwcm90ZWN0aW9uLgpTRUxJTlVYVFlQRT10YXJnZXRlZAoKCg==
            - path: /etc/rc.local
              permissions: "0755"
              owner: root
              content: |
                #!/bin/bash
                touch /var/lock/subsys/local
                arp -s 172.16.3.2 b8:69:f4:e6:5a:51
            runcmd:
            - echo 172.16.3.197 website.sukai.com.np >> /etc/hosts
            - [ chmod, +x, /etc/rc.d/rc.local]
            - [ arp, -s, 172.16.3.2, 'b8:69:f4:e6:5a:51']
            - echo nameserver 103.98.131.106 >> /etc/resolv.conf
            - [ sed, -i, -e, '/192.168.122.1/d', /etc/resolv.conf]
            - [ yum, -t, -y, update]
            - [ yum, -t, -y, install, screen, wget]
            - [ reboot]

spot_img
spot_img

Related Articles

- Advertisment -spot_img
- Advertisment -spot_img

Recent Articles

spot_img

Popular Articles