0

I keep getting the older pods while listing pods (pods in older deployment) for a deployment after recreating the deployment (either by replace or delete and create), using this code:

List<Pod> otelCollectorPods =
  client
    .pods()
    .inNamespace(LOGCOLLECTION_NAMESPACE)
    .withLabels(otelCollectorDeployment.getMetadata().getLabels())
    .list()
    .getItems();

for (Pod pod : otelCollectorPods) {
  String podName = pod.getMetadata().getName();
  
  InputStream outputJsonFileInputStream =
    client
      .pods()
      .inNamespace(LOGCOLLECTION_NAMESPACE)
      .withName(podName)
      .file("/otel-output/json-out.json")
      .read();

  // do something with the inputstream...
}

I have tried creating deployment using createOrReplace as well as delete and the create, nothing worked:

client
  .apps()
  .deployments()
  .inNamespace(LOGCOLLECTION_NAMESPACE)
  .withName(otelCollectorDeployment.getMetadata().getName())
  .createOrReplace(otelCollectorDeployment);

--

client
  .apps()
  .deployments()
  .inNamespace(LOGCOLLECTION_NAMESPACE)
  .withName(otelCollectorDeployment.getMetadata().getName())
  .delete();


client
  .apps()
  .deployments()
  .inNamespace(LOGCOLLECTION_NAMESPACE)
  .withName(otelCollectorDeployment.getMetadata().getName())
  .create(otelCollectorDeployment);
lprakashv
  • 1,121
  • 10
  • 19
  • Are you sure that the pods are no existing (i.e they are not listed in the `kubectl get pods` command)? – Mikolaj S. Nov 26 '21 at 09:44
  • None so far. I think I will have to use the pods list to get the logs for each, I was just wondering if I could use the similar strategy as the command I pasted in the question. – lprakashv Dec 01 '21 at 17:22

0 Answers0