[英]How can I exec into a K8s pod but use a bash_profile from outside of it?
我的.bash_profile
有很多我经常使用的别名。 但是,当我执行到 kubernetes pod 时,这些别名变得(可以理解的)无法访问。 当我说“执行到”时,我的意思是:
kubectl exec -it [pod-name] -c [container-name] bash
有什么办法可以让我在执行后仍然可以使用我的 bash 配置文件?
你说那些只是别名。 在这种情况下,只有在这种情况下,您才能保存。 使用bash_profile
--from-env-file
在ConfigMap
中的 bash_profile
kubectl create configmap bash-profile --from-env-file=.bash_profile
请记住,env 文件中的每一行都必须采用 VAR=VAL 格式。
以#开头的行和空白行将被忽略。
然后,您可以将所有键值对加载为容器环境变量:
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
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
@Mark提到的想法也应该有效。
如果你做kubectl cp.bash_profile <pod_name>:/root/
如果你需要把它放到一个特定的容器中你可以添加选项-c, --container='': Container name. If omitted, the first container in the pod will be chosen
-c, --container='': Container name. If omitted, the first container in the pod will be chosen
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.