Welcome to the kubectl (in a container)
Latest Release: Click Here
For Version specific releases
So, I wanted to label a few nodes on my Kubernetes cluster, and rather than doing it by hand wanted to do it as a job. The solutions to run kubectl as job that I found were either not updated to the latest release or had a different container for each release, that just makes the life difficult as if I update my K8's to a latest one, I need to remember to also update the job that is running with this solution.
Here, I can just not pass any variable to control the client version and be rest assured I will always get the latest one.
All the files used for showing are present here These were tested on a minikube cluster, except for the helm chart example that is not yet tested.
$ kubectl apply -f https://raw.githubusercontent.com/tapas-sharma/kubectl-k8s/master/example/job-labelNodes.yaml
kube-system namespace.$ kubectl -n kube-system get jobs
NAME COMPLETIONS DURATION AGE
labelnode 1/1 13s 32m
tapas/sharma=muchWow, you can check that using the following command$ kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
minikube Ready master 52m v1.18.3 ....,tapas/sharma=muchWoW
$ kubectl apply -f https://raw.githubusercontent.com/tapas-sharma/kubectl-k8s/master/example/job-unlabelNodes.yaml
$ kubectl apply -f https://raw.githubusercontent.com/tapas-sharma/kubectl-k8s/master/example/kubectlversion.yaml
$ kubectl logs kubeversion
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.6", GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037", GitTreeState:"clean", BuildDate:"2020-07-15T16:58:53Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
KUBE_VERSION environment variable to the pod, thus forcing it to get the latest kubectl version as of writing this wiki.To integrate with helm, you can refer here This shows, how to read the K8's version from the helm in-built variables and pass it to the container. This is a modification of label nodes example and can be used as pre-install, post-install or any other hooks by making it as a job/pod etc.
Content type
Image
Digest
Size
16 MB
Last updated
about 6 years ago
docker pull tapassharma/kubectl