Hello.
I'm running couple of GVMs in Anthos cluster using VM runtime. For one of these GVMs I need to set hostname that is different from GVM name.
I tried to set it internally using hostnamectl, but every time I reboot the VM, hostname changes to GVM name
test-vm:~ # hostnamectl
Static hostname: static-vm
Transient hostname: test-vm
I can see that kubevirt.io/VirtualMachineInstance spec supports hostname
hostname <string>
Specifies the hostname of the vmi If not specified, the hostname will be set
to the name of the vmi, if dhcp or cloud-init is configured properly.
but vm.cluster.gke.io/VirtualMachine spec doesn't.
Since gvm is kind of a wrapper on kubevirt vm, is it possible to pass the hostname somehow?
Hi @AndrewR,
Welcome to Google Cloud Community!
If you're wondering if you can pass a custom hostname to a VM runtime in Anthos, there are ways to manage VM networking and hostname configuration. However, this depends on the VM runtime you're using and how the VM is connected to the Anthos cluster.
You may refer to the following instructions below, a sample on how to create a VM by directly applying a VirtualMachine YAML manifest file with the kubectl CLI.
nano my-vm.yaml
apiVersion: vm.cluster.gke.io/v1
kind: VirtualMachine
metadata:
name: VM_NAME
spec:
osType: linux
compute:
cpu:
vcpus: VCPU_NUMBER
memory:
capacity: MEMORY_SIZE
interfaces:
- name: eth0
networkName: NETWORK_NAME
default: true
disks:
- boot: true
virtualMachineDiskName: DISK_NAME
kubectl apply -f my-vm.yaml
kubectl get gvm VM_NAME
The following example output shows the VM in a Running state:
NAME STATUS AGE IP
MY_VM Running 64s 192.168.2.124
You can also refer to these documentations, which might help for future reference.
I hope the above information is helpful.
> this depends on the VM runtime you're using
Are there different VM runtimes? I am using the one provided by Google.
> how the VM is connected to the Anthos cluster
again, is it possible to connect it multiple ways?
In your example of simple VM, if you create it like this
```name: VM_NAME```
The VM name and the VM hostname will be same VM_NAME. I need them to be different. Kubevirt allows it, but VM Runtime doesn't.