kubectl config merge redirect not as expected

12/1/2018

I want to merge the kubectl config and redirect it to a file, the code:

#!/usr/bin/env bash

HOST_KUBECONFIG="$KUBECONFIG"
MY_KUBECONFIG=kube_config
export KUBECONFIG="$HOST_KUBECONFIG"
echo "$(kubectl config view --flatten)" > .kube_config_tmp
if [ -f "$MY_KUBECONFIG" ] ; then
  export KUBECONFIG="$MY_KUBECONFIG":.kube_config_tmp
else
  export KUBECONFIG=.kube_config_tmp
fi
kubectl config view --flatten  >file1

kubectl config view --flatten  > $MY_KUBECONFIG

It is strange that the result in file1 and MY_KUBECONFIG(kube_config) is different. In file1 can get the correct result ,but in MY_KUBECONFIG(kube_config) then content is always the same as KUBECONFIG. Could someone explain that?

-- Max Chen
kubectl
kubernetes

0 Answers