Ubuntu 24.04
Sponsored Link

Kubernetes : वर्चुअल मशीन बनाएं2024/11/18

 

KubeVirt के साथ एक वर्चुअल मशीन बनाएँ।

यह उदाहरण निम्न प्रकार के वातावरण पर आधारित है।

+----------------------+   +----------------------+
|  [ ctrl.srv.world ]  |   |   [ dlp.srv.world ]  |
|     Manager Node     |   |     Control Plane    |
+-----------+----------+   +-----------+----------+
        eth0|10.0.0.25             eth0|10.0.0.30
            |                          |
------------+--------------------------+-----------
            |                          |
        eth0|10.0.0.51             eth0|10.0.0.52
+-----------+----------+   +-----------+----------+
| [ node01.srv.world ] |   | [ node02.srv.world ] |
|     Worker Node#1    |   |     Worker Node#2    |
+----------------------+   +----------------------+

[1]

OS छवियों को संग्रहीत करने के लिए एक स्थायी संग्रहण की आवश्यकता होती है।
इस उदाहरण पर, कंट्रोल प्लेन नोड पर NFS सर्वर स्थापित करें और [/home/nfsshare] निर्देशिका को NFS शेयर के रूप में कॉन्फ़िगर करें बाहरी स्थायी संग्रहण के रूप में, और NFS प्लगइन के साथ डायनेमिक वॉल्यूम प्रोविज़निंग को भी कॉन्फ़िगर करें जैसे कि [1], [2], [3], [4] का उदाहरण।

[2] ओएस छवियों को संग्रहीत करने के लिए कंटेनरीकृत डेटा आयातक स्थापित करें।
root@ctrl:~#
export TAG=$(curl -s -w %{redirect_url} https://github.com/kubevirt/containerized-data-importer/releases/latest)

root@ctrl:~#
export VERSION=$(echo ${TAG##*/})

root@ctrl:~#
wget https://github.com/kubevirt/containerized-data-importer/releases/download/${VERSION}/cdi-operator.yaml

root@ctrl:~#
wget https://github.com/kubevirt/containerized-data-importer/releases/download/${VERSION}/cdi-cr.yaml
root@ctrl:~#
vi cdi-cr.yaml
apiVersion: cdi.kubevirt.io/v1beta1
kind: CDI
metadata:
  name: cdi
spec:
  config:
    # मेमोरी सीमा का विस्तार करने के लिए संसाधन अनुभाग जोड़ें
    podResourceRequirements:
      limits:
        cpu: '1'
        memory: 4Gi
    featureGates:
    - HonorWaitForFirstConsumer
  imagePullPolicy: IfNotPresent
  infra:
    nodeSelector:
      kubernetes.io/os: linux
    tolerations:
    - key: CriticalAddonsOnly
      operator: Exists
  workload:
    nodeSelector:
      kubernetes.io/os: linux

root@ctrl:~#
kubectl apply -f cdi-operator.yaml

namespace/cdi created
customresourcedefinition.apiextensions.k8s.io/cdis.cdi.kubevirt.io created
clusterrole.rbac.authorization.k8s.io/cdi-operator-cluster created
clusterrolebinding.rbac.authorization.k8s.io/cdi-operator created
serviceaccount/cdi-operator created
role.rbac.authorization.k8s.io/cdi-operator created
rolebinding.rbac.authorization.k8s.io/cdi-operator created
deployment.apps/cdi-operator created

root@ctrl:~#
kubectl apply -f cdi-cr.yaml

cdi.cdi.kubevirt.io/cdi created
# कुछ मिनटों के बाद, पॉड्स निम्नानुसार शुरू हो जाएंगे

root@ctrl:~#
kubectl get pods -n cdi

NAME                               READY   STATUS    RESTARTS   AGE
cdi-apiserver-555ccd5f7b-nkf96     1/1     Running   0          30s
cdi-deployment-8bf6546cc-xhhrg     1/1     Running   0          30s
cdi-operator-659fd5d79-g49j6       1/1     Running   0          42s
cdi-uploadproxy-6dcd6d454b-t985r   1/1     Running   0          30s
[3] एक वर्चुअल मशीन बनाएँ। इस उदाहरण में, इसे Ubuntu 24.04 के साथ बनाएँ।
root@ctrl:~#
kubectl get sc

NAME         PROVISIONER                                                RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-client   cluster.local/nfs-client-nfs-subdir-external-provisioner   Delete          Immediate           true                   2m42s

# पीवीसी परिभाषा बनाएं

root@ctrl:~#
vi ubuntu-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: "ubuntu-pvc"
  labels:
    app: containerized-data-importer
  annotations:
    cdi.kubevirt.io/storage.import.endpoint: "http://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 15Gi
  storageClassName: nfs-client

root@ctrl:~#
kubectl apply -f ubuntu-pvc.yml

persistentvolumeclaim/ubuntu-pvc created
root@ctrl:~#
kubectl get pvc

NAME         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
ubuntu-pvc   Bound    pvc-7eb289d4-d9c9-4f94-8043-5b6e29c421a4   15Gi       RWO            nfs-client     <unset>                 5s

root@ctrl:~#
kubectl get pods

NAME                  READY   STATUS    RESTARTS   AGE
importer-ubuntu-pvc   1/1     Running   0          18s

# आयातित लॉग देखना संभव है

root@ctrl:~#
kubectl logs -f importer-fedora-pvc

.....
.....
I1118 02:34:00.808524       1 data-processor.go:341] Expanding image size to: 15220080640
E1118 02:34:00.840043       1 prlimit.go:156] failed to kill the process; os: process already finished
I1118 02:34:00.840066       1 data-processor.go:253] Validating image
E1118 02:34:00.844044       1 prlimit.go:156] failed to kill the process; os: process already finished
I1118 02:34:00.853015       1 data-processor.go:247] New phase: Complete
I1118 02:34:00.853219       1 importer.go:231] {"scratchSpaceRequired":false,"preallocationApplied":false,"message":"Import Complete"}

# आयात समाप्त करने के बाद, आयातक पॉड भी समाप्त हो जाएगा

root@ctrl:~#
kubectl get pods

No resources found in default namespace.
# VM परिभाषा बनाएं

root@ctrl:~#
vi ubuntu-vm.yml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: ubuntu2404
  labels:
    kubevirt.io/os: linux
spec:
  runStrategy: Halted
  template:
    spec:
      domain:
        cpu:
          cores: 2
        devices:
          disks:
          - disk:
              bus: virtio
            name: disk0
          - cdrom:
              bus: sata
              readonly: true
            name: cloudinitdisk
          interfaces:
          - name: default
            masquerade: {}
        machine:
          type: q35
        resources:
          requests:
            memory: 4096M
      networks:
      - name: default
        pod: {}
      volumes:
      - name: disk0
        persistentVolumeClaim:
          claimName: ubuntu-pvc
      - cloudInitNoCloud:
          userData: |
            #cloud-config
            hostname: ubuntu2404
            ssh_pwauth: true
            disable_root: false
            chpasswd:
              list: |
                root:myrootpassword
                ubuntu:userpassword
              expire: False
        name: cloudinitdisk

root@ctrl:~#
kubectl apply -f ubuntu-vm.yml

virtualmachine.kubevirt.io/ubuntu2404 created
root@ctrl:~#
kubectl get vms

NAME         AGE   STATUS    READY
ubuntu2404   19s   Stopped   False

root@ctrl:~# virtctl start ubuntu2404 
VM ubuntu2404 was scheduled to start

root@ctrl:~#
kubectl get vmi

NAME         AGE   PHASE     IP               NODENAME           READY
ubuntu2404   22s   Running   192.168.40.232   node01.srv.world   True

root@ctrl:~# virtctl console ubuntu2404 
Successfully connected to ubuntu2404 console. The escape sequence is ^]

ubuntu2404 login: root
Password:
Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 6.8.0-48-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Mon Nov 18 02:44:16 UTC 2024

.....
.....
root@ubuntu2404:~#

# होस्ट के कंसोल पर वापस जाने के लिए, Ctrl + ] कुंजी दबाएँ
# * virsh कमांड के समान ऑपरेशन


# ssh के माध्यम से VM से कनेक्ट करें
root@ctrl:~# kubectl get pods 
NAME                             READY   STATUS    RESTARTS   AGE
virt-launcher-ubuntu2404-mg4gs   2/2     Running   0          101s

root@ctrl:~# kubectl port-forward pod/virt-launcher-ubuntu2404-mg4gs 222:22 & 

root@ctrl:~# ssh ubuntu@127.0.0.1 -p 222 
Handling connection for 222
The authenticity of host '[127.0.0.1]:222 ([127.0.0.1]:222)' can't be established.
ED25519 key fingerprint is SHA256:W/jCnIP+PoghhP3FOrVDa9HBGjOzip+QVBqGEep5roM.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[127.0.0.1]:222' (ED25519) to the list of known hosts.
ubuntu@127.0.0.1's password:
Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 6.8.0-48-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Mon Nov 18 05:25:15 UTC 2024

.....
.....

ubuntu@ubuntu2404:~$
मिलान सामग्री