You only need a deployment to launch a container in Kubernetes. Deployments tell Kubernetes
- what container to run by specifying the Docker image name and tag
- spec: template: spec: containers: – image:
- when to pull the image from the registry
- spec: template: spec: containers: imagePullPolicy:
- If the image is always rebuilt with the same version, like “latest”, set the policy to Always to disable the image caching
- spec: template: spec: containers: imagePullPolicy:
- what to do when the container crashes
- spec: template: spec: containers: restartPolicy:
- usually set to Always
- spec: template: spec: containers: restartPolicy:
- how many replicas to launch simultaneously
- spec: replicas
- how to map this deployment to actual running containers
- The label in spec: selector: matchLabels: connects the deployment to the pod specified in the deployment template via the same deployment’s spec: template: metadata: labels:
- the way Kubernetes should replace containers when we update the deployment
- strategy:
- rollingUpdate (default)
- strategy:
- the namespace
- metadata: namespace:
- if not specified, the “Default” namespace is used
- metadata: namespace:
apiVersion: apps/v1
kind: Deployment
metadata:
name: app1-frontend-deployment
spec:
replicas: 3
selector:
matchLabels:
app: app1-frontend-template-label
template:
metadata:
labels:
app: app1-frontend-template-label
spec:
containers:
- name: app1-frontend-container-label
image: nginx:1.7.9
ports:
- containerPort: 80
To list all deployments
kubectl get deployments
To launch the container specified in the deployment file
kubectl apply -f ./MY_DEPLOYMENT_FILE.yml
Display information about the deployment
kubectl describe deployment MY_DEPLOYMENT
The deployment creates pods. A pod can contain one or multiple containers, usually one. To list the pods
kubectl get pods