Manage Public IPs
This guide shows you how to create Public IPs, attach them to virtual machines, and manage them using the evroc CLI or Kubernetes API.
For information about Public IPs and how they work, see Public IPs.
Prerequisites
- Access to an evroc organization and resource group
- evroc CLI installed and configured, or kubectl configured to access the evroc Kubernetes API
Create a Public IP
Create a Public IP resource that you can attach to a virtual machine.
Using the CLI
Create a Public IP with the evroc networking publicip create command:
evroc networking publicip create mypublicip
Using the API
Create a Public IP by applying a YAML configuration:
apiVersion: networking.evroclabs.net/v1alpha1
kind: PublicIP
metadata:
name: mypublicip
Apply the configuration:
kubectl apply -f publicip.yaml
Attach a Public IP to a VM
Attach a Public IP when creating a new VM, or update an existing VM to attach a Public IP.
Using the CLI
Attach a Public IP when creating a VM:
evroc compute vm create myvm \
--running=true \
--vm-virtual-resources-ref=general.s \
--disk=mybootdisk \
--boot-from=true \
--public-ip=mypublicip
Attach a Public IP to an existing VM:
evroc compute vm update myvm --public-ip=mypublicip
Using the API
Add the Public IP reference to the VM specification:
apiVersion: compute.evroclabs.net/v1alpha1
kind: VirtualMachine
metadata:
name: myvm
spec:
networking:
publicIPv4Address:
static:
publicIPRef: mypublicip
# ... other fields
Apply the configuration:
kubectl apply -f vm.yaml
Change the Public IP on a VM
To replace a VM's Public IP with a different one, the VM must be stopped. You must first stop the VM, detach the current Public IP, attach the new one, and then start the VM again. You cannot directly update from one Public IP to another.
Using the CLI
-
Stop the VM:
evroc compute vm update myvm --running=false -
Detach the current Public IP:
evroc compute vm update myvm --public-ip="" -
Attach the new Public IP:
evroc compute vm update myvm --public-ip=mynewpublicip -
Start the VM:
evroc compute vm update myvm --running=true
Using the API
-
Stop the VM:
kubectl patch virtualmachine myvm --type=merge -p '{"spec":{"running":false}}' -
Remove the
publicIPv4Addressfield from the VM specification:apiVersion: compute.evroclabs.net/v1alpha1 kind: VirtualMachine metadata: name: myvm spec: networking: {} # ... other fieldsApply the configuration:
kubectl apply -f vm.yaml -
Update the specification with the new Public IP:
apiVersion: compute.evroclabs.net/v1alpha1 kind: VirtualMachine metadata: name: myvm spec: networking: publicIPv4Address: static: publicIPRef: mynewpublicip # ... other fieldsApply the updated configuration:
kubectl apply -f vm.yaml -
Start the VM:
kubectl patch virtualmachine myvm --type=merge -p '{"spec":{"running":true}}'
Detach a Public IP from a VM
Remove a Public IP from a VM to disable inbound internet connectivity.
Using the CLI
Detach a Public IP by updating the VM with an empty string:
evroc compute vm update myvm --public-ip=""
Using the API
Remove the publicIPv4Address field from the VM specification:
apiVersion: compute.evroclabs.net/v1alpha1
kind: VirtualMachine
metadata:
name: myvm
spec:
networking: {}
# ... other fields
Apply the updated configuration:
kubectl apply -f vm.yaml
List Public IPs
Using the CLI
List all Public IPs in your resource group:
evroc networking publicip list
Sample output:
Name Ready Reason IP User
------------ ------- -------- ---------------- ------
mypublicip True Ready 185.222.1.1 myvm
Using the API
List Public IPs using kubectl:
kubectl get publicips
Sample output:
NAME READY REASON IP USER
mypublicip True Ready 185.222.1.1 myvm
Delete a Public IP
Delete Public IPs you no longer need. A Public IP must not be attached to any virtual machine before you can delete it.
Using the CLI
Delete a Public IP:
evroc networking publicip delete mypublicip
Using the API
Delete a Public IP using kubectl:
kubectl delete publicip mypublicip
Next steps
- Learn how to configure security groups to control traffic to VMs with Public IPs
- See how to create a virtual machine with a Public IP
- See the Public IP API reference for complete field descriptions