8.15. Control virtual machine states


You can use virtctl to manage virtual machine states and perform other actions from the CLI. For example, you can use virtctl to force stop a VM or expose a port.

You can stop, start, restart, reset, pause, and unpause virtual machines from the web console.

8.15.1. Configure RBAC permissions for managing VM states

You can grant users permission to start and stop virtual machines (VMs) from the OpenShift Container Platform web console. Create a role-based access control (RBAC) cluster role and a cluster role binding to apply the permission.

Prerequisites

  • You have cluster administrator access to an OpenShift Container Platform cluster where OpenShift Virtualization is installed.
  • You have installed the OpenShift CLI (oc).

Procedure

  1. Create a ClusterRole object that allows the target user or group to manage VM states:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: vm-manager-access
    rules:
      - apiGroups:
          - subresources.kubevirt.io
        resources:
          - virtualmachines/start
          - virtualmachines/stop
        verbs:
          - update
    # ...
  2. Run the following command to apply the cluster role:

    $ oc apply -f <filename>.yaml
  3. Confirm that the cluster role was created by running the following command and observing the output:

    $ oc get clusterrole <name>

    Example output:

    NAME                AGE
    vm-manager-access   15s
  4. Inspect the details of the cluster role, and ensure the intended rules for subresources.kubevirt.io are present, specifically the virtualmachines/start and virtualmachines/stop subresources.

    Run the following command and observe the output:

    $ oc describe clusterrole <name>

    Example output:

    Name:         vm-manager-access
    Labels:       <none>
    Annotations:  <none>
    PolicyRule:
      Resources  Non-Resource URLs  Resource Names  Verbs
      ---------  -----------------  --------------  -----
      virtualmachines/start, virtualmachines/stop with subresources.kubevirt.io group  []  []  [update]
  5. Create a ClusterRoleBinding object to bind the cluster role you have created to the target user or group:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: vm-manager-access-binding
    subjects:
      - kind: User
        name: test-user
        apiGroup: rbac.authorization.k8s.io
    roleRef:
      kind: ClusterRole
      name: vm-manager-access
      apiGroup: rbac.authorization.k8s.io
  6. Run the following command to apply the cluster role binding:

    $ oc apply -f <filename>.yaml
  7. Confirm that the cluster role binding was created by running the following command and observing the output:

    $ oc get clusterrolebinding <name>

    Example output:

    NAME                        AGE
    vm-manager-access-binding   15s

Verification

  1. Check if the user can start a VM by running the following command:

    $ oc auth can-i update virtualmachines/start --namespace=<namespace> --as=<user_name> --subresource=subresources.kubevirt.io

    Example output:

    yes
  2. Check if the user can stop a VM by running the following command:

    $ oc auth can-i update virtualmachines/stop --namespace=<namespace> --as=<user_name> --group=subresources.kubevirt.io

    Example output:

    yes
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동