-2

I am starting my docker container using following command
docker run -it -d -p 80001:8000.
Now i want to use use docker container in kubernetes using deployment. How to setup container spec secion of deployment for above mentioned arugment -it and -d. both are require.So first allocate stdin and tty to pod and then keep it running into detach mode.

Akshay Gopani
  • 473
  • 4
  • 16

1 Answers1

1

You don't need to add -it -d. Kubernetes deployment will wake-up the pod in detached mode. Interactive mode (-i) has no sense because it runs in detached mode, and -t (allowcate pseudo tty) also don't needed. There is thread in about dealing with tty in deployments here https://www.reddit.com/r/kubernetes/comments/hczzi2/when_dealing_with_deployments_what_does_tty_true/

If you need later access to this pod you can use kubectl exec -ti <podname> -- bash.

Remember that your pod should run in background some kind of service or at least an sleep loop.

Here more information on how to do this kind of loop How can I keep a container running on Kubernetes?

Update:

If you want to run a pod in Kubernetes with -ti you can do:

kubectl run -i -t busybox --image=busybox --restart=Never --port=8001

after exit remember to delete it with kubectl delete pod busybox

If you want forward ports you can do:

kubectl port-forward busybox 8001:8001 and go to localhost:8001

TlmaK0
  • 3,578
  • 2
  • 31
  • 51
  • @SiHa He is asking for run container in kubernetes with `-ti` nothing about port configuration in deployment. `How to setup container spec secion of deployment for above mentioned arugment -it and -d` – TlmaK0 Jan 27 '22 at 10:51
  • my docker container need -it at start. otherwise docker cmd command will exit. – Akshay Gopani Jan 27 '22 at 10:52
  • 1
    @AkshayGopani No way to do this with kubernetes, kubernetes pod always run in detached mode. – TlmaK0 Jan 27 '22 at 10:52
  • 2
    @AkshayGopani checkout this link https://stackoverflow.com/questions/31870222/how-can-i-keep-a-container-running-on-kubernetes – TlmaK0 Jan 27 '22 at 10:59
  • @TlmaK0 what about this one https://stackoverflow.com/questions/55584280/docker-run-to-kubernetes-yaml . there tty and std – Akshay Gopani Jan 27 '22 at 11:14
  • 1
    @AkshayGopani I'm not sure how tty:true and stdin:true will afect your pod in a deployment, but if you only want to run a pod you can do `kubectl run -i -t busybox --image=busybox --restart=Never` – TlmaK0 Jan 27 '22 at 11:27
  • @AkshayGopani I have updated the answer with run it as a pod directly and not as a deployment – TlmaK0 Jan 27 '22 at 11:37
  • @TlmaK0 i want to run pod from deployment. – Akshay Gopani Jan 27 '22 at 11:46
  • @AkshayGopani so you need to execute a loop, if not the pod will stop, and then run `kubectl exec -ti pod-name -- bash` to access the pod running in the cluster – TlmaK0 Jan 27 '22 at 11:47
  • @AkshayGopani Provided answer has all you need to start with. Remember: kubernetes is not docker, here it works differently. Get familiar with [kubernetes documentation specifically about pods](https://kubernetes.io/docs/concepts/workloads/pods/) and manifests. Also there are imperative or declarative ways to create resources - see [article about it](https://medium.com/payscale-tech/imperative-vs-declarative-a-kubernetes-tutorial-4be66c5d8914) – moonkotte Jan 27 '22 at 14:57
  • 1
    @AkshayGopani Also see [kubernetes api reference - pod.spec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#podspec-v1-core) and there are no `tty` or `std` fields. So as correctly TimaK0 mentioned those fields do not make any sense. I suggest reading official kubernetes documentation as a source of up-to-date information. – moonkotte Jan 27 '22 at 15:08