TL;DR
Master Docker and Kubernetes integration with this comprehensive guide covering container orchestration, deployment strategies, and best practices for cloud-native applications
Docker Kubernetes Integration: A Complete Guide
Executive Summary
Docker and Kubernetes meet at one precise point: the OCI container image. Docker is how most teams build and package images; Kubernetes is how they run those images at scale. The runtime story has changed and this guide states it plainly: Kubernetes no longer uses Docker Engine directly. Since the removal of dockershim, clusters run images through CRI runtimes such as containerd and CRI-O, which pull and execute the same images Docker builds. This guide covers the build-to-cluster path end to end: runtimes, Deployments, multi-container Pods, private registries and image pull secrets, Services and Ingress, persistent storage, resource quotas, autoscaling, security contexts, and network policies, with the YAML needed for each.
Why This Matters
Teams stumble here in predictable ways. They assume Kubernetes needs Docker installed on nodes and are surprised by how modern clusters actually work. They push images to a registry the cluster cannot authenticate to and meet ImagePullBackOff on day one. They deploy without resource requests, so the scheduler packs nodes blindly and one workload starves the rest. Or they treat a Pod like a small VM, putting state inside it that vanishes on reschedule. Getting the integration right means understanding which tool owns which job: Docker builds the artifact, the registry stores and distributes it, and Kubernetes schedules, networks, heals, and scales it.
Core Concepts
The Runtime Reality: CRI, containerd, and CRI-O
Kubernetes talks to runtimes through the Container Runtime Interface (CRI). Docker Engine does not implement CRI, which is why the dockershim shim that once bridged them was removed from Kubernetes. Modern clusters default to containerd (the same runtime component that Docker itself uses internally) or CRI-O. Nothing about your workflow needs to change: docker build produces an OCI image, and containerd runs it happily. What does change is node administration: on the node you inspect containers with crictl, not the Docker CLI, and Docker Engine configuration files such as daemon.json are irrelevant to the cluster.
For reference, the containerd side is configured to use the systemd cgroup driver, which should match the kubelet's setting to avoid cgroup mismatch instability:
# containerd-config.toml
version = 2
[plugins."io.containerd.grpc.v1.cri"]
[plugins."io.containerd.grpc.v1.cri".containerd]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = trueDeployments: The Basic Unit of Work
A Deployment declares how many replicas of a Pod should exist and how updates roll out. Resource requests tell the scheduler what a Pod needs; limits cap what it can take. Both belong in every production manifest.
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myregistry.azurecr.io/myapp:v1
ports:
- containerPort: 8080
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "200m"
memory: "256Mi"Tag images with an immutable version or digest, never latest: Kubernetes cannot tell that a latest tag changed, and rollbacks become unreliable.
Multi-Container Pods and Sidecars
Containers in the same Pod share a network namespace and can share volumes, which enables the sidecar pattern: a helper container that ships logs, proxies traffic, or syncs files alongside the main application.
# multi-container-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: app
image: myregistry.azurecr.io/myapp:v1
volumeMounts:
- name: shared-data
mountPath: /data
- name: sidecar
image: myregistry.azurecr.io/sidecar:v1
volumeMounts:
- name: shared-data
mountPath: /data
volumes:
- name: shared-data
emptyDir: {}Co-locate containers only when they genuinely share a lifecycle and need localhost or shared-volume communication. Independent services belong in independent Deployments so they can scale and fail separately.
Registries and Image Pull Secrets
Public images pull anonymously; private ones need credentials the kubelet can use. Cloud registries integrate with cluster identity (managed identity on AKS, workload identity on GKE, IAM roles on EKS). For any other private registry, create a dockerconfigjson Secret and reference it as imagePullSecrets:
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: registry-secret
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: <base64-encoded-docker-config>
---
# deployment-with-secret.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
template:
spec:
imagePullSecrets:
- name: registry-secret
containers:
- name: myapp
image: myregistry.azurecr.io/myapp:v1ImagePullBackOff almost always means one of three things: the tag does not exist, the registry is unreachable from the nodes, or the pull secret is missing or stale. Check the Pod's events before anything else.
Services and Ingress
A Service gives a set of Pods a stable virtual IP and DNS name and load-balances across them. Ingress adds HTTP routing by host and path in front of Services.
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: myapp
---
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp-service
port:
number: 80Storage: Volumes, PVs, and PVCs
emptyDir dies with the Pod. Data that must survive is claimed through a PersistentVolumeClaim, which binds to a PersistentVolume, in practice usually provisioned dynamically by a StorageClass from the cloud or storage platform:
# persistent-volume-claim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myapp-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10GiPrefer dynamic provisioning over hand-written PVs, and remember ReadWriteOnce means one node at a time; workloads needing shared read-write storage need a storage class that supports it.
Resource Governance and Autoscaling
ResourceQuotas bound a namespace so one team cannot consume the cluster, and they only work when workloads declare requests. The HorizontalPodAutoscaler then scales Deployments against metrics such as CPU utilisation:
# hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50CPU utilisation in an HPA is measured against the Pod's requests, which is another reason requests are not optional.
Security: Contexts and Network Policies
Apply a security context to every workload: run as a non-root user, disallow privilege escalation, and use a read-only root filesystem where the application allows it. Then restrict traffic with NetworkPolicy, which is default-allow until you write one; the policy below accepts ingress only from frontend Pods:
# secure-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: secure-pod
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
containers:
- name: myapp
image: myregistry.azurecr.io/myapp:v1
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true# network-policy.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: myapp-policy
spec:
podSelector:
matchLabels:
app: myapp
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
role: frontend
ports:
- protocol: TCP
port: 8080Configuration follows the same split as Docker: ConfigMaps for ordinary settings, Secrets for sensitive values, mounted as volumes or exposed as environment variables, with RBAC governing who may read them.
Decision Framework
| Situation | Recommendation |
|---|---|
| Building images for a cluster | Docker or BuildKit locally and in CI; the cluster never builds images |
| Private registry on a cloud Kubernetes service | Use the cloud identity integration instead of stored pull secrets |
| Private registry elsewhere | dockerconfigjson Secret referenced via imagePullSecrets |
| Debugging a node-level container problem | crictl, not the Docker CLI; nodes do not run Docker Engine |
| Two containers that must share localhost and files | One Pod with a sidecar |
| Two independently scaling services | Separate Deployments and Services |
| Stateful workload | StatefulSet with PVCs from a dynamic StorageClass |
Implementation Checklist
latestTrade-offs
Kubernetes adds real operational weight: a control plane to run or pay for, a declarative model to learn, and failure modes (scheduler, CNI, ingress controller) that do not exist in plain Docker. containerd on nodes means Docker-specific tooling habits, such as reaching for docker ps during an incident, stop working and must be relearned with crictl. In exchange you get self-healing, rolling updates, and scaling that Compose and Swarm cannot match. For a single host or a handful of static services, that exchange is a bad deal.
When Not to Use
Conclusion
Docker builds the image; Kubernetes runs it, through containerd or CRI-O rather than Docker Engine. Keep that division clear, declare resources honestly, authenticate your registries, and apply security contexts and network policies from the first deployment. Do those things and the integration is uneventful, which is precisely what you want from infrastructure.
References
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.