Golang
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:
- 1.
- 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:
Directive | Description |
---|---|
install | Download the module dependencies. |
run | Build and run the example executable. |
clean | Remove the executable. |
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.
The example application (
main.go
) builds a Kubernetes client using the credentials from either a Kubernetes config file or from a service account mount.Additional Resources
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
buildPVC
illustrates 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.Note
This example also illustrates creating a floating service when the
FLOATING_SERVICE_NAME
environment variable is specified. The function buildFloatingIPService
illustrates the creation of a Service struct. The Kubernetes client is then used to deploy the Service to the cluster.Using utility functions provided by v1alpha1, the application creates a VirtualServer struct, and then deploys the Virtual Server to the cluster using the Kubernetes client.
Note
For long-running, fine-grained and event-driven control of Virtual Servers, a sigs controller can be implemented for Virtual Servers.
Last modified 1yr ago