How to fetch the Helm chart version of an already deployed microservice from Kubernetes Cluster in Python

4/30/2020

I have deployed a microservice in a K8S Cluster. Below are the Helm Chart details -

CHART_NAME=eric-bss-sd-dxp-adaptation-staging, CHART_VERSION=1.0.262, NAMESPACE=anindya-ns

Now I want to write a python script which will fetch this version of the chart (i.e. 1.0.262)

Please help if you have worked on such requirement before or suggest the way forward

-- Anindya Mallick
kubernetes
kubernetes-helm
python

1 Answer

5/13/2020

I can give you some steps, it may helpful.

create a service/pod/deployment..., like below

apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" 

You can use .Chart.Version in any where like name, fullname, lable...,

Use kubectl command to fetch the yaml file ex:- https://github.com/kubernetes/kubernetes/issues/24873

then write your own python code read it, fetch chat version.

Please refer below links https://github.com/kubernetes-client/python https://pypi.org/project/kube/

-- Madhu Potana
Source: StackOverflow