An example implementation in Golang of a kubernetes client to interact with a Virtual Server resource on CoreWeave Cloud.
The provided Golang example illustrates the following:
- 2.Building a Service and PVC to be used as a FloatingIP and Additional Filesystem respectively.
- 3.Removing an existing Virtual Server.
- 4.Creating a new Virtual Server. (The instance is started automatically.)
- 5.Waiting for Virtual Server ready status.
- 6.Stopping the instance, then waiting until it is completely stopped.
- 7.Deleting the Virtual Server once it is completely stopped.
View the example code on GitHub:
Additionally, a Persistent Volume Claim and a Service are created. They are then allocated to the Virtual Server as an additional file system and floating IP respectively. Once prepared, a simple sigs client is used to create, get, and delete the Virtual Server.
A Persistent Volume Claim (PVC) is created and assigned to the Virtual Server as an additional file system. The PVC will then be accessible from within the Virtual Server as a mounted file system. The example function
buildPVCillustrates the creation of a PVC struct. The Kubernetes client is then used to deploy the PVC to the cluster.
A Service is created and assigned to the Virtual Server as a floating IP service. The service must be
type: LoadBalancer, and have been assigned a load balancer IP in order to be used as a floating IP service. If the service is valid, the IP of the service will be assigned to the Virtual Server as a floating IP.
This example also illustrates creating a floating service when the
FLOATING_SERVICE_NAMEenvironment variable is specified. The function
buildFloatingIPServiceillustrates the creation of a Service struct. The Kubernetes client is then used to deploy the Service to the cluster.