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
Create a
ClusterRoleobject 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 # ...Run the following command to apply the cluster role:
$ oc apply -f <filename>.yamlConfirm 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 15sInspect the details of the cluster role, and ensure the intended rules for
subresources.kubevirt.ioare present, specifically thevirtualmachines/startandvirtualmachines/stopsubresources.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]Create a
ClusterRoleBindingobject 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.ioRun the following command to apply the cluster role binding:
$ oc apply -f <filename>.yamlConfirm 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
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.ioExample output:
yesCheck 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.ioExample output:
yes