Creating a pod in kubernetes which can run gnu screen

10/5/2017

I am creating a long-lived jump to run inside of my kubernetes cluster. It uses an EBS volume for the home folder, holds important copies of my code, and gives me fast access for routine behavior. The problem is that I can't use GNU screen to create similarly long-lived sessions.

Here's my 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

And here's how I deploy it:

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

But when I kubectl exec in to the container and try creating a screen:

root@doit-2561276907-kl2h6:~# screen -S asdf
Cannot open your terminal '' - please check.

I can work around this by doing:

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

Also, here's how I connect to the 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
}

So under the hood I am doing kubectl exec -it.

But I don't want all the users of this jumpbox instance to have to run script and switch back to bash. How can I create Pod which is already configured properly for screen?

-- xrl
bash
dockerfile
kubernetes
pty

1 Answer

10/5/2017

I tried this with centos image it works, need to check the ubuntu image.

kubectl run -it screentest --image=centos -- bash
kubectl exec -it screentest-cbd49447f-286wq -- bash
yum -y install screen
screen

Tested this in ubuntu also, it works for me.

kubectl run -it ubuntuest --image=ubuntu -- bash
apt-get update -qq && apt-get install screen -y
screen

also tried with kubectl exec -it ubuntuest-78df75fbb-9sk6f -- bash it works.

-- sfgroups
Source: StackOverflow