I am using the Minikube environment and I have defined the max memory using
$] minikube config set memory 2048
Now I want to get this memory value using the Kubernetes API call in GO. I have tried the following,
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
availableMem := kubernetes.Interface.StorageV1beta1().RESTClient().Get().Name("config")
But the output is not in readable manner.
This code will fetch the available memory of the first cluster
nodeList, err := f.KubeClient.CoreV1().Nodes().List(metav1.ListOptions{})
if err == nil {
if len(nodeList.Items) > 0 {
node := &nodeList.Items[0]
memQuantity := node.Status.Allocatable[v1.ResourceMemory]
totalMemAvail = int(memQuantity.Value() >> 20)
} else {
t.Fatal("Unable to read node list")
return
}
} else {
t.Fatalf("Error while reading node list data: %v", err)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With