我的.bash_profile
具有许多我经常使用的别名。但是,当我执行kubernetes Pane 时,这些别名变得(无法理解)变得不可访问。当我说“exec into”时,我的意思是:kubectl exec -it [pod-name] -c [container-name] bash
有什么办法可以使我在执行后仍可以使用bash配置文件吗?
最佳答案
您说的只是别名。在这种情况下,只有在这种情况下,您才能保存。使用bash_profile
的ConfigMap
中的--from-env-file
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
或Populate a Volume with data stored in a ConfigMap:
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
选项。
关于bash - 如何执行到K8s pods 中,但从外部使用bash_profile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58547457/