이 빠른 시작에서는 GDC용 VM 런타임을 사용하여 Google Distributed Cloud에서 가상 머신(VM)을 만드는 방법을 설명합니다. GDC용 VM 런타임은 KubeVirt를 사용하여 클러스터에서 VM을 조정하므로 동일한 개발 환경에서 VM 기반 앱과 워크로드를 사용할 수 있습니다.
Google Distributed Cloud 버전 1.10 이상에서는 GDC용 VM 런타임이 자동으로 설치되지만 기본적으로 중지되어 있습니다. Google Distributed Cloud에서 VM 리소스를 실행하려면 먼저 GDC용 VM 런타임을 사용 설정해야 합니다.
bmctl
Google Distributed Cloud 버전 1.11 이상에서는 bmctl 명령줄 도구를 사용할 수 있습니다.
런타임을 사용 설정하려면 bmctl 도구를 사용합니다.
bmctlenablevmruntime--kubeconfigKUBECONFIG_PATH
클러스터의 kubeconfig 파일 경로를 제공합니다.
클러스터를 만들면 Google Distributed Cloud가 kubeconfig 파일을 관리자 워크스테이션에 생성합니다. 기본적으로 경로는 bmctl-workspace/CLUSTER_NAME/CLUSTER_NAME-kubeconfig입니다.
GDC용 VM 런타임이 이미 사용 설정되어 있으면 명령어에서 오류를 반환합니다.
커스텀 리소스
Google Distributed Cloud 버전 1.10 이상은 커스텀 리소스 정의를 사용하여 GDC용 VM 런타임을 사용 설정할 수 있습니다. 이 커스텀 리소스는 기본적으로 설치되어 있습니다.
VMRuntime 커스텀 리소스를 수정합니다.
kubectleditvmruntime
사양에서 enabled:true를 설정합니다.
apiVersion:vm.cluster.gke.io/v1kind:VMRuntimemetadata:name:vmruntimespec:enabled:true# useEmulation defaults to "false" if not set.useEmulation:true# vmImageFormat defaults to "qcow2" if not set.vmImageFormat:qcow2
앞의 spec 섹션에서 다음 값을 설정할 수 있습니다.
enabled: GDC용 VM 런타임을 사용 설정하려면 true로 설정합니다.
useEmulation: 노드가 하드웨어 가상화를 지원하지 않거나 확실하지 않으면 값을 true로 설정합니다. 사용 가능한 경우 하드웨어 가상화에서 소프트웨어 에뮬레이션보다 우수한 성능을 제공합니다. useEmulation 필드가 지정되지 않으면 기본값은 false입니다.
vmImageFormat: 두 가지 디스크 이미지 형식 값인 raw 및 qcow2를 지원합니다. vmImageFormat을 설정하지 않으면 GDC용 VM 런타임에서 raw 디스크 이미지 형식을 사용하여 VM을 만듭니다. raw 형식은 쓰기 형식의 사본인 qcow2보다 우수한 성능을 제공할 수 있지만 더 많은 디스크를 사용할 수 있습니다. VM의 이미지 형식에 대한 자세한 내용은 QEMU 문서의 디스크 이미지 파일 형식을 참조하세요.
편집기에서 커스텀 리소스를 저장합니다.
VMRuntime 커스텀 리소스가 사용 설정되었는지 확인합니다.
kubectldescribevmruntimevmruntime
VMRuntime 커스텀 리소스의 세부정보에는 Status 섹션이 포함됩니다.
VMRuntime.Status.Ready가 true로 표시되면 GDC용 VM 런타임이 사용 설정되고 작동 중입니다.
사용자 인증 정보를 사용해서 인증을 수행하고 virtctl 클라이언트 도구를 다운로드한 후 /usr/bin/kubectl-virt를 로컬 머신에 설치할 수 있습니다.
virtctl 플러그인이 설치되었는지 확인합니다.
kubectlpluginlist
응답에 kubectl-virt가 나열되었으면 플러그인이 성공적으로 설치되어 것입니다.
kubectl-virt가 나열되지 않으면 bmctl-workspace/log/install-virtctl-[date]/install-virtctl.log와 같이 이전 bmctl install 명령어 결과에 표시된 대로 install-virtctl.log 파일을 확인합니다.
VM 만들기
이 빠른 시작에서는 kubectl CLI를 사용하여 공개 VM 이미지와 기본 사용자 인증 정보를 사용하는 VM을 만듭니다.
클러스터에 VM을 만듭니다. virtctl 플러그인은 kubectl 명령어와 함께 사용됩니다.
이 명령어는 Ubuntu 20.04 VM과 2 CPU, 4Gi 메모리, local-shared 스토리지 클래스를 사용하는 ReadWriteOnce 모드의 20Gi 부팅 디스크를 기본적으로 만듭니다. 다음 값을 바꿉니다.
VM_NAME: VM의 이름입니다. VM 이름에 소문자 영숫자 문자나 '-'만 사용해야 하며 이름은 영숫자 문자로 시작하고 끝나야 하며 63자 이하여야 합니다. 자세한 내용은 Kubernetes 문서의 RFC 1123 라벨 이름을 참조하세요.
USERNAME: VM에서 만들려는 계정의 사용자 이름입니다.
PASSWORD: 사용자 계정의 비밀번호입니다.
CLI 매개변수에 대한 오류가 수신되면 클러스터 버전이 1.11.1 이상이고 virtctl 클라이언트 도구가 최신 버전인지 확인합니다. CLI 오류에 대한 자세한 내용은 콘솔 로그를 참조하세요. 사용자 이름 및 비밀번호 규칙은 게스트 운영체제(OS) 문서를 참조하세요. 예상대로 작동하지 않으면 GDC용 VM 런타임에서 알려진 문제를 확인하세요.
VM을 만드는 데 몇 분 정도 걸릴 수 있습니다. kubectl 명령어로 VM 상태를 확인합니다.
kubectlgetgvm
다음 출력 예시는 Running 상태의 VM을 보여줍니다.
NAME STATUS AGE IP
vm-sample1 Running 64s 192.168.2.124
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-11-22(UTC)"],[],[],null,["This quickstart shows you how to use VM Runtime on GDC to create a\nvirtual machine (VM) on Google Distributed Cloud. VM Runtime on GDC uses\n[KubeVirt](https://kubevirt.io/)\nto orchestrate VMs on clusters, and lets you work with your VM-based apps and\nworkloads in a uniform development environment.\n\nBefore you begin\n\nTo complete this quickstart, you need access to Google Distributed Cloud version\n1.12 (`anthosBareMetalVersion: 1.12`) or higher cluster. You can use any\ncluster type capable of running workloads. If needed,\n[try Google Distributed Cloud on Compute Engine](/kubernetes-engine/distributed-cloud/bare-metal/docs/try/gce-vms)\nor see the\n[cluster creation overview](/kubernetes-engine/distributed-cloud/bare-metal/docs/installing/creating-clusters/create-clusters-overview).\n\nEnable VM Runtime on GDC\n\nVM Runtime on GDC is automatically installed in Google Distributed Cloud\nversion 1.10 or higher, but is disabled by default. Before you can run VM\nresources in your Google Distributed Cloud, you must enable the\nVM Runtime on GDC. \n\nbmctl\n\nGoogle Distributed Cloud version 1.11 or higher can use the `bmctl` command-line tool:\n\n- To enable the runtime, use the `bmctl` tool:\n\n bmctl enable vmruntime --kubeconfig \u003cvar label=\"Kubeconfig path\" translate=\"no\"\u003eKUBECONFIG_PATH\u003c/var\u003e\n\n Provide the path to the kubeconfig file for your cluster.\n Google Distributed Cloud generates the kubeconfig file on the admin\n workstation when you create a cluster. By default, the path is\n `bmctl-workspace/`\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e`-kubeconfig`.\n\n If VM Runtime on GDC is already enabled, the command returns an\n error.\n\nCustom resource\n\nGoogle Distributed Cloud version 1.10 or higher can use a custom resource definition\nto enable VM Runtime on GDC. This custom resource is installed by\ndefault.\n\n1. Edit the `VMRuntime` custom resource:\n\n kubectl edit vmruntime\n\n2. Set `enabled:true` in the spec:\n\n apiVersion: vm.cluster.gke.io/v1\n kind: VMRuntime\n metadata:\n name: vmruntime\n spec:\n enabled: true\n # useEmulation defaults to \"false\" if not set.\n useEmulation: true\n # vmImageFormat defaults to \"qcow2\" if not set.\n vmImageFormat: qcow2\n\n In the preceding `spec` section, the following values can be set:\n - `enabled`: set to true to enable VM Runtime on GDC\n - `useEmulation`: If your node doesn't support hardware virtualization, or you aren't sure, set the value to true. If available, hardware virtualization provides better performance than software emulation. The `useEmulation` field defaults to `false`, if it isn't specified.\n - `vmImageFormat`: Supports two disk image format values: `raw` and `qcow2`. If you don't set `vmImageFormat`, the VM Runtime on GDC uses the `raw` disk image format to create VMs. The `raw` format may provide improved performance over `qcow2`, a copy on write format, but may use more disk. For more information about the image formats for your VM, see [Disk image file formats](https://www.qemu.org/docs/master/system/images.html#disk-image-file-formats) in the QEMU documentation.\n3. Save the custom resource in your editor.\n\n4. Verify that the `VMRuntime` custom resource is enabled:\n\n kubectl describe vmruntime vmruntime\n\n The details of the `VMRuntime` custom resource include a `Status` section.\n VM Runtime on GDC is enabled and working when\n `VMRuntime.Status.Ready` shows as `true`.\n\nInstall the `virtctl` client tool\n\nTo create and manage VMs, install the\n[virtctl client tool](https://kubevirt.io/user-guide/operations/virtctl_client_tool/).\n\n1. Install the `virtctl` client tool as a `kubectl` plugin:\n\n export GOOGLE_APPLICATION_CREDENTIALS=\"\u003cvar label=\"name\" translate=\"no\"\u003ePATH_TO_SERVICE_ACCOUNT_KEY\u003c/var\u003e/bm-gcr.json\"\n sudo -E bmctl install virtctl\n\n The credentials let you authenticate and download the `virtctl` client tool,\n then install to `/usr/bin/kubectl-virt` on your local machine.\n2. Verify that the `virtctl` plugin is installed:\n\n kubectl plugin list\n\n If `kubectl-virt` is listed in the response, the plugin is successfully\n installed.\n\n If `kubectl-virt` is not listed, check the `install-virtctl.log` file as noted\n in the output of the previous `bmctl install` command, such as\n `bmctl-workspace/log/install-virtctl-[date]/install-virtctl.log`.\n\nCreate a VM\n\nIn this quickstart, you use the `kubectl` CLI to create a VM that uses a public\nVM image and default credentials.\n| **Note:** For instructions on creating a VM from a `VirtualMachine` YAML manifest file, see [Tutorial: Create and manage a Linux VM in VM Runtime on GDC](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/tutorial-create-vm).\n\n1. Create a VM in your cluster. The `virtctl` plugin is used with the\n `kubectl` command:\n\n kubectl virt create vm \u003cvar label=\"name\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e \\\n --image ubuntu20.04 \\\n --configure-initial-password \u003cvar label=\"username\" translate=\"no\"\u003eUSERNAME\u003c/var\u003e:\u003cvar label=\"name\" translate=\"no\"\u003ePASSWORD\u003c/var\u003e\n\n This command creates an *Ubuntu 20.04* VM and defaults of *2* CPU, *4Gi*\n memory, and a *20Gi* boot disk in *ReadWriteOnce* mode using the\n *local-shared* storage class. Replace the following values:\n - \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e: name for your VM. VM names must contain only lowercase alphanumeric characters or '-', start and end with an alphanumeric character, and contain at most 63 characters. For more information, see [RFC 1123 Label Names](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names) in the Kubernetes documentation.\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: user name for the account to create on the VM.\n - \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e: password for the user account.\n\n If you receive an error about CLI parameters, verify that your cluster is at\n version `1.11.1` or higher and that you have the latest version of the\n `virtctl` client tool. For more information about CLI errors, consult the\n console log. For username and password rules, see the documentation for the\n guest operating system (OS). If something isn't working as expected, check for\n [VM Runtime on GDC known issues](/kubernetes-engine/distributed-cloud/bare-metal/docs/troubleshooting/known-issues).\n | **Note:** The preceding command creates a YAML file, such as `vm-sample1.yaml`, in the `~/google-virtctl` directory. You can view the content of this file to see the definition of the Kubernetes resources that were created by VM Runtime on GDC.\n2. It can take a few minutes to create the VM. Check the status of the VM with\n the `kubectl` command:\n\n kubectl get gvm\n\n The following example output shows the VM in a `Running` state: \n\n NAME STATUS AGE IP\n vm-sample1 Running 64s 192.168.2.124\n\nConnect to your VM\n\nWhen your VM is running, connect to the console of the VM.\n\n1. To access a VM from the console, use `kubectl`:\n\n kubectl virt console \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e\n\n2. When prompted, enter the user credentials you specified to create the VM.\n\n3. After you have successfully connected to the console of the VM, exit the VM\n session and console:\n\n Ctrl + ]\n\nClean up\n\nTo clean up the resources created in this quickstart, follow these steps.\n\n1. To delete the VM and associated DataVolume, use `kubectl`:\n\n kubectl virt delete vm \u003cvar scope=\"VM_NAME\" translate=\"no\"\u003eVM_NAME\u003c/var\u003e --all\n\nWhat's next\n\n- [Manage the power state of a VM in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/manage-power-state).\n- [Edit a VM in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/edit-vm).\n- [View VM console logs in Google Distributed Cloud](/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/view-console-logs)."]]