Kubevirt 部署虚拟机

2 篇文章 0 订阅
1 篇文章 0 订阅

Architecture

KubeVirt is built using a service oriented architecture and a choreography pattern.

Stack

  +---------------------+
  | KubeVirt            |
~~+---------------------+~~
  | Orchestration (K8s) |
  +---------------------+
  | Scheduling (K8s)    |
  +---------------------+
  | Container Runtime   |
~~+---------------------+~~
  | Operating System    |
  +---------------------+
  | (Virtual)           |
~~+---------------------+~~
  | Physical            |
  +---------------------+

Users requiring virtualization services are speaking to the Virtualization API (see below) which in turn is speaking to the Kubernetes cluster to schedule requested VMIs. Scheduling, networking, and storage are all delegated to Kubernetes, while KubeVirt provides the virtualization functionality.

Kubevirt Architecture

部署

部署k8s集群

kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.13.0 --pod-network-cidr=192.168.0.0/16

kubectl taint nodes --all node-role.kubernetes.io/master-

kubectl apply -f weave-daemonset-k8s-1.7.yaml

部署Kubevirt基础组件

下载Kubevirt yaml文件:

[root@master kubevirt]# wget https://github.com/kubevirt/kubevirt/releases/download/v0.11.1/kubevirt.yaml
--2019-01-10 19:36:53--  https://github.com/kubevirt/kubevirt/releases/download/v0.11.1/kubevirt.yaml
Resolving github.com (github.com)... 13.250.177.223, 13.229.188.59, 52.74.223.119
Connecting to github.com (github.com)|13.250.177.223|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/76686583/b0e77400-febe-11e8-97df-11a2baaa9902?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190110%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190110T113654Z&X-Amz-Expires=300&X-Amz-Signature=4ca7c40ab5140015fd5dc9974e0e40ce2a9d8b465bb566b0f626e57fb27f8b5e&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dkubevirt.yaml&response-content-type=application%2Foctet-stream [following]
--2019-01-10 19:36:55--  https://github-production-release-asset-2e65be.s3.amazonaws.com/76686583/b0e77400-febe-11e8-97df-11a2baaa9902?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190110%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190110T113654Z&X-Amz-Expires=300&X-Amz-Signature=4ca7c40ab5140015fd5dc9974e0e40ce2a9d8b465bb566b0f626e57fb27f8b5e&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dkubevirt.yaml&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.163.3
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.163.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16625 (16K) [application/octet-stream]
Saving to: ‘kubevirt.yaml’

100%[===================================================================================>] 16,625      65.2KB/s   in 0.2s   

2019-01-10 19:36:56 (65.2 KB/s) - ‘kubevirt.yaml’ saved [16625/16625]

[root@master kubevirt]# ls
kubevirt.yaml
[root@master kubevirt]# 

创建kubevirt命名空间文件:

[root@master kubevirt]# cat kubevirt-namespaces.yaml 
apiVersion: v1
kind: Namespace
metadata:
    name: kubevirt
    labels:
        name: kubevirt
[root@master kubevirt]# 
[root@master kubevirt]# kubectl create -f kubevirt-namespaces.yaml 
namespace/kubevirt created
[root@master kubevirt]# kubectl get ns
NAME          STATUS   AGE
default       Active   5m27s
kube-public   Active   5m27s
kube-system   Active   5m27s
kubevirt      Active   3s
[root@master kubevirt]# 

部署kubevirt:

[root@master kubevirt]# kubectl apply -f kubevirt.yaml       
service/kubevirt-prometheus-metrics created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:admin created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:edit created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:view created
serviceaccount/kubevirt-apiserver created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-apiserver created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-apiserver-auth-delegator created
rolebinding.rbac.authorization.k8s.io/kubevirt-apiserver created
role.rbac.authorization.k8s.io/kubevirt-apiserver created
clusterrole.rbac.authorization.k8s.io/kubevirt-apiserver created
clusterrole.rbac.authorization.k8s.io/kubevirt-controller created
serviceaccount/kubevirt-controller created
serviceaccount/kubevirt-privileged created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-controller created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-privileged-cluster-admin created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:default created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt.io:default created
service/virt-api created
deployment.extensions/virt-api created
deployment.extensions/virt-controller created
daemonset.extensions/virt-handler created
customresourcedefinition.apiextensions.k8s.io/virtualmachineinstances.kubevirt.io created
customresourcedefinition.apiextensions.k8s.io/virtualmachineinstancereplicasets.kubevirt.io created
customresourcedefinition.apiextensions.k8s.io/virtualmachineinstancepresets.kubevirt.io created
customresourcedefinition.apiextensions.k8s.io/virtualmachines.kubevirt.io created
customresourcedefinition.apiextensions.k8s.io/virtualmachineinstancemigrations.kubevirt.io created
[root@master kubevirt]# 
[root@master kubevirt]# kubectl get pod --all-namespaces
NAMESPACE     NAME                              READY   STATUS    RESTARTS   AGE
kube-system   coredns-78d4cf999f-jrrn9          1/1     Running   0          3h14m
kube-system   coredns-78d4cf999f-mvjzw          1/1     Running   0          3h14m
kube-system   etcd-master                       1/1     Running   0          3h14m
kube-system   kube-apiserver-master             1/1     Running   0          3h14m
kube-system   kube-controller-manager-master    1/1     Running   0          3h13m
kube-system   kube-proxy-m67ln                  1/1     Running   0          3h14m
kube-system   kube-scheduler-master             1/1     Running   0          3h14m
kube-system   weave-net-cn8sh                   2/2     Running   0          3h14m
kubevirt      virt-api-b7cdfd6cd-48mzd          1/1     Running   0          73s
kubevirt      virt-api-b7cdfd6cd-kpnqn          1/1     Running   0          73s
kubevirt      virt-controller-dcbb76d59-6jg7j   1/1     Running   0          73s
kubevirt      virt-controller-dcbb76d59-t2dlp   1/1     Running   0          73s
kubevirt      virt-handler-sgbr2                1/1     Running   0          73s
[root@master kubevirt]# 

创建Kubevirt虚拟机

[root@master vnf]# ls
Dockerfile  vnf.qcow2
[root@master vnf]# cat Dockerfile 
FROM kubevirt/container-disk-v1alpha

# Add vm
COPY vnf.qcow2 /disk/
RUN mkdir -p /custom-disk && cp /disk/vnf.qcow2 /custom-disk/vnf.qcow2
[root@master vnf]# docker build -t kubevirt:vnf .
Sending build context to Docker daemon 870.3 MB
Step 1/3 : FROM kubevirt/container-disk-v1alpha
 ---> 6c3f9c17f1cb
Step 2/3 : COPY vnf.qcow2 /disk/
 ---> 457800959812
Removing intermediate container bc285be0d5f8
Step 3/3 : RUN mkdir -p /custom-disk && cp /disk/vnf.qcow2 /custom-disk/vnf.qcow2
 ---> Running in 8ba431fd1942

 ---> e8e7f322cfc7
Removing intermediate container 8ba431fd1942
Successfully built e8e7f322cfc7
[root@master vnf]# 

创建部署Kubevirt虚拟器yaml文件

[root@master kubevirt]# cat vm-vnf.yaml 
apiVersion: kubevirt.io/v1alpha2
kind: VirtualMachine
metadata:
  name: vnf
spec:
  running: false
  template:
    metadata:
      labels: 
        guest: vnf
        kubevirt.io/size: small
    spec:
      domain:
        resources:
          requests:
            memory: 2048M
        devices:
          disks:
          - name: containerdisk
            volumeName: registryvolume
            disk: {}
      volumes:
        - name: registryvolume
          containerDisk:
            image: kubevirt:vnf
[root@master kubevirt]# 

部署Kubevirt虚拟机

[root@master kubevirt]# kubectl apply -f vm-vnf.yaml 
virtualmachine.kubevirt.io/vnf created
[root@master kubevirt]# 

下载virtctl工具:

[root@master kubevirt]# curl -L -o virtctl https://github.com/kubevirt/kubevirt/releases/download/v0.11.1/virtctl-v0.11.1-linux-amd64
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    374      0 --:--:--  0:00:01 --:--:--   374
100 36.9M  100 36.9M    0     0   214k      0  0:02:56  0:02:56 --:--:--  229k
[root@master kubevirt]# 
[root@master kubevirt]# ./virtctl start vnf
VM vnf was scheduled to start
[root@master kubevirt]# kubectl get pod
NAME                      READY   STATUS    RESTARTS   AGE
virt-launcher-vnf-2rkmd   2/2     Running   0          29s
[root@master kubevirt]# 

登录vnf虚拟机:

[root@master kubevirt]# ./virtctl console vnf
Successfully connected to vnf console. The escape sequence is ^]

localhost login: develop
Serial:703B-12E5-4821-670B  Status:788414
Password: 
[root@master kubevirt]# 
[root@master kubevirt]# 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值