<p>I've created a <code>Makefile</code> to export a <code>kubeconfig</code> from <strong>fixed</strong> path like:</p>

<pre><code>myproj
 - .kube     //folder
     config    //file which contain the config
 - Makefile.  //same level as .kube folder
</code></pre>

<p>Now when I'm running <strong>from the terminal</strong> the following it works, I mean if I run <code>kubectl get ns</code> I got results which means that it configure <strong>successfully</strong>!</p>

<pre><code>export KUBECONFIG=/Users/i33333/projects/app-test/v-app/.kube/config
</code></pre>

<p>I've created a makefile target like following</p>

<pre><code>kube-cfg:
    export KUBECONFIG=$(PWD)/.kube/config
</code></pre>

<p>When execute the target I see in the terminal </p>

<pre><code>export KUBECONFIG=/Users/i33333/projects/app-test/v-app/.kube/config
</code></pre>

<p><strong>which exactly the same</strong> as doing that manually but when when I run <code>kubectl get ns</code></p>

<p>I got error: </p>

<pre><code>error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
</code></pre>

<p>I dont understand why it <strong>dosent work when I run it from makefile</strong>  and works when I run it from the terminal manually ? any idea 
I try to change and use also the $(CURRDIR) which doesnt help</p>

<p><strong>update</strong></p>

<p>I've tried like suggested which doesnt works</p>

<pre><code>KUBECONFIG=$(PWD)/.kube/config


kube-cfg:
    export $(KUBECONFIG)
</code></pre>

<p><strong>update2</strong></p>

<p>If I do it like this</p>

<pre><code>KUBECONFIG := $(PWD)/kube/config.yaml
tgt1:
    @export KUBECONFIG=$(KUBECONFIG) &amp;&amp; kubectl get ns
</code></pre>

<p><strong>I was able to see the ns</strong> when running the makefile <code>tgt1:</code> but 
if now I want to run it from the terminal <code>kubectl get ns</code> I get the same error `error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable, <strong>I want to configure it from the makefile</strong></p>

<p>When you run <code>make</code> the recipe is executed in a shell that is forked from <code>make</code> process. Also-recipes spanning multiple, each line (unless chained over newline escape) also gets its own shell child process. This effectively means, whatever happens (shell variable assignments or exports) in any of these shells, has no impact on the <code>make</code> itself or other recipe lines.</p>

<p>You could define for instance a make variable (as you have done in the update) and then you can set that in an environment for any command (<code>somecmd</code>) you are trying to run, e.g.:</p>

<pre><code>some_target:
    export KUBECONFIG=$(KUBECONFIG); somecmd
</code></pre>

<p>or:</p>

<pre><code>some_target:
    KUBECONFIG=$(KUBECONFIG) somecmd
</code></pre>

<hr>

<p>In that case <code>KUBECONFIG</code> refers to a make variable, like the one you've defined above:</p>

<pre><code>KUBECONFIG := $(PWD)/.kube/config
</code></pre>

<p>I.e. like this:</p>

<pre><code>KUBECONFIG := $(PWD)/.kube/config

all: tgt1 tgt2

tgt1:
        @export KUBECONFIG=$(KUBECONFIG); echo "KUBECONFIG is $${KUBECONFIG}"

tgt2:
        @KUBECONFIG=$(KUBECONFIG) sh -c 'echo KUBECONFIG is $${KUBECONFIG}'
</code></pre>

<p>Yielding:</p>

<pre><code>$ make
KUBECONFIG is /tmp/.kube/config
KUBECONFIG is /tmp/.kube/config
</code></pre>

<hr>

<p>So, if you're after something that does persists also after the <code>make</code> is done, you need to write it out. E.g. a wrapper, such such as:</p>

<pre><code>KUBECONFIG := $(PWD)/kube/config.yaml

.PHONY: call

# run callme.sh being the first prerequisite.
call: callme.sh
    ./$&lt;

# creates and sets exec bit on rule target here being callme.sh
callme.sh:
    @echo -e '#!/bin/bash\nKUBECONFIG=$(KUBECONFIG) kubectl get ns' &gt; $@
    chmod +x $@
</code></pre>

<p>This make you can run <code>make</code> and target <code>call</code> calls the wrapper... and you're also left with a wrapper <code>callme.sh</code> you can run after <code>make</code> is done.</p>
