jrdzha
jrdzha

Reputation: 191

Kubernetes and Docker Relationship

What is the nature of the relationship between Docker and Kubernetes? Is it safe to assume that ALL Docker operations done within a Pod will treat the Pod as if it is a normal host machine?

For example, if I were to use the Python Docker SDK, attach to the /var/run/docker.sock, and create a volume, will this volume only exist within the Pod?

My main concern is that I know a Pod is virtualized, thus may not play nicely if I dig a little too deep via other virtualization tools like Docker.

Upvotes: 2

Views: 349

Answers (2)

Webber
Webber

Reputation: 5484

It's important to understand what the responsibility of each of these concepts is.

  • A Docker container is in essence a boundary between the host OS and guest OS, that allows for a process to run in isolation (docs).
  • Kubernetes is an orchestration platform for running such containers (docs).
  • Finally a Pod is a kubernetes object that describes how a docker container is to be run (docs).

With that knowledge we can answer some of your questions;

What is the nature of the relationship between Docker and Kubernetes?

Kubernetes can run docker containers like your computer can, but it's optimised for this specific goal. Kubernetes is also an abstraction (or orchestration) layer, handling resources like network capability, disk space, and cpu cycles for you.

Is it safe to assume that ALL Docker operations done within a Pod will treat the Pod as if it is a normal host machine?

A Pod is not a host in any way. It's merely a description of how a docker container (or multiple) should run. Any resulting containers are running in the virtual space that is created by the kubernetes Nodes.

For example, if I were to use the Python Docker SDK, attach to the /var/run/docker.sock, and create a volume, will this volume only exist within the Pod?

This is something you can do on your local machine, and while technically you could do this on your Node as well, it's not a common use case.

Note that a docker container is isolated from any external factors like a mount or a network socket (which only happen at runtime, and don't change the state of the container itself). You can however configure a container (using a Pod object) to recreate the same conditions on your cluster.

Upvotes: 4

David Maze
David Maze

Reputation: 158647

If Kubernetes is running Docker (it's not guaranteed to) then that /var/run/docker.sock will be the host's Docker socket; there is not an additional layer of virtualization.

You shouldn't try to use Docker primitives in an application running in Kubernetes. The approach you describe can lead to data loss, even, if you try to create a Docker-native volume on a node but then a cluster autoscaler or some other task destroys the node. If you need to create storage or additional containers, you can use the Kubernetes API to create PersistentVolumeClaims, Jobs, and other Kubernetes-managed objects.

Upvotes: 2

Related Questions