简体   繁体   中英

Pod redeploy trigger in golang k8s client

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

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM