Search code examples
kubernetesskaffoldgoogle-cloud-code

Skaffold debug is missing JAVA_TOOL_OPTIONS with Helm deployment


If I understand the documentation here correctly...

Skaffold Debug

If I try to run K8s Project with 'skaffold debug' or with IntelliJ 'Develop on Kubernetes' and Debug, skaffold must insert in my k8s deployment/service files extra port for jdwp and Environment Variable with JAVA_TOOL_OPTIONS. Which is not happening for me.

I am using a Helm Chart to deploy my k8s artifacts and I don't see anywhere that these things are configured (as it also mentioned here GitHub Issue).

If I configure my deployment\service yamls manually, to insert port 5005 for jdwp and environment variable JAVA_TOOL_OPTIONS for jdwp and port forward 5005 then I can remotely attach to process and debug, but skaffold is not able to manage it by itself (It is not even trying, I see no JAVA_TOOL_OPTIONS in my logs).

May be, it does not understand that I am running a JVM project or may be, while I created with my Helm Project with 'helm create' and there are several yaml files (configmap.yaml, deployment.yaml, hpa.yaml, ingress.yaml, service.yaml, serviceaccount.yaml) it is not able to find correct file to manipulate.

If I also understand correctly, the deployment/pod that would be debugged must have following annotations:

Annotations

debug.cloud.google.com/config

which are missing completely, only thing I see on deployment is the following -

ide: idea
ideVersion: 2021.1.1.0.0
ijPluginVersion: unknown
skaffold.dev/run-id: d2420cca-f212-4349-b078-41f36ed51bd5

Any idea what is going wrong here?

Actually, deployment functioning correctly and my Pod reports Ok for Readyness check but no debugging starting from skaffold/intellij.


Solution

  • There were some mismatches between the @posthumecaver's Helm chart and the skaffold.yaml that prevented Skaffold from configuring the image. I'll summarize the findings here for the benefit of those who stumble across this post.

    @posthumecaver is using Skaffold's Helm support. This requires that the skaffold.yaml and the Helm chart use a common key for referencing the image. There are three approaches used in Helm for referencing images:

    Fully-Qualified Name (default)

    Skaffold will configure Helm setting a key to the fully-tagged image reference.

    The skaffold.yaml setup:

    build:
      artifacts:
        - image: gcr.io/my-project/my-image
    deploy:
      helm:
        releases:
          - name: my-chart
            chartPath: helm
            artifactOverrides:
              img: gcr.io/my-project/my-image
    

    The chart template:

    image: "{{.Values.img}}"
    

    The values.yaml (note that Skaffold overrides this value):

    img: gcr.io/other-project/other-image:latest
    

    Skaffold will invoke

    helm install <chart> <chart-path> --set-string img=gcr.io/my-project/my-image:generatedTag@sha256:digest
    

    Split Repository and Tag

    Skaffold can be configured to provide Helm with a separate repository and tag. The key used in the artifactOverrides is used as base portion producing two keys {key}.repository and {key}.tag.

    The skaffold.yaml setup:

    build:
      artifacts:
        - image: gcr.io/my-project/my-image
    deploy:
      helm:
        releases:
          - name: my-chart
            chartPath: helm
            artifactOverrides:
              img: gcr.io/my-project/my-image
            imageStrategy:
              helm: {}
    

    The chart template:

    image: "{{.Values.img.repository}}:{{.Values.img.tag}}"
    

    The values.yaml (note that Skaffold overrides these value):

    img:
      repository: gcr.io/other-project/other-image
      tag: latest
    

    Skaffold will invoke

    helm install <chart> <chart-path> --set-string img.repository=gcr.io/my-project/my-image,img.tag=generatedTag@sha256:digest
    

    Split Registry, Repository, and Tag

    Skaffold can also be configured to provide Helm with a separate repository and tag. The key used in the artifactOverrides is used as base portion producing three keys: {key}.registry, {key}.repository, and {key}.tag.

    The skaffold.yaml setup:

    build:
      artifacts:
        - image: gcr.io/my-project/my-image
    deploy:
      helm:
        releases:
          - name: my-chart
            chartPath: helm
            artifactOverrides:
              img: gcr.io/my-project/my-image
            imageStrategy:
              helm:
                explicitRegistry: true
    

    The chart template:

    image: "{{.Values.img.registry}}/{{.Values.img.repository}}:{{.Values.img.tag}}"
    

    The values.yaml (note that Skaffold overrides these value):

    img:
      registry: gcr.io
      repository: other-project/other-image
      tag: latest
    

    Skaffold will invoke

    helm install <chart> <chart-path> --set-string img.registry=gcr.io,img.repository=my-project/my-image,img.tag=generatedTag@sha256:digest