You create a Deployment object with a desired state. A Deployment controller changes the actual state to the desired state at a controlled rate.
Deployments (updates and rollbacks) wrap around Replication Controllers (actually for Deployments a Replica Set – Scalability, reliability, desired state) which wrap around Pods.
Old way of deploying:
Use Replication Controller and do:
kubectl rolling-update -f updated-rc.yml
but now handled by the control plane:
YAML -> apiserver -> deployed to cluster
To change, update YAML and push to apiserver. This then creates a new Replica Set.
Note: the old Replica Set remains. Which makes it easy to rollback.
Declaratively, with a manifest. E.g.
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: hello-deploy spec: replicas: 10 minReadySeconds: 10 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 template: metadata: labels: app: hello-world spec: containers: - name: hello-pod image: your/image ports: - containerPort: 8080
Note the relevant bits are:
minReadySeconds: 10 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1
Note: I’m aliasing kubectl -> k
k apply -f deploy.yml --record k describe deploy hello-deploy k rollout status deployment hello-deploy k get deploy hello-deploy k rollout history deployment hello-deploy k rollout undo deployment hello-deploy
A Kubernetes Service defines Pods and a policy – aka a micro-service.
Note: the set of Pods targetted by a Service is usually done using a Label Selector.
Note: you can create a Service at the same time you create a Deployment by using
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
ClusterIP: internal IP only available in cluster
NodePort: usually used as a Cluster wide point of access for a LoadBalancer.