Skip to content

Helm command failure: Kubernetes cluster unreachable: context does not exist #2820

@satishweb

Description

@satishweb

What happened?

devspace dev command failed with below error:

$ devspace dev
info Using namespace 'devspace-myname'
info Using kube context 'my-aws-k8s-context-name'
deploy:dev Deploying chart  (devspace-myname) with helm...
create_deployments: error deploying dev: unable to deploy helm chart:  error executing 'helm upgrade devspace-myname --values /tmp/38929297 --install --namespace devspace-myname /path/to/my/chart/ --kube-context my-aws-k8s-context-name': Error: Kubernetes cluster unreachable: context "my-aws-k8s-context-name" does not exist
fatal exit status 1

What did you expect to happen instead?
devspace dev successfully executing helm command to install the helm chart

How can we reproduce the bug? (as minimally and precisely as possible)

  1. Copy this devspace.yaml into your project
  2. Run command devspace dev

My devspace.yaml:

version: v2beta1
name: test
vars:
  IMAGE: "satishweb/devops-tools"
  TAG: "latest"
  OWNER:
    source: "command"
    command: "/bin/bash"
    args:
      - "-c"
      - "git config user.name | awk '{print tolower($0)}'|tr -d ' '"
  WORK_DIR: "/work/source"
  NAMESPACE:
    source: "command"
    command: "/bin/bash"
    args:
      - "-c"
      - "git config user.name | awk '{print tolower($0)}'|tr -d ' '|sed 's/^/devspace-/'"
  FIXUID: "1000"
  FIXGID: "1000"
  HOME: "/work"

deployments:
  dev:
    helm:
      chart:
        name: "devspace"
        repo: "oci://ghcr.io/luminartech/helm-charts-public"
        version: "6.3.12-0"
      releaseName: "devspace-${OWNER}"
      displayOutput: true
      values:
        global:
          IAMRole: arn:aws:iam::123456789012:role/iam-role
          persistentDataDiskSize: 10Gi
          storageClassName: gp3-persistent-125
          images:
            devcontainer: "${IMAGE}:${TAG}"
          env:
            FIXUID: "${FIXUID}"
            FIXGID: "${FIXGID}"
            HOME: "${HOME}"
        service:
          ports:
            - port: 8080
    namespace: ${NAMESPACE}

dev:
  dev:
    command: ["sleep","infinity"] # 8 hours
    devImage: "${IMAGE}:${TAG}"
    labelSelector:
      app.kubernetes.io/part-of: devspace-${OWNER}
      app.kubernetes.io/instance: devspace-${OWNER}
    namespace: "${NAMESPACE}"
    workingDir: ${WORK_DIR}
    logs:
      enabled: true

    attach:
      enabled: false

    ssh:
      enabled: false

    proxyCommands:
      - gitCredentials: true
      - command: "git"
      - command: "gh"
    ports:
      - port: "8080:8080"

    env:
      - name: "OWNER"
        value: "${OWNER}"
      - name : "FIXUID"
        value: "${FIXUID}"
      - name : "FIXGID"
        value: "${FIXGID}"
      - name: "WORK_DIR"
        value: "${WORK_DIR}"
      - name: "NAMESPACE"
        value: "${NAMESPACE}"
      - name: "HOME"
        value: "${HOME}"

    sync:
      - path: "~/.kube/config:${HOME}/.kube/config"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.saml2aws:${HOME}/.saml2aws"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.aws:${HOME}/.aws"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
      - path: "~/.gitconfig:${HOME}/.gitconfig"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.git-credentials:${HOME}/.git-credentials"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.vim:${HOME}/.vim"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
      - path: "~/.tmux.conf:${HOME}/.tmux.conf"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.zsh_history:${HOME}/.zsh_history"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.docker/config.json:${HOME}/.docker/config.json"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
        file: true
      - path: "~/.ssh:${HOME}/.ssh"
        onUpload:
          restartContainer: false
        initialSyncCompareBy: "mtime" # mtime or size
      - path: "${WORK_DIR}:${HOME}/source"
        printLogs: true
        excludePaths:
          - ".git/"
        downloadExcludePaths:
          - ".cache"
        uploadExcludePaths:
          - ".cache"
        startContainer: true
        onUpload:
          restartContainer: false
          exec:
            - name: "Echo Updated Action"
              command: "echo"
              args: ["Files synced from developer's system"]
              onChange:
                - "**/*"
        initialSync: "preferLocal"
        waitInitialSync: true
        initialSyncCompareBy: "mtime" # mtime or size

    terminal:
      command: "./devspace_start.sh"
      workDir: "${WORK_DIR}"
      enabled: true
      disableReplace: true

    resources:
      requests:
        cpu: "4"
        memory: "8Gi"
      limits:
        cpu: "4"
        memory: "8Gi"

Local Environment:

  • DevSpace Version: 6.3.12
  • Operating System: linux
  • ARCH of the OS: ARM64
    Kubernetes Cluster:
  • Cloud Provider: aws
  • Kubernetes Version: Client Version: v1.29.3 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.25.16-eks-508b6b3

Anything else we need to know?
Apparently, failure was caused by use of HOME var declaration. Renaming HOME to CONTAINER_HOME solved the problem.

It took a while to figure out the root cause. If --debug flag was passed to the helm command, it would have been more easier to find the root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions