title: How to identify kubernetes cluster provider using kubectl
body: <p>I work on a k8s daemonset whose deployment requires that certain values are changed depending on the k8s cluster provider type (gke, eks, aks, minikube, k3s, kind, self-managed k8s installed using kubeadm on a vm, ... etc).</p>
  <p>What is the right way to identify what is the k8s cluster provider type given that <code>kubectl/kubeconfig</code> is already configured?</p>
  <p>One option is to use <code>kubectl config current-context view</code>:</p>
  <pre class="lang-sh prettyprint-override"><code>CURRENT_CONTEXT_NAME=&quot;$(kubectl config current-context view)&quot;
  PLATFORM=&quot;self-managed&quot;
  
  autoDetectEnvironment(){
      if [[ -z &quot;$CURRENT_CONTEXT_NAME&quot; ]]; then
          echo &quot;no configuration has been provided&quot;
          return
      fi  
  
      echo &quot;Autodetecting environment&quot;
      if [[ $CURRENT_CONTEXT_NAME =~ ^minikube.* ]]; then
          PLATFORM=&quot;minikube&quot;
      elif [[ $CURRENT_CONTEXT_NAME =~ ^gke_.* ]]; then
          PLATFORM=&quot;gke&quot;
      elif [[ $CURRENT_CONTEXT_NAME =~ ^kind-.* ]]; then
          PLATFORM=&quot;kind&quot;
      elif [[ $CURRENT_CONTEXT_NAME =~ ^k3d-.* ]]; then
          PLATFORM=&quot;k3d&quot;
          elif [[ $CURRENT_CONTEXT_NAME =~ ^kubernetes-.* ]]; then
                  PLATFORM=&quot;self-managed&quot;
          else
                  echo &quot;No k8s cluster configured or unknown env!&quot;
                  exit 2
          fi  
  }
  </code></pre>
  <p>However, this seems hacky and am sure it will not work under all cases. For e.g., for EKS I could not figure out what regex to use.</p>