简体   繁体   中英

how to create kubernetes pod with docker container

I have running docker container A and I want to create pod with container A. Is it possible? If it isn't, Can I hold container state "created" in kubernetes?

I also tried setting containerID to the running containerID in the pod.yaml file, and tried to change the containerID to kubectl edit on the already running pod, but not all succeeded.

All together running the container and running the pod both are different.

If you want to run container A in a pod follow steps below: 1. create a docker image from container A and push to docker registry 2. create a deployment.yaml file for Kubernetes and mention this container docker pull URL and tag in image and tag section 3. deploy pod using kubectl apply -f deployment.yaml

There's no way to "import" a pre-existing Docker container into a Kubernetes pod. Kubernetes always manages the entire lifecycle of a container, including deciding which host to run it on.

If your workflow involves doing some manual setup in between docker create and docker start , you should try to automate this; Kubernetes has nothing equivalent and in fact sometimes it will work against you. If a node gets destroyed (either because an administrator drained it or because its hard disk crashed or something else) Kubernetes will try to relocate every pod that was there, which means containers will get destroyed and recreated somewhere else with no notice to you. If you use a deployment to manage your pods (and you should) you will routinely have multiple copies of a pod, and there you'd have to do your manual setup on all of them.

In short: plan on containers being destroyed and recreated regularly and without your intervention. Move as much setup as you can into your container's entrypoint, or if really necessary, an init container that runs in the pod. Don't expect to be able to manually set up a pod before it runs. Follow this approach in pure-Docker space, too: a single container on its own shouldn't be especially valuable and you should be able to docker rm && docker run a new copy of it without any particular problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM