【发布时间】:2017-10-05 01:33:31
【问题描述】:
我正在创建一个长寿命的跳转以在我的 kubernetes 集群内运行。它使用 EBS 卷作为主文件夹,保存我的代码的重要副本,并让我快速访问日常行为。问题是我不能使用 GNU screen 创建类似的长寿命会话。
这是我的 Dockerfile:
FROM ubuntu:zesty
ENV KUBECTL_VERSION=v1.7.6
RUN apt-get update && \
apt-get install -y \
htop vim sysstat \
build-essential make \
ruby ruby-dev rake \
postgresql-client libpq-dev \
curl wget \
python python-pip && \
pip install awscli && \
gem install --no-rdoc --no-ri bundler
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl && \
chmod a+x kubectl && \
mv kubectl /usr/local/bin/kubectl
ADD dotfiles /root-dotfiles
ADD code /root-code
ADD docker-entrypoint.sh /docker-entrypoint.sh
我是这样部署它的:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: doit
purpse: jumpbox
name: doit
namespace: default
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: doit
purpose: jumpbox
template:
metadata:
labels:
app: doit
purpose: jumpbox
spec:
containers:
- image: 123.dkr.ecr.eu-central-1.amazonaws.com/doit:latest
imagePullPolicy: Always
name: doit
command: ["sleep", "infinity"]
workingDir: /root
env:
- name: TERM
value: xterm
volumeMounts:
- mountPath: /root
subPath: root-homedir
name: doit-home
volumes:
- name: doit-home
persistentVolumeClaim:
claimName: doit-home
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 1
但是当我kubectl exec 进入容器并尝试创建一个屏幕时:
root@doit-2561276907-kl2h6:~# screen -S asdf
Cannot open your terminal '' - please check.
我可以通过以下方式解决这个问题:
root@doit-2561276907-kl2h6:~# script /dev/null
Script started, file is /dev/null
# bash
root@doit-2561276907-kl2h6:~# screen -S asdf
# now inside of the screen
另外,这是我连接到 Pod 的方式:
function doit {
doit_pods=$(kubectl get pods -l 'app==doit' -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
kubectl exec -it $doit_pods bash
}
所以在后台我正在做kubectl exec -it。
但我不希望此 jumpbox 实例的所有用户都必须运行脚本并切换回 bash。如何创建已经为 screen 正确配置的 Pod?
【问题讨论】:
-
你在使用
kubectl exec -it吗? -
是的,我正在使用它。查看“这是我连接到 Pod 的方式”部分。这是一个帮助函数,用于查找 pod 并针对它运行 exec -it。
标签: bash kubernetes dockerfile pty