<p>Looking for some ideas on how to expose an http endpoint from kubernetes cluster that shows the docker images tag for each service that is live and up-to-date as services are updated with newer tags.</p>
<p>Example something like this: <code>GET endpoint.com/api/metadata</code></p>
<pre><code>{
   &quot;foo-service&quot;: &quot;registry.com/foo-service:1.0.1&quot;,
   &quot;bar-service&quot;: &quot;registry.com/bar-service:2.0.1&quot;
}

</code></pre>
<p>when <code>foo-service</code> is deployed with a new tag <code>registry.com/foo-service:1.0.2</code>, I want the endpoint to reflect that change.</p>
<p>I can't just store the values as environment variables as it is not guaranteed the service that exposes that endpoint will be updated on each deploy.</p>
<p>Some previous I had but does not seem clean:</p>
<ul>
<li><p>Update an external file in s3 to keep track of image tags on each deployment, and cache/load data on each request to endpoint.</p>
</li>
<li><p>Update a key in Redis within the cluster and read from that.</p>
</li>
</ul>

Mo Xue
<p>Folowing on @DavidMaze's suggestion. I ended up using the Kubernetes API to display a formatted version of the deployed services via an rest api endpoint.</p>
<p>Steps:</p>
<ul>
<li>Attach a role with relevant permissions to a service account.</li>
</ul>
<pre><code># This creates a service role that can be attached to
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: service-role
  namespace: dev
rules:
  - verbs:
      - list
    apiGroups:
      - apps
    resources:
      - deployments
</code></pre>
<ul>
<li>Use one of the available kubernetes api libraries to connect to the kubernetes api from within the cluster, Java in my case. And retrieve the deployment list.</li>
</ul>
<pre><code>implementation io.kubernetes:client-java:15.0.1
</code></pre>
<ul>
<li>Output the result of the kubernetes api call and expose a cached version of it through an endpoint (Java snippet)</li>
</ul>
<pre><code>public Map&lt;String, String&gt; getDeployedServiceVersions() { 
            ApiClient client = Config.defaultClient();
            Configuration.setDefaultApiClient(client);

            AppsV1Api api = new AppsV1Api();
            V1DeploymentList v1DeploymentList = api.listNamespacedDeployment(releaseNamespace, null, false, null, null, null, null, null, null, 10, false);
            # Helper method to map deployments to result
            return getServiceVersions(v1DeploymentList);
}
</code></pre>
