1

How can I trigger the update (redeploy) of the hearth through the k8s golang client.

At the moment, I use these libraries to get information about pods and namespaces:

v1 "k8s.io/api/core/v1
k8s.io/apimachinery/pkg/apis/meta/v1
k8s.io/client-go/kubernetes
k8s.io/client-go/rest

Maybe there is another library or it can be done through linux signals

mide
  • 23
  • 3
  • Question is *why* you want to trigger a redeploy. Normally a redeploy happens automatically when a deployment spec changes, e.g. when the pod image gets a new release tag. – rustyx Jul 14 '21 at 23:10
  • Can you describe what you're trying to accomplish? Do you have a deployment? A standalone pod? Are you trying to upgrade the pod, or just restart it in place? – Clark McCauley Jul 14 '21 at 23:30

2 Answers2

2

The standard way to trigger a rolling restart is set/update an annotation in the pod spec with the current timestamp. The change itself does nothing but that changes the pod template hash which triggers the Deployment controller to do its thang. You can use client-go to do this, though maybe work in a language you're more comfortable with if that's not Go.

coderanger
  • 52,400
  • 4
  • 52
  • 75
1

The go client and similar libraries would be following the REST API structure. I believe the kubectl client also uses the API, so it should be possible.

Checkout the code for pod functions in the go library (possibly "Apply" is what you're looking for): https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/core/v1/pod.go and the API reference: https://kubernetes.io/docs/reference/kubernetes-api/

Dan Harper
  • 1,130
  • 10
  • 22