Deployment Configuration

Deployment Controller

  • In Kubernetes, the smallest unit that you can deploy is a Pod which is one or more Docker containers that are grouped together.
  • Usually, it's a single Docker container within a pod.
  • For scaling and high availability, we need multiple instances of our application running. So we use Replication Controller to create replicas of pods.
  • Replication Controller ensures that the required number of replicas are running at all times.
  • A Deployment builds on replication controller with additional support for Application Lifecycle Management such as seamless upgrades, rollbacks, application revisioning, etc.

Deployment

  • As in previous web application, you can see its deployment configuration
  • Image indicates the docker image which is built from the Build configuration
  • Replicas indicates number of replica
  • Strategy indicates the deployment strategy. Rolling means the deployment  will update the replicas one at a time
  • In Triggers section shows when the deployment is triggered i.e.:
    • When the Docker image changes, when the Build job runs
    • When the deployment configuration changes

YAML File

  • The YAML file looks very similar to a deployment configuration in Kubernetes but they are not the same.
    • kind is DeploymentConfig instead of Deployment
    • apiVersion is specific to OpenShift
  • The remaining sections are similar such as the specification, replicas, strategy, and template.
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: '2018-06-23T12:40:17Z'
  generation: 3
  labels:
    app: simple-webapp-flask
  name: simple-webapp-flask
  namespace: workshop
  resourceVersion: '23188162'
  selfLink: >-
    /apis/apps.openshift.io/v1/namespaces/workshop/deploymentconfigs/simple-webapp-flask
  uid: 95332d5a-76e2-11e8-a221-1276fea5e684
spec:
  replicas: 1
  selector:
    deploymentconfig: simple-webapp-flask
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: simple-webapp-flask
        deploymentconfig: simple-webapp-flask
    spec:
      containers:
        - image: >-
            172.30.14.44:5000/workshop/simple-webapp-flask@sha256:e406540a8e194497948bba5827c191feba8c53fdf09fa9ad9cb0092f8e872631
          imagePullPolicy: Always
          name: simple-webapp-flask
          ports:
            - containerPort: 8080
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
  test: false
  triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
          - simple-webapp-flask
        from:
          kind: ImageStreamTag
          name: 'simple-webapp-flask:latest'
          namespace: workshop
        lastTriggeredImage: >-
          172.30.14.44:5000/workshop/simple-webapp-flask@sha256:e406540a8e194497948bba5827c191feba8c53fdf09fa9ad9cb0092f8e872631
      type: ImageChange
    - type: ConfigChange

Rollback

  • Simply select previous deployment, and click Rollback.

Deployment Strategy

  • By default, deployment strategy is Rolling Update

  • Blue/Green deployment lets you test the green version first before switching the routing from all the users to them.

  • A/B deployment lets you split the traffic to both blue and green versions and gradually increase to the new version until fully upgraded.

Command Review

  • oc rollout latest dc/simple-webapp-docker
  • oc rollout history dc/simple-webapp-docker
  • oc rollout describe dc simple-webapp-docker
  • oc rollout undo dc/simple-webapp-docker

Workshop

  • From the previous simple-webapp-docker application that we already build the Docker image.
  • We will create a deployment for that by copying and modifying the YAML file from this documentation page.
  • And add this YAML file to our project to create a new deployment.
kind: "DeploymentConfig"
apiVersion: "v1"
metadata:
  name: "simple-webapp-docker"
spec:
  template: 
    metadata:
      labels:
        name: "simple-webapp-docker"
    spec:
      containers:
        - name: "simple-webapp-docker"
          image: "simple-webapp-docker:latest"
          ports:
            - containerPort: 8080
              protocol: "TCP"
  replicas: 1
  triggers:
    - type: "ConfigChange" 
    - type: "ImageChange" 
      imageChangeParams:
        automatic: true
        containerNames:
          - "simple-webapp-docker"
        from:
          kind: "ImageStreamTag"
          name: "simple-webapp-docker:latest"
  strategy: 
    type: "Rolling"
  paused: false 
  revisionHistoryLimit: 2 
  minReadySeconds: 0 

No Comments

Back to top