Traefik pod not found when using "kubectl port-forward" for dashboard access

:thinking: Issue description

  • I am attempting to use kubectl port-forward to access the Traefik dashboard
  • It says the pod doesnt exist, even though that name does

Command I am using

kubectl port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name -n traefik) 9000:9000

Error I am getting

Error from server (NotFound): pods "traefik-796d5fd8b9-rwxcd" not found

Screenshot showing the pod exists in the first command, but still getting an error

:earth_americas: Environment

Software versions

  • K3s Version: v1.20.4+k3s1
  • Traefik: v2 (installed via Helm)

Configurations

dashboard.yml (taken from Github)
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: dashboard
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`traefik.localhost`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))
      kind: Rule
      services:
        - name: api@internal
          kind: TraefikService
helm-values.yml
#
# Advanced K8s settings
#
rbac:
  enabled: true
tolerations:
  - key: "CriticalAddonsOnly"
    operator: "Exists"
  - key: "node-role.kubernetes.io/master"
    operator: "Exists"
    effect: "NoSchedule"

#
# Configure providers
#
providers:
  kubernetesIngress:
    publishedService:
      enabled: true
#
# Create an IngressRoute for the dashboard
#
ingressRoute:
  dashboard:
    enabled: true
# #
# # Redirect to HTTPs
# #
# ports:
#   web:
#     redirectTo: websecure

# #
# # Options for the main traefik service, where the entrypoints traffic comes
# # from.
# service:
#   type: NodePort

# Configure ports
ports:
  # The name of this one can't be changed as it is used for the readiness and
  # liveness probes, but you can adjust its config to your liking
  traefik:
    port: 9000
    # Use hostPort if set.
    # hostPort: 9000
    #
    # Use hostIP if set. If not set, Kubernetes will default to 0.0.0.0, which
    # means it's listening on all your interfaces and all your IPs. You may want
    # to set this value if you need traefik to listen on specific interface
    # only.
    # hostIP: 192.168.100.10

    # Defines whether the port is exposed if service.type is LoadBalancer or
    # NodePort.
    #
    # You SHOULD NOT expose the traefik port on production deployments.
    # If you want to access it from outside of your cluster,
    # use `kubectl port-forward` or create a secure ingress
    expose: false
    # The exposed port for this service
    exposedPort: 9000
    # The port protocol (TCP/UDP)
    protocol: TCP
  web:
    port: 8000
    # hostPort: 8000
    expose: true
    exposedPort: 80
    # The port protocol (TCP/UDP)
    protocol: TCP
    # Use nodeport if set. This is useful if you have configured Traefik in a
    # LoadBalancer
    # nodePort: 32080
    # Port Redirections
    # Added in 2.2, you can make permanent redirects via entrypoints.
    # https://docs.traefik.io/routing/entrypoints/#redirection
    # redirectTo: websecure
  websecure:
    port: 8443
    # hostPort: 8443
    expose: true
    exposedPort: 443
    # The port protocol (TCP/UDP)
    protocol: TCP
    # nodePort: 32443
    # Set TLS at the entrypoint
    # https://doc.traefik.io/traefik/routing/entrypoints/#tls
    tls:
      enabled: true
      # this is the name of a TLSOption definition
      options: ""
      certResolver: ""
      domains: []
      # - main: example.com
      #   sans:
      #     - foo.example.com
      #     - bar.example.com

#
# Things that I felt more comfortable setting via the CLI
#
additionalArguments:
  - "--certificatesresolvers.letsencrypt.acme.email=myemail@me.test"
  - "--certificatesresolvers.letsencrypt.acme.storage=/data/acme.json"
  - "--certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
  - "--api.insecure=true"
  - "--accesslog=true"
  - "--log.level=ERROR"

:sparkles: Additional details

Here is the output of kubectl get all --all-namespaces:

:raised_hands: Thank you for your help!

If there is anything else that you would like to see, just let me know! Thanks!!!

1 Like

Special thanks to Daniel Tomcej (dtomcej on Github), the solution is adding a namespace to the kubectl port-forward command.

For example, the command that works for me is:

kubectl port-forward -n traefik $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name -n traefik) 9000:9000

Notice I had to add -n traefik in each command above.

Thanks Traefik Community! You're so helpful :raised_hands:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.