TDeployments are declarative objects that described the deployed application. The Deployment object exists to manage the release of new version of the applications. We can simply to rollout or rollback without downtime through deployment.
The Yaml file for the deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kuard
spec:
selector:
matchLabels:
run: kuard
replicas: 1
template:
metadata:
labels:
run: kuard
spec:
containers:
- name: kuard
image: gcr.io/kuar-demo/kuard-amd64:blue
The ReplicaSet is managing the Pods and Deployment is managing the ReplicaSet.
We can get know the ReplicaSet and desire status from the Deployment.
#kubectl get deployments deploymentname -o jsonpath --template {.spec.selector.matchLabels}
Example:
$ kubectl get deployments kuard -o jsonpath --template {.spec.selector.matchLabels}
map[run:kuard]
$ kubectl get replicasets --selector=run=kuard
NAME DESIRED CURRENT READY AGE
kuard-1128242161 1 1 1 13m
The Yaml file for the rolling update through deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: null
generation: 1
labels:
run: kuard
name: kuard
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/kuard
spec:
progressDeadlineSeconds: 2147483647
replicas: 2
revisionHistoryLimit: 10
selector:
matchLabels:
run: kuard
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: kuard
spec:
containers:
- image: gcr.io/kuar-demo/kuard-amd64:blue
imagePullPolicy: IfNotPresent
name: kuard
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
The Strategy object is defined the rollout option of the deployment. It has two ways to do this rollout task. 1) recreate 2) RollingUpdate
The deployment is using for two main purposes. 1) Scaling 2) Rolling update
Scaling:
We can edit the deployment yaml file updated the ReplicaSet as per your scaling. We can autoscaling easily without any downtime through deployment.
Rolling update or updated with Latest image:
We can edit the yaml file and updated the latest image of the application. It will rollout without any error/downtime through deployment.
P.S: Make sure to add the change cause annotation whenever your performing the rolling out of the application.
Monitoring the Rollout action:
# kubectl rollout status deployments deploymentname
Example:
$ kubectl rollout status deployments kuard
deployment kuard successfully rolled out
Rollout history:
#kubectl rollout history deployments deploymentname
Rollback the deployment to previous version incase of any issue with new release.
# kubectl rollout undo deployments deploymentname
$ kubectl rollout undo deployments kuard
deployment "kuard" rolled back
DameonSet:
DamonSet are used to deploying a system dameons such as log collectors and monitoring agents which typically run on each nodes. DamonSets are created by submitting a DemonSet configuration to the Kubernetes API server.
The Yaml file for the DameonSet:
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: fluentd
labels:
app: fluentd
spec:
template:
metadata:
labels:
app: fluentd
spec:
containers:
- name: fluentd
image: fluent/fluentd:v0.14.10
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
Node selectors can be limit what pods can run on given time in the K8S cluster. It will restrict the Pod creation on every node by using a DamonSet configuration.
No comments:
Post a Comment