kcp-dev / contrib-tmc

An experimental add-on readding some Kubernetes compute APIs and impement transparent multi-cluster scheduling
Apache License 2.0
5 stars 3 forks source link

Kubernetes port environment variables on synced deployments are blank #122

Open mikenairn opened 2 years ago

mikenairn commented 2 years ago

Describe the bug Kubernetes port environment variables (KUBERNETES_SERVICE_PORT and KUBERNETES_SERVICE_PORT_HTTPS) are blank if you are using a kcp exposed via the default port (443) and don't explicitly add it to the server url.

Environment that is added by kcp:

$ kubectl get deployment my-deployment -n kcp1c7217931cde6b107ec3fe3e66465be96f6e11dcdb483d6325515f18 -o json | jq .spec.template.spec.containers[0].env
[
  {
    "name": "KUBERNETES_SERVICE_PORT"
  },
  {
    "name": "KUBERNETES_SERVICE_PORT_HTTPS"
  },
  {
    "name": "KUBERNETES_SERVICE_HOST",
    "value": "kcp.mykcp.com"
  }
]

To Reproduce Steps to reproduce the behavior:

  1. Start KCP and expose it on the default port (443)
  2. Use a kubeconfig that does not specify the port of the server url e.g. server: kcp.mykcp.com
  3. Add a workload cluster and sync it
  4. Deploy an application
  5. Pod will complain if it is trying to do anything with the default kube client, something like:
    W0613 16:55:57.404049 1 client_config.go:622] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined

Note: Adding port 443 to the server URL (kcp.mykcp.com:443) in the kubeconfig gets round the issue. Code here must be returning nothing https://github.com/kcp-dev/kcp/blob/af114bdd7c0a3105e79485fd4176de1693e465ea/pkg/syncer/spec/mutators/deployment.go#L112

Expected behavior Environment variable should be set

Additional context Only tested with 0.5.0

sttts commented 2 years ago

naive question: why doesn't kube add them?

cc @jmprusi

mjudeikis commented 11 months ago

/transfer-issue contrib-tmc