kubectl apply creates or updates Kubernetes resources from YAML configuration. It supports a declarative workflow: edit the configuration, then apply it to the cluster instead of constructing every object imperatively. section 11.4.3
Common deployment uses include:
- Generate a Secret manifest with kubectl create secret --dry-run=client -o yaml, save it, and later apply it with kubectl apply -f secret.yaml. section 11.4.3
- Update a Deployment manifest, such as changing its container image, and apply the change to start a rolling update. section 4.2.1
- Modify a blue/green Deployment or Service manifest and apply each change, including switching the Service selector to the prepared version. section 4.2.3
Applying a production image change
Change the image in a Deployment manifest, then run kubectl apply -f deploy.yaml. With a rolling-update strategy, Kubernetes replaces Pods while continuing to serve requests; with blue/green, apply the manifest changes and switch the Service selector after the new Deployment is ready. section 4.2.1 section 4.2.3
Listing 4.6 Chapter04/4.2.1_RollingUpdate/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: timeserver
spec:
replicas: 3
selector:
matchLabels:
pod: timeserver-pod
strategy:
type: RollingUpdate #1
rollingUpdate: #2
maxSurge: 2 #2
maxUnavailable: 1 #2
template:
metadata:
labels:
pod: timeserver-pod
spec:
containers:
- name: timeserver-container
image: docker.io/wdenniss/timeserver:3
#1 Rolling update strategy
#2 Optional configuration
A Deployment manifest shows the kind of versioned configuration that kubectl apply updates, including the image and rolling-update settings. section 4.2.1





