Docker
DockerIntermediate

Docker Kubernetes Integration: A Complete Guide

DevHub Team
4 min read
DockerKubernetesContainer OrchestrationDevOps

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

Docker and Kubernetes integration enables powerful container orchestration capabilities for modern cloud-native applications. This guide explores the integration patterns, deployment strategies, and best practices for using Docker with Kubernetes.

$1

``mermaid

graph TB

subgraph "Docker Environment"

A[Docker Engine]

B[Container Registry]

C[Docker Build]

end

subgraph "Kubernetes Cluster"

D[API Server]

E[Controller Manager]

F[Scheduler]

G[kubelet]

H[Container Runtime]

end

A --> B

B --> H

C --> B

D --> G

G --> H

E --> D

F --> D

classDef docker fill:#1a73e8,stroke:#fff,color:#fff

classDef k8s fill:#34a853,stroke:#fff,color:#fff

class A,B,C docker

class D,E,F,G,H k8s

`

$1

$1

`yaml

/etc/docker/daemon.json

{

"exec-opts": ["native.cgroupdriver=systemd"],

"log-driver": "json-file",

"log-opts": {

"max-size": "100m"

},

"storage-driver": "overlay2",

"registry-mirrors": [

"https://registry.docker-cn.com",

"https://mirror.gcr.io"

]

}

`

$1

`yaml

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 = true

`

$1

$1

`yaml

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"

`

$1

`yaml

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: {}

`

$1

$1

Registry Authentication Integration
Docker Hub docker login imagePullSecrets
Azure Container Registry az acr login Managed Identity
Google Container Registry gcloud auth Workload Identity

$1

`yaml

secret.yaml

apiVersion: v1

kind: Secret

metadata:

name: registry-secret

type: kubernetes.io/dockerconfigjson

data:

.dockerconfigjson:

---

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:v1

`

$1

$1

`yaml

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: 80

`

$1

$1

`yaml

persistent-volume.yaml

apiVersion: v1

kind: PersistentVolume

metadata:

name: myapp-pv

spec:

capacity:

storage: 10Gi

accessModes:

- ReadWriteOnce

hostPath:

path: /data/myapp

---

persistent-volume-claim.yaml

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: myapp-pvc

spec:

accessModes:

- ReadWriteOnce

resources:

requests:

storage: 10Gi

`

$1

$1

`yaml

resource-quota.yaml

apiVersion: v1

kind: ResourceQuota

metadata:

name: compute-quota

spec:

hard:

requests.cpu: "4"

requests.memory: 4Gi

limits.cpu: "8"

limits.memory: 8Gi

`

$1

`yaml

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: 50

`

$1

$1

`yaml

prometheus-servicemonitor.yaml

apiVersion: monitoring.coreos.com/v1

kind: ServiceMonitor

metadata:

name: myapp-monitor

spec:

selector:

matchLabels:

app: myapp

endpoints:

- port: metrics

`

$1

Component Log Path Collection Method
Container Logs /var/log/containers Fluentd DaemonSet
Docker Daemon /var/log/docker Filebeat
Kubernetes Events API Server Event Exporter

$1

$1

`yaml

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

`

$1

`yaml

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: 8080

``

$1

$1

Practice Description Implementation
ConfigMaps Store configuration Use volumes
Secrets Secure sensitive data Use env vars
RBAC Access control Use roles

$1

$1

Issue Cause Solution
ImagePullBackOff Registry auth Check secrets
CrashLoopBackOff App failure Check logs
Pending Resource limits Check quota

$1

1. [Kubernetes Documentation](https://kubernetes.io/docs/)

2. [Docker Documentation](https://docs.docker.com/)

3. [Container Runtime Interface](https://kubernetes.io/docs/concepts/architecture/cri/)

4. [Kubernetes Networking](https://kubernetes.io/docs/concepts/cluster-administration/networking/)

5. [Kubernetes Security](https://kubernetes.io/docs/concepts/security/)

6. [Kubernetes Best Practices](https://kubernetes.io/docs/concepts/configuration/overview/)

  • [Docker Multi-stage Builds](/posts/docker/multi-stage-builds) - Build optimization
  • [Docker Security Scanning](/posts/docker/security-scanning) - Container security
  • [Docker Compose V2](/posts/docker/compose-v2) - Container orchestration
  • [Docker Desktop Alternatives](/posts/docker/desktop-alternatives) - Development environment
  • 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.