Fedora 41
Sponsored Link

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

 

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

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

-----------+---------------------------+--------------------------+------------
           |                           |                          |
       eth0|10.0.0.30              eth0|10.0.0.51             eth0|10.0.0.52
+----------+-----------+   +-----------+----------+   +-----------+----------+
|   [ dlp.srv.world ]  |   | [ node01.srv.world ] |   | [ node02.srv.world ] |
|     Control Plane    |   |      Worker Node     |   |      Worker Node     |
+----------------------+   +----------------------+   +----------------------+

[1]

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

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

[root@dlp ~]#
export VERSION=$(echo ${TAG##*/})

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

[root@dlp ~]#
wget https://github.com/kubevirt/containerized-data-importer/releases/download/${VERSION}/cdi-cr.yaml
[root@dlp ~]#
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@dlp ~]#
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@dlp ~]#
kubectl apply -f cdi-cr.yaml

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

[root@dlp ~]#
kubectl get pods -n cdi

NAME                               READY   STATUS    RESTARTS   AGE
cdi-apiserver-55dd9447cb-px9mj     1/1     Running   0          2m29s
cdi-deployment-55c6d9fc49-9rx4m    1/1     Running   0          2m29s
cdi-operator-7f5bc68fc5-tgprq      1/1     Running   0          2m50s
cdi-uploadproxy-5b76f7c876-fh8wx   1/1     Running   0          2m29s
[3] एक वर्चुअल मशीन बनाएँ। इस उदाहरण में, इसे Fedora 41 के साथ बनाएँ।
[root@dlp ~]#
kubectl get sc

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

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

[root@dlp ~]#
vi fedora-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: "fedora-pvc"
  labels:
    app: containerized-data-importer
  annotations:
    cdi.kubevirt.io/storage.import.endpoint: "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-AmazonEC2-41-1.4.x86_64.raw.xz"
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 15Gi
  storageClassName: nfs-client

[root@dlp ~]#
kubectl apply -f fedora-pvc.yml

persistentvolumeclaim/fedora-pvc created
[root@dlp ~]#
kubectl get pvc

NAME         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
fedora-pvc   Bound    pvc-f7bcb943-1b3f-42f8-a35b-605ded78ec44   15Gi       RWO            nfs-client     <unset>                 9m

[root@dlp ~]#
kubectl get pods

NAME                  READY   STATUS    RESTARTS   AGE
importer-fedora-pvc   1/1     Running   0          14s

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

[root@dlp ~]#
kubectl logs -f importer-fedora-pvc

.....
.....
I1106 06:04:15.804515       1 data-processor.go:341] Expanding image size to: 15220080640
E1106 06:04:15.809706       1 prlimit.go:156] failed to kill the process; os: process already finished
I1106 06:04:15.809722       1 data-processor.go:253] Validating image
E1106 06:04:15.813337       1 prlimit.go:156] failed to kill the process; os: process already finished
I1106 06:04:15.816310       1 data-processor.go:247] New phase: Complete
I1106 06:04:15.816915       1 importer.go:231] {"scratchSpaceRequired":false,"preallocationApplied":false,"message":"Import Complete"}

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

[root@dlp ~]#
kubectl get pods

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

[root@dlp ~]#
vi fedora-vm.yml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: fedora41
  labels:
    kubevirt.io/os: linux
spec:
  running: true
  template:
    spec:
      domain:
        cpu:
          cores: 2
        devices:
          disks:
          - disk:
              bus: virtio
            name: disk0
          - cdrom:
              bus: sata
              readonly: true
            name: cloudinitdisk
        machine:
          type: q35
        resources:
          requests:
            memory: 4096M
      volumes:
      - name: disk0
        persistentVolumeClaim:
          claimName: fedora-pvc
      - cloudInitNoCloud:
          userData: |
            #cloud-config
            hostname: fedora41
            ssh_pwauth: true
            disable_root: false
            chpasswd:
              list: |
                root:myrootpassword
                fedora:userpassword
              expire: False
        name: cloudinitdisk

[root@dlp ~]#
kubectl apply -f fedora-vm.yml

virtualmachine.kubevirt.io/fedora41 created
[root@dlp ~]#
kubectl get vms

NAME       AGE   STATUS    READY
fedora41   8s    Running   True

[root@dlp ~]#
kubectl get vmi

NAME       AGE     PHASE     IP               NODENAME           READY
fedora41   2m49s   Running   192.168.40.217   node01.srv.world   True

[root@dlp ~]# virtctl console fedora41 
Successfully connected to fedora41 console. The escape sequence is ^]

fedora41 login: root
Password:
[root@fedora41 ~]#

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

[root@dlp ~]# ssh fedora@192.168.40.217
The authenticity of host '192.168.40.217 (192.168.40.217)' can't be established.
ED25519 key fingerprint is SHA256:eH+Jf4nj0c+OvjGYm+RBtBHc1K3pwYxdjUxvLXjTNAU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.40.217' (ED25519) to the list of known hosts.
fedora@192.168.40.217's password:
[fedora@fedora41 ~]$
मिलान सामग्री