Kubectl: Named container port gets different name than in manifest

Created on 7 Aug 2020  Â·  9Comments  Â·  Source: kubernetes/kubectl

What happened:

I have a deployment with a single container and ports:

[I] ➜ kubectl -n kube-system get deployment coredns -o yaml | grep ' ports' -A6
        ports:
        - containerPort: 53
          name: tcp
          protocol: TCP
        - containerPort: 53
          protocol: UDP
        - containerPort: 9153

I have a manifest that is the same:

[I] ➜ grep ' ports' -A6 a/apps-v1.Deployment-coredns.yaml
        ports:
        - containerPort: 53
          name: tcp
          protocol: TCP
        - containerPort: 53
          name: udp
          protocol: UDP

I compare both with kubectl diff:

[I] ➜ kubectl diff -f a/apps-v1.Deployment-coredns.yaml
diff -u -N /tmp/LIVE-920116509/apps.v1.Deployment.kube-system.coredns /tmp/MERGED-881599448/apps.v1.Deployment.kube-system.coredns
--- /tmp/LIVE-920116509/apps.v1.Deployment.kube-system.coredns  2020-08-07 13:43:55.134872796 +0200
+++ /tmp/MERGED-881599448/apps.v1.Deployment.kube-system.coredns        2020-08-07 13:43:55.288206694 +0200
@@ -6,7 +6,7 @@
     kubectl.kubernetes.io/last-applied-configuration: | <redacted>
   creationTimestamp: "2020-04-21T16:33:15Z"
-  generation: 6
+  generation: 7
   labels:
     name: coredns
     tanka.dev/environment: environments.dns.dev-us-central1.kube-system
@@ -53,7 +53,7 @@
         name: coredns
         ports:
         - containerPort: 53
-          name: tcp
+          name: udp
           protocol: TCP
         - containerPort: 53
           protocol: UDP

This is not what should happen, no difference is expected but considering comments #735, kubernetes or kubectl might consolidate the ports, so I apply:

[I] ✘1 ➜ kubectl apply -f a/apps-v1.Deployment-coredns.yaml
deployment.apps/coredns configured

Again, I check the diff, expecting idempotency:

[I] ➜ kubectl diff -f a/apps-v1.Deployment-coredns.yaml
diff -u -N /tmp/LIVE-700948331/apps.v1.Deployment.kube-system.coredns /tmp/MERGED-197268942/apps.v1.Deployment.kube-system.coredns
--- /tmp/LIVE-700948331/apps.v1.Deployment.kube-system.coredns  2020-08-07 13:51:17.023080611 +0200
+++ /tmp/MERGED-197268942/apps.v1.Deployment.kube-system.coredns        2020-08-07 13:51:17.149747700 +0200
@@ -6,7 +6,7 @@
     kubectl.kubernetes.io/last-applied-configuration: | <redacted>
   creationTimestamp: "2020-04-21T16:33:15Z"
-  generation: 7
+  generation: 8
   labels:
     name: coredns
     tanka.dev/environment: environments.dns.dev-us-central1.kube-system
@@ -53,7 +53,7 @@
         name: coredns
         ports:
         - containerPort: 53
-          name: udp
+          name: tcp
           protocol: TCP
         - containerPort: 53
           protocol: UDP

I get another diff, toggling the port name again.

What you expected to happen:
In the first case, I would expect that the Port/Protocol pair could be named differently.
If for some reason there is consolidation happening on solely the Port, then I expect idempotency.

How to reproduce it (as minimally and precisely as possible): see above

Anything else we need to know?:

Environment:

  • Kubernetes client and server versions (use kubectl version):

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"archive", BuildDate:"2020-05-22T20:04:08Z", GoVersion:"go1.14.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.10-gke.42", GitCommit:"42bef28c2031a74fc68840fce56834ff7ea08518", GitTreeState:"clean", BuildDate:"2020-06-02T16:07:00Z", GoVersion:"go1.12.12b4", Compiler:"gc", Platform:"linux/amd64"}

  • Cloud provider or hardware configuration: Google/GKE

  • OS (e.g: cat /etc/os-release): server: Google's COS, client: Arch Linux

kinbug triagnot-reproducible

All 9 comments

@Duologic I'm not able to reproduce this. Here's the deployment I'm using.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    test: test
spec:
  replicas: 1
  selector:
    matchLabels:
      test: test
  template:
    metadata:
      labels:
        test: test
    spec:
      containers:
        - name: test
          image: busybox
          command:
            - sleep
            - "10000000000000"
          ports:
            - name: tcp
              protocol: TCP
              containerPort: 53
            - name: udp
              protocol: UDP
              containerPort: 53

Can you test with this or provide a fully reproducible manifest?

Are you able to reproduce on a supported version of Kubernetes (1.16, 1.17, 1.18)?

Also I noticed you have metadata.generation showing up in your diff which seems strange to me.

/triage not-reproducible

A newer Kubernetes version might resolve it, we're a in the process of upgrading our clusters, will reopen if this is still an issue after upgrade to 1.16.

I can report the same issue on

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"archive", BuildDate:"2020-05-22T20:04:08Z", GoVersion:"go1.14.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.13-gke.401", GitCommit:"eb94c181eea5290e9da1238db02cfef263542f5f", GitTreeState:"clean", BuildDate:"2020-09-09T00:57:35Z", GoVersion:"go1.13.9b4", Compiler:"gc", Platform:"linux/amd64"}

/assign @dougsland

@eddiezane: GitHub didn't allow me to assign the following users: dougsland.

Note that only kubernetes members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @dougsland

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

/assign

Unfortunately, I cannot reproduce the issue.

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.5", GitCommit:"e338cf2c6d297aa603b50ad3a301f761b4173aa6", GitTreeState:"clean", BuildDate:"2020-12-09T11:18:51Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:04:18Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}

@Duologic do you mind to share with us a manifest to deploy and a manifest to diff? So would help us to debug and catch this.

Hello, sorry for the delay. I surely have trouble reproducing this in an isolated way too, but I think I might have something.

The original Deployment manifest didn't have the ports 'named', we added that later. By the looks of it, that is what is causing the problem.

Version info:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"archive", BuildDate:"2020-11-25T13:19:56Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.15-gke.4300", GitCommit:"7ed5ddc0e67cb68296994f0b754cec45450d6a64", GitTreeState:"clean", BuildDate:"2020-10-28T09:23:22Z", GoVersion:"go1.13.15b4", Compiler:"gc", Platform:"linux/amd64"}

The used manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dnsutils-named-ports
  namespace: dns-example
spec:
  replicas: 1
  selector:
    matchLabels:
      name: dnsutils-named-ports
  template:
    metadata:
      labels:
        name: dnsutils-named-ports
    spec:
      containers:
      - command:
         - sleep
         - "3600"
        image: gcr.io/kubernetes-e2e-test-images/dnsutils:1.3
        imagePullPolicy: IfNotPresent
        name: dnsutils-named-ports
        ports:
        - containerPort: 53
          name: tcp
          protocol: TCP
        - containerPort: 53
          name: udp
          protocol: UDP

Screencast:
Peek 2021-01-03 20-49

hey,
I think the kubectl apply problem is here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3dbrows picture 3dbrows  Â·  6Comments

willbeason picture willbeason  Â·  4Comments

mnussbaum picture mnussbaum  Â·  6Comments

whs-dot-hk picture whs-dot-hk  Â·  6Comments

cbluth picture cbluth  Â·  6Comments