OpenShift Pods & Services

Length: 00:10:40

Lesson Summary:

OpenShift leverages the kubernetes concept of a pod, defined as "one or more containers deployed together on one host, & the smallest compute unit that can be defined, deployed, & managed."

Pods are the rough equivalent of a machine instance (physical or virtual) to a container, wherein each pod is allocated its own internal IP address, therefore owning its entire port space, and containers within pods can share their local storage and networking.

openshift treats pods as largely immutable; changes cannot be made to a pod definition while it is running. openshift implements changes by terminating an existing pod and recreating it with modified configuration, base image(s), or both. Pods are also treated as expendable, and do not maintain state when recreated. Therefore pods should usually be managed by higher-level controllers, rather than directly by users.

apiVersion: v1
kind: Pod
metadata:
  name: mysql (1)
  labels: (2)
    name: mysql
spec:
  containers: (3)
    - resources:
        limits :
          cpu: 0.5
      image: openshift/mysql-55-centos7 (5)
      name: mysql
      env: (4)
        - name: MYSQL_ROOT_PASSWORD
          value: yourpassword
        - name: MYSQL_USER
          value: wp_user
        - name: MYSQL_PASSWORD
          value: wp_pass
        - name: MYSQL_DATABASE
          value: wp_db
      ports: (6)
        - containerPort: 3306
          name: mysql
      volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql/data
  volumes: (7)
    - name: mysql-persistent-storage
      persistentVolumeClaim:
        claimName: claim-mysql
  1. Pods must have a unique name within their namespace. As a note, a pod definition may specify the basis of a name with the generateName attribute, and random characters will be added automatically to generate a unique name.
  2. Pods can be "tagged" with one or more labels, which can then be used to select and manage groups of pods in a single operation. The labels are stored in key/value format in the metadata hash. In the example, our pod is simply labeled as mysql.
  3. containers specifies an array of container definitions.
  4. Environment variables (env:) can be specified to pass necessary values to each container.
  5. Each container in the pod is instantiated from its own Docker-formatted container image.
  6. The container can bind to ports which will be made available on the pod’s IP.
  7. The pod defines storage volumes that are available to its container(s) to use. In this case, it provides an PersistentVolume named mysql-persistent-storage, with a specific mountPath: in the container on /var/lib/mysql/data


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More