How to Create a Deployment
In this section, we'll create a brand-new Kubernetes Deployment from a YAML file. We can do the same thing imperatively using the kubectl run
command, but we shouldn't. The right way is the declarative way!
The following code snippet is the Deployment manifest file that we'll use. It's available in the book's GitHub repo in the deployments
folder and is called deploy.yml
.
The examples assume it's in your system's PATH and is called deploy.yml
.
apiVersion: apps/v1 #Older versions of k8s use apps/v1beta1 kind: Deployment metadata: name: hello-deploy spec: replicas: 10 selector: matchLabels: app: hello-world minReadySeconds: 10 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 template: metadata: labels: app: hello-world spec: containers: - name: hello-pod image: nigelpoulton/k8sbook:latest ports: ...