Kubernetes equivalent of 'docker run -it'

久未见 提交于 2019-12-24 10:44:34

问题


I have one docker image and I am using following command to run it.

docker run -it -p 1976:1976 --name demo demo.docker.cloud.com/demo/runtime:latest

I want to run the same in Kubernetes. This is my current yaml file.

apiVersion: v1
kind: Deployment
metadata:
  name: demo-deployment
  labels:
    app: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
      - name: demo
        image: demo.docker.cloud.com/demo/runtime:latest
        ports:
        - containerPort: 1976
        imagePullPolicy: Never

This yaml file covers everything except flag "-it". I am not able to find its Kubernetes equivalent. Please help me out with this. Thanks


回答1:


Looking at the Container definition in the API reference, the equivalent options are stdin: true and tty: true.

(None of the applications I work on have ever needed this; the documentation for stdin: talks about "reads from stdin in the container" and the typical sort of server-type processes you'd run in a Deployment don't read from stdin at all.)




回答2:


I assume you are trying to connect a shell to your running container. Following the guide at https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/ - You would need the following commands. To apply your above configuration:

Create the pod: kubectl apply -f ./demo-deployment.yaml

Verify the Container is running: kubectl get pod demo-deployment

Get a shell to the running Container: kubectl exec -it demo-deployment -- /bin/bash



来源:https://stackoverflow.com/questions/56371369/kubernetes-equivalent-of-docker-run-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!