<p>My <code>.bash_profile</code> has many aliases that I use regularly. When I exec into a kubernetes pod, though, those aliases become (understandably) inaccessible. And when I say "exec into" I mean:</p>

<p><code>kubectl exec -it [pod-name] -c [container-name] bash</code></p>

<p>Is there any way to make it so that I can still use my bash profile after exec'ing in?</p>

<p>You said those are only the aliases. In that case and only in that case you could save the .<code>bash_profile</code> in the <code>ConfigMap</code> using <code>--from-env-file</code></p>

<pre><code>kubectl create configmap bash-profile --from-env-file=.bash_profile
</code></pre>

<p>Keep in mind that each line in the env file has to be in VAR=VAL format.</p>

<p><strong>Lines with # at the beginning and blank lines will be ignored.</strong></p>

<p>You can then load all the key-value pairs as container environment variables:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: bash-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      envFrom:
      - configMapRef:
          name: bash-profile
  restartPolicy: Never
</code></pre>

<p>Or <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#populate-a-volume-with-data-stored-in-a-configmap" rel="nofollow noreferrer">Populate a Volume with data stored in a ConfigMap</a>:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: bash-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "ls /etc/config/" ]
      volumeMounts:
      - name: config-volume
        mountPath: /root/.bash_profile
  volumes:
    - name: config-volume
      configMap:
        # Provide the name of the ConfigMap containing the files you want
        # to add to the container
        name: bash-profile
  restartPolicy: Never
</code></pre>

<p>The idea mentioned by @<a href="https://stackoverflow.com/users/2203038/mark">Mark</a> should also work.</p>

<p>If you do <code>kubectl cp .bash_profile &lt;pod_name&gt;:/root/</code> if you need to put it into a specific containers you can add option <code>-c, --container='': Container name. If omitted, the first container in the pod will be chosen</code>.</p>
