Skip to content

k8s:debug - kubernetes namespace is ignored #152

@ZoltanMozes

Description

@ZoltanMozes

Operating System
$ uname -a
Linux zoltan-VirtualBox 5.3.0-46-generic #38~18.04.1-Ubuntu SMP Tue Mar 31 04:17:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Eclipse JKube version
org.eclipse.jkube
kubernetes-maven-plugin
1.0.0-alpha-1

Java version
$ java -version
java version "13.0.2" 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)

Maven version
mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/zoltan/.sdkman/candidates/maven/current
Java version: 13.0.2, vendor: Oracle Corporation, runtime: /home/zoltan/dev/java/jdk-13.0.2
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.0-46-generic", arch: "amd64", family: "unix"

Target cluster version (Kubernetes, OpenShift, Minikube, CRC, etc.)
$ minikube version
minikube version: v1.9.1
commit: d8747aec7ebf8332ddae276d5f8fb42d3152b5a1

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T20:08:47Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:50:46Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}

Symptom:

k8s:debug

fails to establish port-forwarding via kubectl, because the namespace (pom.xml) is ignored when calling kubectl.

pom.xml

	<properties>
		...
		<jkube.namespace>customnamespace</jkube.namespace>
[INFO] --- kubernetes-maven-plugin:1.0.0-alpha-1:debug (default-cli) @ shopping-cart ---
[INFO] k8s: Using Kubernetes at https://172.17.0.2:8443/ in namespace customnamespace with manifest /home/zoltan/dev/workspaces/eLearning/services/shopping-cart/target/classes/META-INF/jkube/kubernetes.yml 
[INFO] k8s: Using namespace: customnamespace
[INFO] k8s: Updating a Service from kubernetes.yml
[INFO] k8s: Updated Service: target/jkube/applyJson/customnamespace/service-shopping-cart-9.json
[INFO] k8s: Enabling debug on Deployment shopping-cart
[INFO] k8s: Waiting for debug pod with selector LabelSelector(matchExpressions=[], matchLabels={app=shopping-cart, provider=jkube, group=hu.customnamespace}, additionalProperties={}) and environment variables {JAVA_DEBUG_SUSPEND=false, JAVA_ENABLE_DEBUG=true}
[INFO] k8s: Port forwarding to port 5005 on pod shopping-cart-5cfc69469b-9sl86 using command /snap/bin/kubectl
[WARNING] k8s:port-forward Error from server (NotFound): pods "shopping-cart-5cfc69469b-9sl86" not found
[INFO] k8s: 
[INFO] k8s: Now you can start a Remote debug execution in your IDE by using localhost and the debug port 5005
[INFO] k8s: 

The problem is indicated as a warning (still it should be an ERROR):

[WARNING] k8s:port-forward Error from server (NotFound): pods "shopping-cart-5cfc69469b-9sl86" not found

Root cause:
kubernetes namespace is silently ignored by the

k8s:debug

Maven goal.

Ducktaping workaround: configuring the context (for subsequent kubectl commands) manually solves the problem:
kubectl config set-context --current --namespace=customnamespace

Once the context is explicitely set as per above, port forwarding works well when typing:

k8s:debug

The above command is now able to find the pod (since namespace is explicitly set) and port-forwarding can be established -> remote JVM debugger can now be attached from Spring Tool Suit 4 without issues (breakpoints hit etc)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions