Control Virtual Machine Network Requests Through Network Policy
The platform's virtual machine solution is implemented based on the open-source component KubeVirt, which actually runs within Pods. By utilizing the functionality of Network Policies, it is possible to control the incoming and outgoing requests of virtual machines.
TOC
ProcedureResult VerificationStep One: Create a Virtual Machine and Network Policy Allowing All Traffic ThroughStep Two: Update Network Policy to Remove www.example.com from WhitelistProcedure
-
Enter Container Platform.
-
In the left navigation bar, click Network > Network Policies.
-
Click Create Network Policy.
-
Configure the following parameters as needed.
-
Click Create.
Result Verification
This document verifies the setup using a virtual machine to access www.example.com.
Step One: Create a Virtual Machine and Network Policy Allowing All Traffic Through
-
Create the virtual machine, please refer to Create Virtual Machine for detailed steps.
-
Configure the network policy in the command namespace of the virtual machine, adding whitelist rules for both TCP and UDP protocols, with the following parameters:
-
Whitelist for TCP Protocol:
-
Whitelist Rules for UDP Protocol:
-
-
After the network policy is created, log in to the virtual machine and execute the following command to request www.example.com.
-
The request is successful.
Step Two: Update Network Policy to Remove www.example.com from Whitelist
-
Execute the following command to obtain the IP address for www.example.com, resulting in the IP address 93.184.215.14.
-
Update the network policy created in Step One, with the following updated parameters:
-
After updating the network policy, log in to the virtual machine and execute the following command to request www.example.com.
-
The request times out, indicating that the exclude remote functionality is effective.