云计算-容器云-KubeVirt 运维

KubeVirt 运维:创建 VM
使用提供的镜像在 kubevirt 命名空间下创建一台 VM,名称为 exam,指定 VM 的内存、CPU、网卡和磁盘等配置。

[root@k8s-master-node1 ~]# kubectl explain kubevirt.spec. --recursive |grep use
         useEmulation   <boolean>
[root@k8s-master-node1 ~]# kubectl -n kubevirt edit kubevirt
spec:
  certificateRotateStrategy: {}
  configuration:
    developerConfiguration: #{}
      useEmulation: true
[root@k8s-master-node1 ~]# vim vm.yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: exam
spec:
  running: true
  template:
    spec:
      domain:
        devices:
          disks:
            - name: vm
              disk: {}
        resources:
          requests:
            memory: 1Gi
      volumes:
        - name: vm
          containerDisk:
            image: fedora-virt:v1.0
            imagePullPolicy: IfNotPresent
[root@k8s-master-node1 ~]# kubectl apply -f vm.yaml
virtualmachine.kubevirt.io/exam created
[root@k8s-master-node1 ~]# kubectl get virtualmachine
NAME        AGE   STATUS    READY
exam   31s   Running   True
[root@k8s-master-node1 ~]# kubectl delete -f vm.yaml
virtualmachine.kubevirt.io "exam" deleted

KubeVirt 运维:VMI 管理
将提供的镜像在default命名空间下创建一台VMI,名称为exam,使用Service 对外暴露 VMI。

[root@k8s-master-node1 ~]# vim Dockerfile 
FROM scratch
ADD exam.qcow2 /disk/
[root@k8s-master-node1 ~]# docker build -t exam:v1.0 -f Dockerfile . 
[root@k8s-master-node1 ~]# vim exam.yaml 
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
  name: exam
  labels:
    app: exam
spec:
  domain:
    devices:
      disks:
      - name: containerdisk
        disk:
          bus: virtio
      - name: cloudinitnodisk
        disk:
          bus: virtio
    resources:
      requests:
        memory: 512Mi
  volumes:
    - name: containerdisk
      containerDisk:
        image: exam:v1.0
        imagePullPolicy: IfNotPresent
    - name: cloudinitnodisk
      cloudInitNoCloud:
        userData: |-
          hostname: exam
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  name: exam
  labels:
    app: exam
spec:
  ports:
  - name: 80-80
    port: 80
    nodePort: 30082 # 节点端口
    protocol: TCP
    targetPort: 80 # 目标端口
  selector:
    app: exam
  type: NodePort
[root@k8s-master-node1 ~]# kubectl apply -f exam.yaml
virtualmachineinstance.kubevirt.io/exam created
service/exam created
[root@k8s-master-node1 ~]# kubectl get vmi
NAME   AGE   PHASE     IP            NODENAME           READY
exam   60s   Running   10.244.0.50   k8s-master-node1   True
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值