OpenShift Concepts TODEPLETE: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(608 intermediate revisions by the same user not shown)
Line 1: Line 1:
=DEPLETE TO=
{{Internal|OpenShift Concepts|OpenShift Concepts}}
=External=
=External=


Line 4: Line 7:


=Internal=
=Internal=
 
* [[OpenShift]]
* [[OpenShift#Subject|OpenShift]]
* [[Kubernetes]]
* [[Kubernetes]]
* [[Docker]]
* [[Docker]]
=Overview=
The OpenShift is a [[Software_Development#Platform-as-a-Service_.28PaaS.29|Platform-as-a-Service (PaaS)]] based on industry standards. It provides development environments on demand. It is a polyglot offering, including a range of languages, frameworks, runtimes and databases. It automates management of the entire application life cycle: build, deploy and retire. It enables collaboration between developers on projects.
OpenShift is PaaS by RedHat: an enterprise-grade, secure, multi-language, auto-scaling, self-service, elastic could application platform, automated with CI/CD and built on Red Hat technologies.
OpenShift is supported anywhere RHEL is: bare metal, virtualized infrastructure (Red Hat Virtualization, vSphere, Hyper-V), OpenStack platform, public cloud providers (Amazon, Google, Azure). It runs on RHEL and Red Hat Atomic.
OpenShift extends [[Kubernetes Concepts#Overview|Kubernetes]] to provide a more feature rich development lifecycle platform.
[[Image:OpenShiftArchitecture.png]]


=OpenShift Workflow=
=OpenShift Workflow=


Users or automation make calls to the [[#API|REST API]] via the command line, web console or programmatically, to change the state of the system. The master analyses the state changes and acts to bring the state of the system in sync with the desired state. The state is maintained in the [[#Store_Layer|store layer]]. Most OpenShift commands and API calls do not require the corresponding actions to be performed immediately. They usually create or modify a resource description in [[#etcd|etcd]]. etcd then notifies Kubernetes or the OpenShift [[#Controller|controllers]], which notify the resource about the change. Eventually, the system state reflects the change.
Users or automation make calls to the [[#API|REST API]] via the command line, web console or programmatically, to change the state of the system. The master analyses the state changes and acts to bring the state of the system in sync with the desired state. The state is maintained in the [[#Store_Layer|store layer]]. Most OpenShift commands and API calls do not require the corresponding actions to be performed immediately. They usually create or modify a resource description in [[#etcd|etcd]]. etcd then notifies Kubernetes or the OpenShift [[OpenShift_Pod_Concepts#Controller|controllers]], which notify the resource about the change. Eventually, the system state reflects the change.


OpenShift functionality is provided by the interaction of several layers:
OpenShift functionality is provided by the interaction of several layers:
Line 35: Line 25:
* <span id='Replication_Layer'></span>The '''replication layer''' contains the [[#Replication_Controller|replication controller]], whose role is to ensure that the number of instances and pods defined in the [[#etc|store layer]] actually exists.
* <span id='Replication_Layer'></span>The '''replication layer''' contains the [[#Replication_Controller|replication controller]], whose role is to ensure that the number of instances and pods defined in the [[#etc|store layer]] actually exists.


=Component Types=
=<span id='OpenShift_Component_Types'></span><span id='Component_Types'></span>Objects=
 
==Core Objects==
 
Defined by Kubernetes, and also used by OpenShift. All these objects have an API type, which is listed below.
 
* [[OpenShift_Concepts#Project|Projects]] ([[Oc_get#project|oc get project]]), defined by <tt>[[OpenShift_Project_Definition|Project]]</tt>.
* [[OpenShift_Concepts#Pod|Pods]] ([[Oc_get#pod.2C_pods.2C_po|oc get pods]]) defined by <tt>[[OpenShift_Pod_Definition|Pod]]</tt>.
* [[OpenShift_Concepts#Node|Nodes]] ([[Oc_get#node.2C_nodes|oc get nodes]]) defined by <tt>[[OpenShift_Node_Definition|Node]]</tt>.
* [[OpenShift_Concepts#DeploymentConfig|Deployment Configurations]] ([[Oc_get#dc|oc get dc]]) defined by  <tt>[[OpenShift DeploymentConfig Definition#Overview|DeploymentConfig]]</tt>.
* [[OpenShift_Concepts#Service|Services]] ([[Oc_get#services.2C_svc|oc get svc]]) defined by <tt>[[OpenShift Service Definition#Overview|Service]]</tt>.
* [[OpenShift_Concepts#Route|Routes]] ([[Oc_get#routes.2C_routes|oc get route]]) defined by <tt>[[OpenShift Route Definition#Overview|Route]]</tt>.
* [[OpenShift_Concepts#Replication_Controller|Replication Controllers]] ([[Oc_get#rc|oc get rc]]) defined by <tt>[[OpenShift ReplicationController Definition#Overview|ReplicationController]]</tt>.
* [[OpenShift_Security_Concepts#Secret|Secrets]] ([[Oc_get#secret|oc get secret]]) defined by <tt>[[OpenShift Secret Definition|Secret]]</tt>.
* [[OpenShift_Concepts#DaemonSet|Daemon Sets]].
 
==OpenShift Objects==
 
Defined by OpenShift, outside Kubernetes. These objects also have an API type, which is listed below.
 
* [[OpenShift_Concepts#Image|Images]] defined by <tt>[[OpenShift_Image_Definition#Overview|Image]]</tt>.
* [[#Image_Stream|Image Streams]] ([[Oc_get#is|oc get is]]) defined by <tt>[[OpenShift Image Stream Definition#Overview|ImageStream]]</tt>.
* [[OpenShift_Concepts#Image_Stream_Tag|Image Stream Tags]] ([[Oc_get#istag|oc get istag]]).
* [[OpenShift_Concepts#Build|Builds]] ([[Oc_get#build.2C_builds|oc get build]]).
* [[OpenShift_Concepts#Build_Configuration|Build Configurations]] ([[Oc_get#bc|oc get bc]]) defined by <tt>[[OpenShift Build Configuration Definition#Overview|BuildConfig]]</tt>.
* [[#Template|Templates]] defined by <tt>[[OpenShift Template Definition|Template]]</tt>.
* [[OpenShift_Security_Concepts#OAuthClient|OAuthClient]].
 
==Other Objects that do not have an API Representation==


{{Internal|Oc types#OpenShift_Component_Types|OpenShift Component Types}}
* [[OpenShift_Concepts#Container|Containers]]
* [[OpenShift_Concepts#Label|Labels]]
* [[OpenShift_Concepts#Volume|Volumes]]


=OpenShift Hosts=
=OpenShift Hosts=
Line 64: Line 84:


====The native HA Method====
====The native HA Method====
===Master API===
The master API is available internally (inside the OpenShift cluster) at https://openshift.default.svc.cluster.local This value is available internally to pods as the KUBERNETES_SERVICE_HOST environment variable.


==Node==
==Node==
Line 98: Line 122:
A container is a kernel-provided mechanism to run one or more processes, in a portable manner, in a Linux environment. Containers are isolated from each other on a host and are initialized from [[#Image|images]]. All application instances - based on various languages/frameworks/runtimes - as well as databases, run inside containers on [[#Node|nodes]]. For more details, see {{Internal|Docker_Concepts#Container|Docker Containers}}
A container is a kernel-provided mechanism to run one or more processes, in a portable manner, in a Linux environment. Containers are isolated from each other on a host and are initialized from [[#Image|images]]. All application instances - based on various languages/frameworks/runtimes - as well as databases, run inside containers on [[#Node|nodes]]. For more details, see {{Internal|Docker_Concepts#Container|Docker Containers}}


A [[#Pod|pod]] can have application containers and [[#Init_Container|init containers]].
A [[#Pod|pod]] can have application containers and [[OpenShift_Init_Container#Overview|init containers]].


In OpenShift, containers are never restarted. Instead, new containers are spun up to replace old containers when needed. Because of this behavior, [[OpenShift_Concepts#Persistent_Volume|persistent storage volumes]] mounted on containers are critical for maintaining state such as for configuration files and data files.
In OpenShift, containers are never restarted. Instead, new containers are spun up to replace old containers when needed. Because of this behavior, [[OpenShift_Concepts#Persistent_Volume|persistent storage volumes]] mounted on containers are critical for maintaining state such as for configuration files and data files.
==Init Container==
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#init-containers}}


=Docker Support in OpenShift=
=Docker Support in OpenShift=
Line 112: Line 132:
==Docker Storage in OpenShift==
==Docker Storage in OpenShift==


Each Docker server requires Docker storage, which is allocated on each node in a space specially provisioned as [[Docker_Concepts#Storage_Backend|Docker storage backend]]. The Docker storage is ephemeral and separate from [[#Storage|OpenShift storage]]. The [[Docker_Concepts#Loopback_Storage|default loopback storage]] back end for Docker is a [[Linux Logical Volume Management Concepts#thin_pool|thin pool]] on loopback devices, which is not appropriate for production.
Each Docker server requires Docker storage, which is allocated on each node in a space specially provisioned as [[Docker_Concepts#Storage_Backend|Docker storage backend]]. The Docker storage is ephemeral and separate from [[OpenShift_Volume_Concepts#The_Volume_Mechanism|OpenShift storage]]. The [[Docker_Concepts#Loopback_Storage|default loopback storage]] back end for Docker is a [[Linux Logical Volume Management Concepts#thin_pool|thin pool]] on loopback devices, which is not appropriate for production.


=The node Daemon=
As per OCP 3.7, Docker storage ca be backed by one of two options (storage drivers): a [[Docker Concepts#devicemapper-storage-driver|devicemapper]] thin pool logical volume  and an [[Docker Concepts#overlayfs-storage-driver|overlay2]] filesystem (recommended). More details about how Docker storage is configured on a specific system can be obtained from:


=Pod=
cat /etc/sysconfig/docker-storage
DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper --storage-opt dm.fs=xfs --storage-opt dm.thinpooldev=/dev/mapper/docker_vg-container--thinpool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true"


A pod is a set of one or more [[Docker Concepts#Container|containers]], deployed together onto a [[#Node|node]], as a single unit.
and also


The defining characteristic of a pod is that all its containers share a virtual network device - an unique IP -, and a set of [[#Persistent_Volume|persistent volumes]]. Pods also define the security and runtime policy for each container.
docker info


The "pod" is a Kubernetes concept, for more details, see [[Kubernetes Concepts#Pod|Kubernetes Pods]]. Each pod gets a [[#Pod_IP_Address|pod IP address]] that is routable by default from any other pod in the environment. The default addresses are part of the 10.x.x.x set. The containers on a pod share the IP address and TCP ports, because they share the pod's virtual network device. They also share persistent storage [[#Volume|volumes]], and other resources allocated to the pod. The pod contains collocated applications that are relatively tightly coupled and run with a ''shared context''. Within that context, an application may have individual [[Linux cgroups|cgroups]] isolation applied. A pod models an application-specific ''logical host'', containing applications that in a pre-container world would have run on the same physical or virtual host, and in consequence, the pod cannot span hosts. The pod is the ''smallest unit'' that can be defined, deployed and managed by OpenShift. Complex applications can be made of any number of pods, and OpenShift helps with pod orchestration. Pods do not maintain state, they are expendable.
=The node Daemon=
 
Pods must not created or managed directly, but by their [[#Controller|controllers]], which are specified in the pod description.
 
OpenShift treats pods as largely immutable - changes cannot be made to a pod definition while the pod is running - and expendable, they do not maintain state when they are destroyed and recreated. Therefore, they are managed by controllers, not directly by users.
 
The pods for a project are displayed by the following commands:
[[oc get#all|oc get all]]
[[Oc_get#pods.2C_po|oc get pods]]


Pods for a project can also be viewed in the web console to the project -> Applications -> Pods.
=<span id='Controller'></span><span id='Pod_Configuration'></span><span id='Pod_Lifecycle'></span><span id='Terminal_State'></span><span id='Pod_Definition'></span><span id='Pod_Name'></span><span id='Pod_Definition_File'></span><span id='Pod_Placement'></span><span id='Pod_Probe'></span><span id='Liveness_Probe'></span><span id='Readiness_Probe'></span><span id='Local_Manifest_Pod'></span><span id='Bare_Pod'></span><span id='Static_Pod'></span><span id='Pod_Type'></span><span id='Terminating'></span><span id='NonTerminating'></span><span id='Pod_Presets'></span><span id='Init_Container'>Pod=


==Controller==
Contains: controller, pod configuration, pod lifecycle, terminal state, pod definition, pod name, pod placement, pod probe, liveness probe, readiness probe, local manifest pod, bare pod, static pod, pod type, terminating, nonterminating, pod presents, init container.
 
A controller is the OpenShift component that creates and manages [[#Pod|pods]]. The controller of a pod is reported by [[oc describe#pod|oc describe pod]] command, under the "Controllers" section:
 
...
Controllers: ReplicationController/logging-kibana-1
...
 
The most common controllers are:
* [[#Replication_Controller|Replication Controllers]]
* [[#DaemonSet|DaemonSets]]
 
==Pod Configuration==
 
Pods are treated as ''static'', and cannot be changed while they are running. To change a pod, the current pod must be terminated, and a new one with a modified base image and/or configuration must be created.
 
==Pod Lifecycle==
 
* A pod is defined in a [[#Pod_Definition|pod definition]].
* A pod is instantiated and assigned to run on a node as a result of the [[#Scheduler|scheduling process]].
* The pod runs until its containers exit or the pod is removed.
* Depending on policy and exit code, may be removed or retained to enable access to their container's logs.
 
==Pod Definition==
 
The definition of an already existing pod can be obtained with [[oc describe#pod|oc describe pod]].
 
===Pod Name===
 
Pod must have an unique name in their namespace (project). The pod definition can specify a base name and use "generateName" attribute to append random characters at the end of the base name, thus generating an unique name.
 
===Pod Definition File===
 
{{Internal|Pod Definition File|Pod Definition File}}
 
==Pod Placement==
 
{{External|https://docs.openshift.com/container-platform/3.5/admin_guide/scheduler.html#controlling-pod-placement}}
 
Pods can be configured to execute on a specific node, defined by the node name, or on nodes that match a specific [[#Node_Selector|node selector]].
 
To assign a pod to a ''specific node'', <font color=red>TODO https://docs.openshift.com/container-platform/3.5/admin_guide/scheduler.html#constraining-pod-placement-labels</font>
 
To assign a pod to ''nodes that match a node selector'', add the "nodeSelector" element in the pod configuration, with a value consisting in key/value pairs, as described here:
 
{{Internal|OpenShift_Deployment_Operations#Assigning_a_Pod_to_Nodes_that_Match_a_Node_Selector|Assigning a Pod to Nodes that Match a Node Selector}}
 
After a successful placement, either by a replication controller or by a DaemonSet, the pod <span id='successful_node_selector_recorded'></span>records the successful node selector expression as part of its definition, which can be rendered with oc get pod -o yaml:
 
spec:
  ...
  nodeSelector:
    logging: "true"
  ...
 
 
<font color=red>Consolidate with [[OpenShift_Concepts#Node_Selector]]</font>
 
==Pod Probe==
 
Users can configure ''pod probes'' for liveness or readiness.


=Label=
=Label=
Line 291: Line 245:
# Via replacement with a different implementation.
# Via replacement with a different implementation.


The pod placement process is described here: {{Internal|#Pod_Placement|Pod Placement}}
The pod placement process is described here: {{Internal|OpenShift_Pod_Concepts#Pod_Placement|Pod Placement}}


==Default Scheduler Implementation==
==Default Scheduler Implementation==
Line 314: Line 268:
===Configurable Predicates===
===Configurable Predicates===


* ServiceAffinity - filters out nodes that do not belong to the topological level defined by the provided labels.  
====ServiceAffinity====
* LabelsPresence - checks whether the node has certain labels defined, regardless of value.
 
ServiceAffinity filters out nodes that do not belong to the topological level defined by the provided labels. See [[/etc/origin/master/scheduler.json#serviceAffinity|scheduler.json]]
 
====LabelsPresence====
 
LabelsPresence checks whether the node has certain labels defined, regardless of value.


==Priority Functions==
==Priority Functions==
Line 339: Line 298:
The default scheduler policy is configured in the master configuration file [[master-config.yml]] as [[Master-config.yml#schedulerConfigFile|kubernetesMasterConfig.schedulerConfigFile]], which by default points to [[/etc/origin/master/scheduler.json]]. Another example of scheduler policy file: {{Internal|Scheduler Policy File|Scheduler Policy File}}
The default scheduler policy is configured in the master configuration file [[master-config.yml]] as [[Master-config.yml#schedulerConfigFile|kubernetesMasterConfig.schedulerConfigFile]], which by default points to [[/etc/origin/master/scheduler.json]]. Another example of scheduler policy file: {{Internal|Scheduler Policy File|Scheduler Policy File}}


=Storage=
=<span id='Storage'></span><span id='Volume'></span><span id='Persistent_Volume'></span><span id='Persistent_Volume_Claim'></span><span id='EmptyDir'></span><span id='Temporary_Pod_Volume'></span>Volumes=
 
{{External|https://docs.openshift.com/container-platform/latest/dev_guide/persistent_volumes.html|}}
 
{{External|https://docs.openshift.com/container-platform/latest/architecture/additional_concepts/storage.html#persistent-volumes}}
 
==Volume==
 
Volumes are mounted filesystems available to [[#Pod|pods]] and their [[#Container|containers]]. Volumes may be backed by a number of host-local or network attached storage endpoints. The simplest volume type is EmptyDir, which is a temporary directory on a single machine. Administrators may also allow to request and attach [[#Persistent_Volume|Persistent Volumes]].
 
===Persistent Volume===
 
{{Internal|Kubernetes Concepts#Persistent_Volume|Kubernetes Persistent Volume}}
 
The persistent volumes and persistent volume claims can be listed with [[oc get#pv|oc get pv]] and [[oc get#pvc|oc get pvc]].
 
{{Internal|OpenShift_PersistentVolume_Operations#Persistent_Volume_Operations|Persistent Volume Operations}}
 
====Persistent Volume Definition File====
 
{{Internal|Persistent Volume Definition File|Persistent Volume Definition File}}
 
===Persistent Volume Claim===
 
A ''persistent volume claim'' is a request for a persistence resource with specific attributes, such as storage size. Persistent volume claims are matched to available volumes and ''binds'' them together. This process allows a claim to be used as a volume in a pod: OpenShift finds the volume backing the claim and mounts it into the pod. Persistent volume claims are project-specific objects. All persistent volume claims for the current project can be listed with:
 
[[OpenShift_PersistentVolume_Operations#List_Existent_Persistent_Volume_Claims_for_the_Current_Project|oc get pvc]]
 
{{Internal|OpenShift_PersistentVolume_Operations#Persistent_Volume_Claim_Operations|Persistent Volume Claim Operations}}
 
====Persistent Volume Claim Definition File====
 
{{Internal|Persistent Volume Claim Definition File|Persistent Volume Claim Definition File}}
 
==Temporary Pod Volume==
 
{{External|https://docs.openshift.com/container-platform/latest/dev_guide/volumes.html#dev-guide-volumes}}


When temporary pod volumes are used, the data is written to /var/lib/origin/openshift.local.volumes/pods on the node where the pod is running.
Persistent Volumes, Persistent Volume Claims, EmptyDirs, ConfigMaps, Downward API, Host Paths, Secrets: {{Internal|OpenShift Volume Concepts|Volumes}}


=etcd=
=etcd=
Line 398: Line 321:
==Integrated Docker Registry==
==Integrated Docker Registry==


OpenShift contains an integrated [[Docker_Concepts#Image_Registry|Docker image registry]], providing authentication and access control to images. The integrated registry should not be confused with the OpenShift Container Registry (OCR), which is a standalone solution, which can be used outside of an OpenShift environment. The integrated registry is installed as part of the cluster installation process. The integrated registry is the default location where users can push images they build. Users push images into registry and whenever a new image is stored in the registry, the registry notifies OpenShift about it and passes along image information such as the [[#Namespace|namespace]], the name and the image metadata. Various OpenShift components reacts by creating new builds and deployments. Third party image registry providers (http://dockerhub.com, or RedHat's own http://registry.access.redhat.com) can also be integrated. In general, any server implementing Docker registry API can be integrated.
OpenShift contains an integrated [[Docker_Concepts#Image_Registry|Docker image registry]], providing authentication and access control to images. The integrated registry should not be confused with the OpenShift Container Registry (OCR), which is a standalone solution, which can be used outside of an OpenShift environment. The integrated registry is an application deployed within the "[[#Default_Project|default]]" project as a  [[Docker_Concepts#Privileged_Container|privileged container]], as part of the cluster installation process. The integrated registry is available internally in the OpenShift cluster at the following [[#The_Service_IP_Address|Service IP]]: docker-registry.default.svc:5000/. It consists of a a "docker-registry" [[#Service|service]], a "docker-registry" [[#DeploymentConfig|deployment configuration]], a "registry" [[OpenShift_Security_Concepts#Service_Account|service account]] and a role binding that associates the service account  to the "system:registry" cluster role. [[OpenShift Registry Definition|More details]] on the structure of the integrated registry can be generated with [[oadm registry|oadm registry -o yaml]]. The default registry also comes with a [[#The_Registry_Console|registry console]] that can be used to browse images.


The integrated registry is an application deployed within a project; it is deployed as [[Docker_Concepts#Privileged_Container|privileged container]] (referred to as an ''infrastructure container''). The default integrated registry is deployed as part of the "[[OpenShift_Concepts#Default_Project|default]]" project. It consists of a a "docker-registry" [[#Service|service]], a "docker-registry" [[#DeploymentConfig|deployment configuration]], a "registry" [[OpenShift_Security_Concepts#Service_Account|service account]] and a role binding that associates the service account  to the "system:registry" cluster role. This is the [[OpenShift Registry Definition|registry's definition]] generated with <tt>oadm registry -o yaml</tt>.
The main function of the integrated registry is to provide a default location where users can push images they build. Users push images into registry and whenever a new image is stored in the registry, the registry notifies OpenShift about it and passes along image information such as the [[#Namespace|namespace]], the name and the image metadata. Various OpenShift components react by creating new builds and deployments.  
 
Alternatively, the integrated registry may store and expose to projects external images the projects may need. The docker servers on OpenShift nodes are configured to be able to access the internal registry, but they are also configured with [[#registry.access.redhat.com|registry.access.redhat.com]] and [[#docker.io|docker.io]].
 
Multiple running instances of the container registry require backend storage supporting writes by multiple processes. If the chosen infrastructure provider does not contain this ability, running a single instance of a container registry is acceptable.


<font color=red>
<font color=red>
'''Questions'''':
'''Questions''':
* How can I "instruct" an application to use a specific registry.  a “lab” application to use registry-lab
* How can I "instruct" an application to use a specific registry.  a “lab” application to use registry-lab
* How do pods that need images go to that registry and not other? The answer to this question lays in the way an application uses the registry.  
* How do pods that need images go to that registry and not other? The answer to this question lays in the way an application uses the registry.  
</font>
</font>


The default registry comes with a [[#The_Registry_Console|registry console]].
==External Registries==


===The Registry Console===
The external registries [[#registry.access.redhat.com|registry.access.redhat.com]] and [[#docker.io|docker.io]] are accessible. In general, any server implementing Docker registry API can be integrated as a [[#Stand-alone_Registry|stand-alone registry]].


The registry comes with a "registry console" that allows web-based access to the registry. An URL example is https://registry-console-default.apps.openshift.novaordis.io. The registry console is deployed as a [[OpenShift_Concepts#Default_Project|registry-console]] pod part of the "[[OpenShift_Concepts#Default_Project|default]]" project.
====registry.access.redhat.com====


More details: {{External|https://docs.openshift.com/container-platform/latest/install_config/registry/deploy_registry_existing_clusters.html#registry-console}}
{{Internal|registry.access.redhat.com|registry.access.redhat.com}}


==Stand-alone Registry==
The Red Hat registry is available at http://registry.access.redhat.com. An individual image can be inspected with an URL similar to https://access.redhat.com/containers/#/registry.access.redhat.com/jboss-eap-7/eap70-openshift/images/1.5-23


{{External|https://docs.openshift.com/container-platform/latest/install_config/install/stand_alone_registry.html#install-config-installing-stand-alone-registry}}
====docker.io====


OpenShift comes with an [[#Integrated_Docker_Registry|integrated container registry]]. However, a stand-alone container registry can be installed and used with the OpenShift cluster.
[[Docker Concepts#Docker_Hub|Docker Hub]] is available at http://dockerhub.com.


==Registry Operations==
==Stand-alone Registry==


{{Internal|OpenShift Registry Operations|Registry Operations}}
{{External|https://docs.openshift.com/container-platform/latest/install_config/install/stand_alone_registry.html#install-config-installing-stand-alone-registry}}


=Service=
Any server implementing Docker registry API can be integrated as a standalone registry: a stand-alone container registry can be installed and used with the OpenShift cluster.


A ''service'' represents a group of pods, which may individually come and go, and its primary function is to ''provide the permanent IP, hostname and port for other applications to use''. Each service has a [[#The_Service_IP_Address|service IP address]] and a port, which is allocated from the [[#The_Services_Subnet|services subnet]]. The service IP address is sometimes referred to as the "cluster IP", which is consistent with the abstraction provided by the service: a cluster of pods providing the service. The services constitute the [[#Service_Layer|service layer]].
==<span id=The_Registry_Console'></span>Integrated Registry Console==


The service IP is available internally in the cluster. It is not routable (in the IP sense) externally. The service can be exposed externally via a [[#Route|route]].
{{External|https://docs.openshift.com/container-platform/latest/install_config/registry/deploy_registry_existing_clusters.html#registry-console}}


A ''service resource'' is an abstraction that defines a logical set of pods and a policy that is used to access the pods. The ''service layer'' is how applications communicate with one another. The service is a [[Kubernetes Concepts#Service|Kubernetes concept]]. The service serves as an ''internal'' load balancer: it identifies a set of replicated pods and then proxies the connections it receives to those pods ([[OpenShift_Concepts#Router|routers]] provide external load balancing). The service is not a "thing", but an entry in the configuration. Backing pods can be added or removed to or from the service arbitrarily. This way, anything that depends on the service can refer to it as a consistent IP:port pair. The services uses a label selector to find all the running containers associated with it.
The registry comes with a "registry console" that allows web-based access to the registry. An URL example is https://registry-console-default.apps.openshift.novaordis.io. The registry console is deployed as a [[OpenShift_Concepts#Default_Project|registry-console]] pod part of the "[[OpenShift_Concepts#Default_Project|default]]" project.


Services can be consumed from other pods using the values of the <SERVICE>_HOST environment variables that are injected by the cluster.
==Registry Operations==


Services of a project can be displayed with:
{{Internal|OpenShift Registry Operations|Registry Operations}}
 
[[oc get#all|oc get all]]
[[Oc_get#services.2C_svc|oc get svc]]
 
==Service Endpoint==


An <[[#Pod_IP_Address|pod IP address]]>:<port> pair that corresponds to a process running inside of a container, on a pod, on a node. The service endpoint coordinate can be obtained by executing:
=<span id='Service_Endpoint'></span><span id='Service_Proxy'></span><span id='Service_Dependencies'></span><span id='Relationship_between_Services_and_the_Pods_providing_the_Service'></span><span id='EndpointsController'></span>Service=


oc describe service <''service-name''>
{{Internal|OpenShift Service Concepts|OpenShift Service Concepts}}
 
Name: logging-kibana
...
Endpoints: 10.129.2.17:3000
...
 
=Relationship between Services and the Pods providing the Service=


=API=
=API=
Line 459: Line 374:


=Networking=
=Networking=
In OpenShift, nodes communicate to each over using the infrastructure-provided network. Pods communicate with each other via a software defined network (SDN), also known as the cluster network, which runs in top of that.


==Required Network Ports==
==Required Network Ports==
Line 481: Line 398:


The ''cluster network'' is the network from which pod IPs are assigned. These network blocks should be private and must not conflict with existing network blocks in your infrastructure that pods, nodes or the master may require access to. The default subnet value is 10.128.0.0/14 (10.128.0.0 - 10.131.255.255) and it cannot be arbitrarily reconfigured after deployment. The size and address range of the cluster network, as well as the host subnet size are configurable during installation. Configured with 'osm_cluster_network_cid' at [[OpenShift_3.5_Installation#Configure_Ansible_Inventory_File|installation]].
The ''cluster network'' is the network from which pod IPs are assigned. These network blocks should be private and must not conflict with existing network blocks in your infrastructure that pods, nodes or the master may require access to. The default subnet value is 10.128.0.0/14 (10.128.0.0 - 10.131.255.255) and it cannot be arbitrarily reconfigured after deployment. The size and address range of the cluster network, as well as the host subnet size are configurable during installation. Configured with 'osm_cluster_network_cid' at [[OpenShift_3.5_Installation#Configure_Ansible_Inventory_File|installation]].
Samples of pod addresses can be obtained by querying [[OpenShift_Service_Concepts#Service_Endpoints|service endpoints]] in a project:
oc get endpoints
NAME          ENDPOINTS          AGE
some-service  10.130.1.17:8080  21m


The master maintains a registry of nodes in etcd, and each [[#Node|node]] gets allocated upon creation an unused subnet from the cluster network. Each node gets a /23 subnet, which means the cluster can allocate 512 subnets to nodes, and each node has 510 addresses to assign to containers running on it. Once the node is registered with the master, and gets its cluster network subnet, SDN creates on the node three devices:
The master maintains a registry of nodes in etcd, and each [[#Node|node]] gets allocated upon creation an unused subnet from the cluster network. Each node gets a /23 subnet, which means the cluster can allocate 512 subnets to nodes, and each node has 510 addresses to assign to containers running on it. Once the node is registered with the master, and gets its cluster network subnet, SDN creates on the node three devices:
Line 505: Line 428:
===The Services Subnet===
===The Services Subnet===


OpenShift uses a "services subnet", also known as "kubernetes services network", in which [[#Service|OpenShift Services]] will be created within the [[#SDN|SDN]]. This network block should be private and must not conflict with any existing network blocks in the infrastructure to which pods, nodes, or the master may require access to. It defaults to 172.30.0.0/16. It cannot be re-configured after deployment. If changed from the default, it must not be 172.16.0.0/16, which the docker0 network bridge uses by default, unless the docker0 network is also modified. It is configured with 'openshift_master_portal_net', 'openshift_portal_net' at [[OpenShift_3.5_Installation#Configure_Ansible_Inventory_File|installation]] and populates the master configuration file [[Master-config.yml#servicesSubnet| servicesSubnet]] element. Note that Docker expects its [[/etc/sysconfig/docker#--insecure-registry|insecure registry]] to available on this subnet.
OpenShift uses a "services subnet", also known as "kubernetes services network", in which [[OpenShift Service Concepts#Overview|OpenShift Services]] will be created within the [[#SDN|SDN]]. This network block should be private and must not conflict with any existing network blocks in the infrastructure to which pods, nodes, or the master may require access to. It defaults to 172.30.0.0/16. It cannot be re-configured after deployment. If changed from the default, it must not be 172.16.0.0/16, which the docker0 network bridge uses by default, unless the docker0 network is also modified. It is configured with 'openshift_master_portal_net', 'openshift_portal_net' at [[OpenShift_3.5_Installation#Configure_Ansible_Inventory_File|installation]] and populates the master configuration file [[Master-config.yml#servicesSubnet| servicesSubnet]] element. Note that Docker expects its [[Docker_Server_Configuration#--insecure-registry|insecure registry]] to available on this subnet.


The services subnet IP address of a specific service can be displayed with:
The services subnet IP address of a specific service can be displayed with:
Line 656: Line 579:


The secure routes specify the TLS termination of the route, which relies on SNI (Server Name Indication). More specifically, they can be:
The secure routes specify the TLS termination of the route, which relies on SNI (Server Name Indication). More specifically, they can be:
* <span id="edge_secured_route"></span>edge secured (or edge terminated). Occurs at the router, prior to proxying the traffic to the destination. The  front end of the router serves the TLS certificates, so they must be configured in the route. If the certificates are not configured in the route, the default certificate of the router is used. Connection from the router into the internal network are not encrypted. This is an [[Route_Definition_File#Secured_Edge-Terminated_Route|example of edge-termintated route]].
* <span id="edge_secured_route"></span>edge secured (or edge terminated). Occurs at the router, prior to proxying the traffic to the destination. The  front end of the router serves the TLS certificates, so they must be configured in the route. If the certificates are not configured in the route, the default certificate of the router is used. Connection from the router into the internal network are not encrypted. This is an [[OpenShift_Route_Definition#Secured_Edge-Terminated_Route|example of edge-termintated route]].
* <span id="passthrough_secured_route"></span>passthrough secured (or passthrough terminated). The encrypted traffic is send to to destination, the router does not provide TLS termination, hence no keys or certificates are required on the router. The destination will handle certificates. This method supports client certificates. This is an [[Route_Definition_File#Passthrough-Terminated_Route|example of passthrough-termintated route]].
* <span id="passthrough_secured_route"></span>passthrough secured (or passthrough terminated). The encrypted traffic is send to to destination, the router does not provide TLS termination, hence no keys or certificates are required on the router. The destination will handle certificates. This method supports client certificates. This is an [[OpenShift_Route_Definition#Passthrough-Terminated_Route|example of passthrough-termintated route]].
* <span id="re-encryption_terminated_secured_route"></span>re-encryption terminated secured. This is an [[Route_Definition_File#Re-encryption-Terminated_Route|example of re-encyrption-termintated route]].
* <span id="re-encryption_terminated_secured_route"></span>re-encryption terminated secured. This is an [[OpenShift_Route_Definition#Re-encryption-Terminated_Route|example of re-encyrption-termintated route]].
 
{{Internal|OpenShift Route Definition|Route Definition}}


Routes can be displayed with the following commands:
Routes can be displayed with the following commands:
Line 664: Line 589:
  [[oc get#routes|oc get routes]]
  [[oc get#routes|oc get routes]]


Routes can be created with API calls, an JSON or [[Route Definition File|YAML object definition file]] or the [[oc expose#service|oc expose service]] command.
Routes can be created with API calls, an JSON or [[OpenShift Route Definition|YAML object definition file]] or the [[oc expose#service|oc expose service]] command.


===Path-Based Route===
===Path-Based Route===
Line 676: Line 601:
===Default Routing Subdomain===
===Default Routing Subdomain===


The suffix and the default routing subdomain can be configured in the [[OpenShift_Master_Configuration_File#subdomain|master configuration file]].
The suffix and the default routing subdomain can be configured in the [[Master-config.yml#subdomain|master configuration file]].
 
===Route Definition File===
 
{{Internal|Route Definition File|Route Definition File}}


===Route Operations===
===Route Operations===


{{Internal|OpenShift_Network_Operations#Route_Operations|Route Operations}}
{{Internal|OpenShift Route Operations|Route Operations}}


==Networking Workflow==
==Networking Workflow==
Line 705: Line 626:
* services
* services
* [[OpenShift_Security_Concepts#Secret|Secrets]]
* [[OpenShift_Security_Concepts#Secret|Secrets]]
* [[#ConfigMaps|configmaps]]
* [[OpenShift_Volume_Concepts#ConfigMap|configmaps]]
* persistentvolumeclaims
* persistentvolumeclaims
* openshif.io/imagestreams
* openshif.io/imagestreams


Most resources can be defined in JSON or YAML files, or via an API call.
Most resources can be defined in JSON or YAML files, or via an API call. Resources can be exposed via the [[OpenShift_Volume_Concepts#Downward_API|downward API]] to the container.


==Resource Quota==
=<span id='Resource_Quotas'></span>Resource Management=


<tt>ResourceQuota</tt> object enumerates hard resource usage limits ''per project''.
{{Internal|OpenShift Resource Management Concepts|Resource Management}}
 
<tt>ClusterResourceQuota</tt> object enumerates hard resource usage limits across the cluster.
 
After a quota is first declared on a project, the system restricts the ability to create new resources that may exceed the quota until usage statistics are calculated. If the resource creation request exceeds the quota, the server will deny the action and will return an error message.
 
When a resource is created, the quota usage is updated immediately. When a resource is delete, the quota usage is updated during the next full per-project statistics update.
 
{{Internal|Resource Quota Definition File|Resource Quota Definition File}}
 
Operations:
* [[Oc_get#quota|oc get quota]]
* [[Oc_describe#quota|oc describe quota]]
* [[Oc_create#Creating_a_Resource_Quota|oc create]]


=Project=
=Project=
Line 738: Line 646:
* [[#Node|nodes]]
* [[#Node|nodes]]
* [[#Persistent_Volume|persistent volumes]]
* [[#Persistent_Volume|persistent volumes]]
* [[#Images|images]]
More details about OpenShift types are available here [[oc types|OpenShift types]].


Each project has its own set of <span id='Objects'>''objects''</span>: [[#Pod|pods]], [[#Service|services]], [[#Replication_Controller|replication controllers]], etc. The names of each resource are unique within a project. Developers may request projects to be create, but administrators control the resources allocated to the projects.
Each project has its own set of <span id='Objects'>''objects''</span>: [[#Pod|pods]], [[#Service|services]], [[#Replication_Controller|replication controllers]], etc. The names of each resource are unique within a project. Developers may request projects to be create, but administrators control the resources allocated to the projects.
Line 751: Line 662:
==Current Project==
==Current Project==


The ''current project'' is a concept that applies to [[Oc#Namespace_Selection|oc]], and specifies the project oc commands apply to, without to explicitly having to use the -n <project-name> qualifier. The current project can be set with [[Oc_project|oc project]] and read with [[oc status]]. The current project is part of the CLI tool's [[OpenShift_Command_Line_Tools#Context|current context]], maintained in user's [[.kube/config]].
The ''current project'' is a concept that applies to [[Oc#Namespace_Selection|oc]], and specifies the project oc commands apply to, without to explicitly having to use the -n <project-name> qualifier. The current project can be set with [[Oc_project|oc project]] and read with [[oc status]]. The current project is part of the CLI tool's [[OpenShift_Command_Line_Tools#Context|current context]], maintained in user's [[.kube config|.kube/config]].


==Global Project==
==Global Project==
Line 792: Line 703:
==="openshift" Project===
==="openshift" Project===


Contains [[#Template|templates]].
Contains standard [[#Template|templates]] and [[#.22openshift.22_Image_Streams|image streams]]. Images to use with OpenShift projects can be installed during the [[OpenShift_3.6_Installation#Load_Default_Image_Streams_and_Templates|OpenShift installation phase]], or they can be added later running command similar to:
oc -n openshift [[OpenShift_Image_and_ImageStream_Operations#Create_an_Individual_Image_Stream_with_import-image|import-image]] jboss-eap64-openshift:1.6


===Other Standard Projects===
===Other Standard Projects===
Line 798: Line 710:
* "kube-system"
* "kube-system"
* "management-infra"
* "management-infra"
==Projects and Applications==
Each project may have multiple applications, and each application can be managed individually.
A new application is created with:
[[oc new-app]]
===The "app" Label===
<font color=red>
'''TODO''': app vs. application
There is no OpenShift object that represent an applications. However, the pods belonging to a specific application are grouped together in the Web console project window, under the same "Application" logical category. The grouping is done based on the "app" label value: all pods with the same "app" label value are represented as belonging to the same "application". The "app" label value can be explicitly set in the template that is used to instantiate the application with, [[OpenShift_Template_Definition#Labels|in the "labels:" section]]. Some templates [[OpenShift_Build_and_Deploy_a_JEE_Application_with_S2I#Create_the_Application|expose this as parameter]], so it can be set on command line with a syntax similar to:
--param APPLICATION_NAME=<''application-name''>
</font>
===Application Operations===
{{Internal|OpenShift_Application_Operations#Overview|Application Operations}}


==Project Operations==
==Project Operations==
Line 815: Line 748:
The objects define in a template collectively define a ''desired state''. OpenShift's responsibility is to make sure that the current state matches the desired state.
The objects define in a template collectively define a ''desired state''. OpenShift's responsibility is to make sure that the current state matches the desired state.


{{Internal|Template Quota Definition File|Template Definition File}}
{{Internal|OpenShift Template Definition|Template Definition}}


Specifying parameters in a template allows all objects instantiated by the template to see consistent values for these parameters when the template is processed. The parameters can be specified explicitly, or generated automatically.
Specifying parameters in a template allows all objects instantiated by the template to see consistent values for these parameters when the template is processed. The parameters can be specified explicitly, or generated automatically.


The configuration can be generated from template with [[oc process]] command.
The configuration can be generated from template with [[oc process]] command.
Most templates use pre-built S2I builder images, that includes the programming language runtime and its dependencies. These builder images can also be used by themselves, without the corresponding template, for simple use cases.


==New Project Template==
==New Project Template==
Line 826: Line 761:


  oadm create-bootstrap-project-template -o yaml
  oadm create-bootstrap-project-template -o yaml
==New Application Template==
[[oc new-app]] ''<template-name>''


==Template Libraries==
==Template Libraries==
Line 838: Line 777:
{{Internal|OpenShift Template Operations|Template Operations}}
{{Internal|OpenShift Template Operations|Template Operations}}


=CICD Support=
=Build=
 
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html}}
 
A ''build'' is the process of transforming input parameters into a resulting object. In most cases, that means transforming source code, other images, Dockerfiles, etc. into a ''runnable image''. A build is run inside of a  [[Docker_Concepts#Privileged_Container|privileged container]] and has the same restrictions normal pods have. A build usually results in an image pushed to a Docker registry, subject to post-build tests. Builds are run with the builder [[OpenShift_Security_Concepts#Service_Account|service account]], which must have access to any secrets it needs, such as repository credentials - in addition to the builder service account having to have access to the build secrets, the [[#Build_Configuration|build configuration]] must [[OpenShift_Concepts#Build_Configuration_and_Build_Secrets|contain the required build secret]]. Builds can be [[#Build_Trigger|triggered]] manually or automatically.
 
OpenShift supports several types of builds. The type of build is also referred to as the [[#Build_Strategy|build strategy]]:
* [[#Docker_Build|Docker build]]
* [[#Source-to-Image_.28S2I.29_Build|Source-to-Image (S2I or source) build]]
* [[#Pipeline_Build|Pipeline build]]
* [[#Custom_Build|Custom build]]
 
Builds for a project can be reviewed by navigating with the web console to the project -> Builds -> Builds or invoking [[Oc_get#build.2C_builds|oc get builds]] from command line. Note these are actual executed builds, not build configurations.
 
==Build Strategy==
 
===Docker Build===
 
Docker can be used to build [[Docker Concepts#Container_Image|images]] directly. The Docker build expects a repository with [[Dockerfile]] and all artifacts required to produce runnable image. It invokes the [[docker build]] command, and the result is a runnable image.
 
{{Internal|OpenShift_Build_Operations#Docker_Build|Create a Docker Build}}
 
===Source-to-Image (S2I) Build===
 
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html#source-build}}
 
{{External|https://docs.openshift.com/container-platform/latest/creating_images/s2i.html#creating-images-s2i}}
 
A ''source to image build strategy'' is a process that takes a base image, called the [[#Builder_Image|builder image]], application source code and [[#S2I_Scripts|S2I scripts]], compiles the source and injects the build artifacts into the builder image, producing a ready-to-run new Docker image, which is the end product of the build. The image is then pushed into the [[#Integrated_Docker_Registry|integrated Docker registry]].


OpenShift enables [[Software Development#DevOps|DevOps]]. It has built-in support for the [[Jenkins and OpenShift|Jenkins CI server]], providing a native way of doing [[Software Development#CICD|CICD]].
The essential characteristic of the source build is that the [[#Builder_Image|builder image]] provides both the build environment and the runtime image in which the build artifact is supposed to run in. The build logic is encapsulated within the [[#S2I_Scripts|S2I scripts]]. The S2I scripts usually come with builder image, but they can also be overridden by scripts placed in the source code or in different location, specified in the build configuration. OpenShift supports a wide variety of languages and base images: Java, PHP, Ruby, Python, Node.js. [[#Incremental_Build|Incremental builds]] are supported. With a source build, the assemble process performs a large number of complex operations without creating a new layer at each step, resulting in a compact final image.  


OpenShift can integrate with Git-based source code repositories. When a developer pushes code to the GIt repository, Jenkins pulls the code and performs a project build. After the build is complete, Jenkins invokes the OpenShift master node API to initiate a [[#Source-to-Image_.28S2I.29_Build|"source-to-image" (S2I) build]]. As part of the SI process, the latest project artifact is downloaded from Jenkins and included in the image that runs in the OpenShift node.
The source strategy is specified in the [[#Build_Configuration|build configuration]] as follows:


More details: {{Internal|Jenkins and OpenShift|Jenkins and OpenShift}}
kind: BuildConfig
spec:
  '''strategy''':
      '''type''': <font color=teal>'''Source'''</font>
      <font color=teal>'''sourceStrategy'''</font>:
        '''from''':
          kind: ImageStreamTag
          name: jboss-eap70-openshift:1.5
          namespace: openshift
  '''source''':
    '''type''': Git
    '''git''':
      uri: ...
  '''output''':
    '''to''':
      kind: '''ImageStreamTag'''
      name: <''app-image-repository-name''>:latest
The [[#Builder_Image|builder image]] is specified with a 'spec.strategy.sourceStrategy.from' element. Source code origin is specified with 'spec.strategy.source' element. Assuming that the build is successful, the resulted image is pushed into the <font color=red>?</font> image stream and tagged with the 'output' image stream tag.


{{Internal|OpenShift CI/CD Operations|OpenShift CI/CD Operations}}
A working S2I Build Example is available here: {{Internal|OpenShift Build and Deploy a JEE Application with S2I|OpenShift Build and Deploy a JEE Application with S2I}}
 
An example to create a source build configuration from scratch is available here: {{Internal|OpenShift_Build_Operations#Source_Build|Create a Source Build}}
 
====The Build Process====
 
For a source build, the build process takes place in the [[#Builder_Image|builder image]] container. It consists in the following steps:
* Download the [[#S2I_Scripts|S2I scripts]].
* If it is an [[#Incremental_Build|incremental build]], save the previous build's artifacts with [[#save-artifacts|save-artifacts]].
* A work directory is created.
* Pull the source code from the repository into the work directory.
* Heuristics is applied to detect how to build the code.
* Create a TAR that contains  [[#S2I_Scripts|S2I scripts]] and source code.
* Untar [[#S2I_Scripts|S2I scripts]], sources and artifacts.
* Invoke the [[#assemble|assemble]] script.
* The build process changes to 'contextDir' - anything that resides outside 'contextDir' is ignored by the build.
* Run build.
* Push image to docker-registry.default.svc:5000/<''project-name''>/...
 
====Builder Image====
 
The builder image is an image that must contain both compile time dependencies and build tools, because the build process take place inside it, and runtime dependencies and the application runtime, because the image will be used to create containers that execute the application. The builder image must also contain the tar archiving utility, available in $PATH, which is used during the build process to extract source code and S2I scripts, and the /bin/sh command line interpreter. A builder image should be able to generate some usage information by running the image with [[docker run]]. An article that shows how to create builder images is available here: https://blog.openshift.com/create-s2i-builder-image/.
 
====Extended Build====
 
An extended build uses a [[#Builder_Image|builder image]] and a ''runtime image'' as two separate images. In this case the builder image contains the build tooling but not the application runtime. The runtime image contains the application runtime. This is useful when we don't want the build tooling laying around in the runtime image.
 
====S2I Scripts====
 
The S2I scripts encapsulate the build logic and must be executable inside the [[#Builder_Image|builder image]]. They must be provided as an input of the source build and play an essential role in the [[#The_Build_Process|build process]]. They come from one of the following locations, listed below in the inverse order of their precedence (if the same script is available in more than one location, the script from the location listed last in the list is used):
 
* Bundled with the [[#Builder_Image|builder image]], in a location specified as "io.openshift.s2i.scripts-url" label. A common value is "image:///usr/local/s2i". As an example, these are the S2I scripts that come with an EAP7 builder image: [https://github.com/NovaOrdis/playground/blob/master/openshift/sample-s2i-scripts/eap7-image/assemble assemble], [https://github.com/NovaOrdis/playground/blob/master/openshift/sample-s2i-scripts/eap7-image/run run] and [https://github.com/NovaOrdis/playground/blob/master/openshift/sample-s2i-scripts/eap7-image/save-artifacts save-artifacts].
* Bundled with the source code in an .s2i/bin directory of the application source repository.
* Published at an URL that is specified in the [[OpenShift_Build_Configuration_Definition#scripts|build configuration definition]].
 
Both the "io.openshift.s2i.scripts-url" label value specified in the image and the script specified in the [[OpenShift_Build_Configuration_Definition#scripts|build configuration]] can take one of the following forms:
* image:///<''path-to-script-directory''> - the absolute path inside the image.
* file:///<''path-to-script-directory''> - relative or absolute path to a directory on the host where the scripts are located.
* http(s)://<''path-to-script-directory''> - URL to a directory where the scripts are located.
 
The scripts are:
 
=====assemble=====
 
This is a required script. It builds the application artifacts from source and places them into appropriate directories inside the image. The script's main responsibility is to turn source code into a runnable application. It can also be used to inject configuration into the system.
 
It should execute the following sequence:
* Restore build artifacts, if the build is incremental. In this case [[#save-artifacts|save-artifacts]] must be also defined.
* Place the application source in the build location.
* Build.
* Install the artifacts into locations that are appropriate for them to run.
 
EAP7 builder image example: [https://github.com/NovaOrdis/playground/blob/master/openshift/sample-s2i-scripts/eap7-image/assemble assemble].
 
=====run=====
 
This is a required script. It is invoked when the container is instantiated to execute the application.
 
EAP7 builder image example: [https://github.com/NovaOrdis/playground/blob/master/openshift/sample-s2i-scripts/eap7-image/run run].
 
=====save-artifacts=====
 
This is an optional script, needed when incremental builds are enabled. It gathers all dependencies that can speed up the build process, from the build image that has just completed the successful build (the Maven .m2 directory, for example). The dependencies are assembled into a tar file and streamed to standard output.
 
EAP7 builder image example: [https://github.com/NovaOrdis/playground/blob/master/openshift/sample-s2i-scripts/eap7-image/save-artifacts save-artifacts].
 
=====usage=====
 
This is an optional script. Informs the user how to properly use the image.
 
=====test/run=====
 
This is an optional script. Allows to create a simple process to check whether the image is working correctly. For more details see:
 
{{External|https://docs.openshift.com/container-platform/latest/creating_images/s2i_testing.html#creating-images-s2i-testing}}
 
====Incremental Build====


=Build=
The source build may be configured as an ''incremental build'', which re-uses the previously downloaded dependencies and previously built artifacts, in order to speed up the build. Incremental builds reuse previously downloaded dependencies, previously built artifacts, etc.


{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html}}
strategy
  type: "Source"
  sourceStrategy:
    from:
        ...
    <font color=teal>'''incremental'''</font>: true


A ''build'' is the process of transforming input parameters into a resulting object. In most cases, that means transforming source code, other images, Dockerfiles, etc. into a runnable image. A build is run inside of a container and has the same restrictions normal pods have. A build usually results in an image pushed to a Docker registry, subject to post-build tests.
====Webhooks====


Docker can be used to build [[Docker Concepts#Container_Image|images]] directly, but OpenShift supplies additional builders to assist with creating an image, by adding code or configuration to existing images. The build process is defined by its [[#Build_Strategy|build strategy]].
A source build can be configured to be automatically trigged when a new event - most commonly a push - is detected by the source repository.  When the repository identifies a push, or any other kind of event it was configured for, it makes a HTTP invocation into an OpenShift URL. For internal repositories that run within the OpenShift cluster, such as [[OpenShift Gogs|Gogs]], the URL is https&#58;//openshift.default.svc.cluster.local/oapi/v1/namespaces/<''project-name''>/buildconfigs/<''build-configuration-name''>/webhooks/<''generic-secret-value''>/generic. The secret value can be [[OpenShift_Build_Configuration_Definition#Enable_a_Generic_Webhook_Trigger|manually configured in the build configuration]], as shown here, but it is usually set to a randomly generated value when the build configuration is created. For an external URL, such as GitHub, the URL must be publicly accessible '''<font color=red>TODO</font>'''. Once the build is triggered, it proceed as it would otherwise proceed if it was triggered by other means. Note that no build server is required for this mechanism to work, though a build server such as [[OpenShift_CI/CD_Concepts#Overview|Jenkins]] can be integrated and configured to drive a [[#Pipeline_Build|pipeline build]].


The build operations are executed by OpenShift in [[Docker_Concepts#Privileged_Container|privileged containers]].
The detailed procedure to configure a webhook trigger is available here:


Builds for a project can be reviewed by navigating with the web console to the project -> Builds -> Builds.
{{Internal|OpenShift_Build_Operations#Configure_a_Webhook_Trigger_for_a_Source_Build|Configure a Webhook Trigger for a Source Build}}


Build operations:
====Tagging the Build Artifact====


{{Internal|OpenShift Build Operations#Overview|Build Operations}}
Once the build process (the [[#assemble|assemble]] script) completes successfully, the build runtime sets the image's command to the [[#run|run]] script, and tags the image with the [[OpenShift Build Configuration Definition#output|output name]] specified in the build configuration.


<span id='Build_Config'></span>
<font color=red>'''TODO'''</font>. How to tag the output image with a dynamic tag that is generated from the information in the source code itself?
==Build Configuration==


A <tt>BuildConfig</tt> object is the definition of an entire build. It contains a description of how to build source code and a base image into a
==== MAVEN_MIRROR_URL====
new image, the specification of triggers (web-hooks), which specify events for invoking builds, for example when a newer base image is available, or new deployments.


Builds can be:
<font color=red>'''TODO'''</font> 'MAVEN_MIRROR_URL' is an environment variable interpreted by the s2i builder, which use the Maven repository whose URL is specified as a source of artifacts. For more details see: {{Internal|OpenShift_Nexus#MAVEN_MIRROR_URL|OpenShift Nexus}}
* Source based and use builder images for common languages like Java, PHP, Ruby, or Python
* Docker based and create builds from a Dockerfile.


OpenShift creates Docker containers from build images and pushes the to an integrated registry.
===Pipeline Build===


[[oc new-app]] creates a <tt>BuildConfig</tt> object.
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html#pipeline-build}}


The BuildConfig consists of:
{{External|https://docs.openshift.com/container-platform/latest/install_config/configuring_pipeline_execution.html#install-config-configuring-pipeline-execution}}
* Triggers (GitHub webhook, generic webhook, image changes)
* Parameters (source, [[#Build_Strategy|strategy]], output)


==Build Strategy==
{{External|https://docs.openshift.com/container-platform/latest/dev_guide/dev_tutorials/openshift_pipeline.html}}


===Docker Build===
The ''pipeline build strategy'' allows the developers to defined the build logic externally, as a [[Jenkins_Concepts#Pipeline|Jenkins Pipeline]]. The logic is executed by an [[OpenShift_CI/CD_Concepts#Jenkins_Integration|OpenShift-integrated Jenkins instance]], which uses a series of specialized plug-ins to work with OpenShift. More details about how OpenShift and Jenkins interact are available in the [[OpenShift_CI/CD_Concepts#Overview|OpenShift CI/CD Concepts]] page. The specification of the build logic can be embedded directly into an OpenShift build configuration object, as shown below, or it can be specified externally into a [[OpenShift_CI/CD_Concepts#Jenkinsfile|Jenkinsfile]] which is then later automatically integrated with OpenShift. The build can then be started, monitored, and managed by OpenShift in the same way as any other build type, but it can at the same time be managed from the Jenkins UI - these two representations are kept in sync. The pipeline's graphical representation is available both in the integrated Jenkins instance and it OpenShift directly, as a "Pipeline":


The Docker build expects repository with [[Dockerfile]] and all artifacts required to produce runnable image. It invokes the [[docker build]] command, and the result is a runnable image.
[[Image:OpenShiftPipeline.png]]


===Source-to-Image (S2I) Build===
The pipeline build strategy is specified in the [[#Build_Configuration|build configuration]] as follows:


{{External|https://docs.openshift.com/enterprise/3.0/architecture/core_concepts/builds_and_image_streams.html#source-build}}
kind: BuildConfig
spec:
  '''strategy''':
      '''type''': <font color=teal>'''JenkinsPipeline'''</font>
      <font color=teal>'''jenkinsPipelineStrategy'''</font>:
        <font color=teal>'''jenkinsfile'''</font>: |-
            node('mvn') {
                //
                // Groovy script that defines the pipeline
                //
            }
  '''source''':
    '''type''': none
  '''output''': {}


It is a process for building reproducible Docker images, which produces runnable images by injecting application source into a Docker image and assembling a new Docker image. The new image incorporates the base image (also known as the [[#Builder_Image|builder image]]) and the built source code and it is ready to use with the [[docker run]] command. S2I supports incremental builds, which reuse previously downloaded dependencies, previously built artifacts, etc.
This is an example of specifying the build logic inline in the build configuration. It is also possible to specify the build logic externally in a [[OpenShift_CI/CD_Concepts#Jenkinsfile|Jenkinsfile]]. Note that unlike in the [[#Source-to-Image_.28S2I.29_Build|source build]]'s case, no "output" are specified, because this is fully defined in the Jenkins Groovy script. "source" may be used to specify a source repository URL that contains the [[OpenShift_CI/CD_Concepts#Jenkinsfile|Jenkinsfile]] pipeline definition.


A Git ''repository URL'', which contains code written in any supported framework, and a [[#Builder_Image|builder image]], which contains the O/S and the framework to support the code, must be specified to start a S2I build.
An example of how to create a pipeline build configuration from scratch is available here: {{Internal|OpenShift_Build_Operations#Pipeline_Build|Create a Pipeline Build}}


S2I scripts can be written to inject application code into almost any existing Docker image. The assemble process can perform a large number of complex operations without creating a new layer at each step, resulting in a fast process. S2I allows to build the application consistently if an underlying image needs a patch due to a security issue.
====<span id='CICD_Support'></span><span id='CI/CD_Support'></span>CI/CD====


S2I provide a developer-centric flow that focuses on turning the developer source code into a running application as simple as possible.
OpenShift enables [[Software Development#DevOps|DevOps]]. It has built-in support for the [[OpenShift CI/CD Concepts#Overview|Jenkins CI server]], providing a native way of doing [[Continuous Integration#Overview|Continuous Integration]] and [[Continuous Delivery#Overview|Continuous Delivery]].


====Builder Image====
{{Internal|OpenShift CI/CD Concepts|OpenShift CI/CD Concepts}}


The builder image contain both the build and the runtime environment for that source code.
{{Internal|OpenShift CI/CD Operations|OpenShift CI/CD Operations}}


===Custom Build===
===Custom Build===
Line 910: Line 984:
The ''custom builder image'' is a plain Docker image embedded with build process logic.
The ''custom builder image'' is a plain Docker image embedded with build process logic.


===Pipeline Build===
===Chained Builds===
 
Two builds may be chained: one produces binaries from a builder image and source, and pushes the artifacts into an image stream; the other pulls the binaries produces by the first build from the image stream and places them into a runtime image, based on a Dockerfile, A separated image is thus created.
 
<span id='Build_Config'></span>
 
==Build Configuration==
 
A <tt>BuildConfig</tt> object is the definition of an entire build. It contains a description of how to combine source code and a base image to produce a
new image. The <tt>BuildConfig</tt> lists the location of the source code, the [[#Build_Trigger|build triggers]], the [[#Build_Strategy|build strategy]], various other build configuration parameters, such as [[OpenShift_Build_Operations#Set_Maximum_Duration|maximum allowed duration]], and the specification of the output of the build, which is in most cases a Docker container that gets pushed into the integrated registry. Both [[oc new-app]] and [[oc new-build]] create <tt>BuildConfig</tt> objects. The preferred way to create a build configuration is to start with  [[oc new-build]] and customize the resulted build configuration:
 
{{Internal|OpenShift_Build_Operations#Create_a_Build_Configuration|Create a Build Configuration with oc new-build}}
 
{{Internal|OpenShift Build Configuration Definition|Build Configuration Definition}}
 
Generally, immediately after the build configuration is declared, a build starts, and if it successful, a new image will be pushed into the artifact image stream.
 
===Build Trigger===
 
Builds can be triggered by the following events:
 
<font color=red>'''TODO''': when does a build start automatically and when doesn't.</font>
 
====github, generic, gitlab, bitbucket====
 
Source code change signaled by a GitHub webhook or a generic webhook. An internal repository repository must be configured to invoke into an URL similar to https&#58;//openshift.default.svc.cluster.local/oapi/v1/namespaces/$CICD_PROJECT/buildconfigs/<''application-name''>/webhooks/${WEBHOOK_SECRET}/generic. An external repository must be configured to invoke either into Jenkins using a URL similar to <font color=red>?</font> or into the associated build configuration, using an URL similar to <font color=red>?</font>.
 
====<span id='imageChange'></span>ImageChange====
 
{{External|https://docs.openshift.com/container-platform/3.7/dev_guide/deployments/basic_deployment_operations.html#image-change-trigger}}
 
Base image change, in case of [[#Source-to-Image_.28S2I.29_Build|source-to-image]] builds.
 
====Build Configuration Change====
 
{{External|https://docs.openshift.com/container-platform/3.7/dev_guide/deployments/basic_deployment_operations.html#config-change-trigger}}
 
====Manual Build====
 
Manual with [[oc start-build]].
 
===Build Source===
<span id='Build_Sources'></span>
 
A build configuration accepts the following type of sources:
* Git
* Binary (Git and binary are mutually exclusive).  See https://docs.openshift.com/container-platform/latest/dev_guide/builds/build_inputs.html#binary-source.
* Dockerfile
* Image
* [[#Build_Secrets|Input secrets]]
* External artifacts
 
====Build Secrets====
<span id='Build Configuration and Build Secrets'></span>
 
The source element may refer to build [[OpenShift_Security_Concepts#Secret|secrets]]:
 
kind: BuildConfig
...
spec:
  ...
  source:
    ...
    <font color=teal>'''sourceSecret'''</font>:
      name: some-secret
 
===Build Node Selection===
 
Build can be assigned to specific nodes, by specifying labels in the "nodeSelector" field of the build configuration:
 
kind: BuildConfig
...
spec:
  nodeSelector:
    env: app
 
===Build Resources===
 
Can be setup in the build configuration:
 
kind: BuildConfig
<font color='teal'>'''spec'''</font>:
  <font color='teal'>'''resources'''</font>:
    <font color='teal'>'''limits'''</font>:
      cpu: ...
      memory: ...
 
==Build Operations==


The ''pipeline build strategy'' allows developers to define a Jenkins [[#Pipeline|pipeline]] for execution by Jenkins pipeline plugin.
{{Internal|OpenShift Build Operations|Build Operations}}


=Image=
=Image=
Line 918: Line 1,079:
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#docker-images}}
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#docker-images}}


An ''image'' is a layered Linux filesystem that contains all dependencies a container needs to run (application code, application dependencies and any supporting operating system libraries), and the metadata describing its needs and capabilities. An image is identified by a name that can be local to the current cluster - meaning that it is maintained in the internal Docker registry - or point to a remote Docker registry.
An OpenShift ''image'' represents a ''immutable'' [[Docker Concepts#Image|container image in Docker format]]. Images are not project-scoped, but cluster-scoped: any user from any project can get information about any image in the cluster with [[OpenShift_Image_and_ImageStream_Operations#List_Images_available_to_the_Cluster|oc get images]], provided that it has sufficient cluster-level privileges. One role that permits inspecting image information is [[OpenShift_Security_Concepts#.2Fcluster-reader|/cluster-reader]] . On the other hand, a user that only has project-level privileges cannot inspect images.


For more details about Docker images see:
Information about a specific image can be obtained with [[OpenShift_Image_and_ImageStream_Operations#Image_Information|oc get image <''image-name''>]]


{{Internal|Docker_Concepts#Images|Docker Image}}
{{Internal|OpenShift Image Definition|OpenShift Image Definition}}


Images in OpenShift are ''immutable''.
==Image Name==


==Image Stream==
An image is identified by a name, which is the SHA256 hash of the image: "sha256:ea573da7c263e68f2d021c63bec218b79699a0b48e58b3724360de9c6900ca46".  The name can be local to the current cluster - the images produced as artifacts of the cluster's project do not exist anywhere else, until they are explicitly published - or point to a remote Docker registry. An OpenShift cluster usually comes with its own [[#Integrated_Docker_Registry|integrated Docker registry]], accessible to all projects, whose main function is to store images produced by the projects as result of [[#Build|build activities]].


An ''image stream'' is similar to a Docker image repository, in that it contains a group of related Docker images identified by [[#Image_Stream_Tag|image stream tags]]. Logically it is analogous to a branch in a source code repository.
==Image Reference==


The image stream presents a single virtual view of related images. The stream may contain images from the OpenShift integrated Docker registry, other image streams, other image repositories.
The image contains a "dockerImageReference" entry that maintains the location the image can be found at:


OpenShift stores complete metadata about each image, including example command, entry point and environment variables.
docker-registry.default.svc:5000/novaordis-dev/tasks@sha256:41976593d219eb2008a533e7f6fbb17e1fc3391065e2d592cc0b05defe5d5562
 
registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift@sha256:ea573da7c263e68f2d021c63bec218b79699a0b48e58b3724360de9c6900ca46
 
=Image Stream=
 
An ''image stream'' is similar to a [[Docker_Concepts#Image_Repository|Docker image repository]], in that it contains a group of related Docker images identified by [[#Image_Stream_Tag|image stream tags]].
 
The difference in referencing an image stream (or a tag within an image stream) instead of referencing a image registry/namespace/repository:tag directly is that actions can be triggered automatically when the underlying image changes. These actions may include functionality to control when image updates are rolled out.
 
Logically it is analogous to a branch in a source code repository. The image stream presents a single virtual view of related images and allow you to control which images are rolled out to your builds and applications. The stream may contain images from the OpenShift integrated Docker registry, other image streams, other image repositories. OpenShift stores complete metadata about each image, including example command, entry point and environment variables.
 
{{Internal|OpenShift_Image_Stream_Definition#Overview|Image Stream Definition}}
 
Image streams exist as OpenShift objects, describable with <tt>oc get is</tt>, but they also have a representation in the cluster's [[OpenShift_Concepts#Integrated_Docker_Registry|integrated docker repository]] docker-registry.default.svc:5000/, as ''project-name''/''image-stream-name''. As an example, for a "blue-project" and a "red-is":
 
kind: '''ImageStream'''
metadata:
  ...
  '''name''': '''red-is'''
  '''namespace''': '''blue-project'''
spec:
  tags:
  - '''name''': '''latest'''
    '''from''':
      kind: DockerImage
      '''name''': '''registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift'''
 
[[Image:ImageStreamInRegistry.png]]
 
Example of a JSON file that can be used to create image streams in OpenShift: {{External|https://github.com/openshift/origin/blob/master/examples/image-streams/image-streams-rhel7.json}}


[[#Build|Builds]] and [[#Deployment|deployments]] can watch an image stream to receive notifications when new images are added and react by performing a build or a deployment.
[[#Build|Builds]] and [[#Deployment|deployments]] can watch an image stream to receive notifications when new images are added and react by performing a build or a deployment.
Line 939: Line 1,130:


{{Internal|OpenShift_Image_and_ImageStream_Operations|ImageStream Operations}}
{{Internal|OpenShift_Image_and_ImageStream_Operations|ImageStream Operations}}
==="openshift" Image Streams===
A set of standard image streams come pre-configured in the "[[#.22openshift.22_Project|openshift]]" project of an OpenShift installation, but image streams can be [[OpenShift_Image_and_ImageStream_Operations#Create_an_Image_Stream|created in any project]].
==Image Stream Lookup Policy==
The lookup policy specifies how other resources reference this image within this namespace.
Possible values:
* '''local''' - will change the docker short image reference, such as "mysql" or "php:latest" on objects in this namespace to the image ID whenever they match this image stream, instead of reaching out to a remote registry. The name will be fully qualified to an image ID if found. The gag's referencePolicy is taken into account on the replaced value. It only works within the current namespace.


==Image Stream Tag==
==Image Stream Tag==


The default tag is called "latest".
The default tag is called "latest". A tag may point to an external Docker registry, at other tags in the same image stream, a different image stream, or be controlled to directly point to known images. An image stream tag full name is <''image-stream-name''>:<''tag-name''>. For example, the tag "0.11.29" exposed by the "gogs" image stream as shown here:


A tag may point to an external Docker registry, at other tags in the same stream, or be controlled to directly point to known images.
...
kind: ImageStream
metadata:
  '''name''': <font color=teal>gogs</font>
spec:
  tags:
  - '''name''': <font color=teal>"0.11.29"</font>
    ...
 
is referred to by a deployment configuration as:
 
...
triggers:
- type: ImageChange
    imageChangeParams:
      ...
      from:
        kind: ImageStreamTag
        '''name''': <font color=teal>'''gogs:0.11.29'''</font>


<font color=red> Images can be pushed to an image stream tag directly via the integrated Docker registry.</font>
<font color=red> Images can be pushed to an image stream tag directly via the integrated Docker registry.</font>
The image stream tag has a '''referencePolicy''', which defines how other components should consume this image. The reference policy's '''type''' determines how the image pull spec should be transformed when the image stream tag is used in deployment configuration triggers or new builds. The default value is "Source", indicating the original location of the image should be used (if imported). The user may also specify "Local", indicating that the pull spec should point to the integrated Docker registry and leverage the registry's ability to proxy the pull to an upstream registry. "Local" allows the credentials used to pull this image to be managed from the image stream's namespace, so others on the platform can access a remote image but have no access to the remote secret. It also allows the image layers to be mirrored into the local registry which the images can still be pulled even if the upstream registry is unavailable.


==Image Pull Policy==
==Image Pull Policy==
Line 952: Line 1,174:
When the container is created, the runtime uses the "imagePullPolicy" to determine whether to pull the image prior to starting the container. More details available here:
When the container is created, the runtime uses the "imagePullPolicy" to determine whether to pull the image prior to starting the container. More details available here:


{{Internal|Pod_Definition_File#imagePullPolicy|Pod Definition File - imagePullPolicy}}
{{Internal|Pod_Definition#imagePullPolicy|Pod Definition - imagePullPolicy}}
 
==To Process==
 
* https://github.com/openshift/origin/tree/master/examples/image-streams


=Deployment=
=Deployment=


A ''deployment'' is a [[#Replication_Controller|replication controller]] based on a user-defined [[#Template|template]] called a [[#DeploymentConfig|deployment configuration]].  
{{External|https://docs.openshift.com/container-platform/latest/architecture/core_concepts/deployments.html}}
 
{{External|https://docs.openshift.com/container-platform/latest/dev_guide/deployments/how_deployments_work.html}}


A ''deployment'' adds extended support for software development and deployment lifecycle. Deployments are created manually or in response to triggered events.  
A ''deployment'' is a [[#Replication_Controller|replication controller]] based on a user-defined [[#Template|template]] called a [[#DeploymentConfig|deployment configuration]]: a successful deployment results in a new replication controller being created.


The deployment system provides a [[#DeploymentConfig|deployment configuration]], which is a [[#Template|template]] for deployments, triggers that drive automated deployments in response to events, user-customizable strategies to transition from the previous deployment to the new deployment, rollback procedure, and manual replication scaling.Deployment configuration version increments each time new deployment is created from configuration. Deployments allow defining hooks to be run before and after the replication controller is created.
A deployment adds extended support for software development and deployment lifecycle. Deployments are created manually or in response to triggered events, and the most common events that trigger a deployment are either an image change or a configuration change.
 
The deployment system provides a [[#DeploymentConfig|deployment configuration]], which is a [[#Template|template]] for deployments, triggers that drive automated deployments in response to events, user-customizable strategies to transition from the previous deployment to the new deployment, rollback procedure, and manual replication scaling. Deployment configuration version increments each time new deployment is created from configuration. Deployments allow defining hooks to be run before and after the replication controller is created.


Deployments allow [[#Rollback|rollbacks]].
Deployments allow [[#Rollback|rollbacks]].
Line 968: Line 1,198:
The deployments are triggered with [[oc deploy]].
The deployments are triggered with [[oc deploy]].


==DeploymentConfig==
==Deployment Configuration==
<span id='DeploymentConfig"></span>


<span id="Deployment_Configuration"></span>A ''deployment configuration'' is a user-defined [[#Template|template]] for performing [[#Deployment|deployments]], which result in running applications. The deployment configuration defines the template for a [[#Pod|pod]]. It manages deploying new images or configuration changes whenever those change. A single deployment configuration is usually analogous to a single micro service.
<span id="Deployment_Configuration"></span>A ''deployment configuration'' is a user-defined [[#Template|template]] for performing [[#Deployment|deployments]], which result in running applications. The deployment configuration defines the template for a [[#Pod|pod]]. It manages deploying new images or configuration changes whenever those change. A single deployment configuration is usually analogous to a single micro service.
Line 979: Line 1,210:
* [[#Replication_Controller|Replication controller]] definition.
* [[#Replication_Controller|Replication controller]] definition.
* Default replica count fo the deployment.
* Default replica count fo the deployment.
* Triggers for creating new deployments automatically, in response to events. If no triggers are defined, deployments must be started manually.
* [[#Deployment_Configuration_Triggers|Triggers]] for creating new deployments automatically, in response to events. If no triggers are defined, deployments must be started manually.
* Strategy for transitioning before deployments.
* Strategy for transitioning before deployments.
* Life-cycle hooks. Every hook has a failure policy (Abort, Retry, Ignore).
* Life-cycle hooks. Every hook has a failure policy (Abort, Retry, Ignore).


DeploymentConfiguation triggers:
{{Internal|OpenShift DeploymentConfig Definition|DeploymentConfig Definition}}
* ConfigChange - results in a new deployment whenever changes are detected to replication controller template of deployment configuration.
* ImageChange - results in a new deployment whenever value of image stream tag changes.
 
{{Internal|DeploymentConfig Definition File|DeploymentConfig Definition File}}


The DeploymentConfig for a project can be listed with:
The DeploymentConfig for a project can be listed with:
Line 993: Line 1,220:
  [[Oc_get#dc|oc get dc]]
  [[Oc_get#dc|oc get dc]]


==External==
===Deployment Triggers===
<span id='Deployment_Configuration_Triggers'></span>
 
The deployment triggers are specified in the deployment configuration, and can be modified [[OpenShift_Application_Operations#Configuring_Deployment_Triggers_from_Command_Line|from command line]]:
 
====ConfigChange====
 
Results in a new deployment, and a new replication controller being created whenever changes are detected to replication controller template of deployment configuration. In the presence of a ConfigChange trigger, the first replication controller is automatically created when the deployment configuration itself is created.


* https://docs.openshift.com/container-platform/3.6/dev_guide/deployments/how_deployments_work.html
====ImageChange====
 
The deployment trigger is a change in the image stream. If we do not want the result of a build to be deployed automatically, even if the build pushes a new image in the repository, we simply do not list the "ImageChange" deployment trigger in the deployment configuration.


==Replication Controller==
==Replication Controller==


A ''replication controller'' is one of the [[#Controller|pod controller]] types available in OpenShift.  
A ''replication controller'' is one of the [[OpenShift Pod Concepts#Controller|pod controller]] types available in OpenShift. It resides on master, and insures that the specified number of pod [[Kubernetes Concepts#Replica|replicas]] defined in the replication controller configuration are running at all times.  
 
It resides on master, and insures that the specified number of pod [[Kubernetes Concepts#Replica|replicas]] defined in the environment state are running at all times.  


Logically, the replication controllers constitute the [[#Replication_Layer|replication layer]].  
Logically, the replication controllers constitute the [[#Replication_Layer|replication layer]].  
Line 1,008: Line 1,242:


A replication controller is most commonly used to represent a single deployment of part of an application based on a built image.
A replication controller is most commonly used to represent a single deployment of part of an application based on a built image.
There were situations when a failed deployment can be re-started by deleting the replication controller.


The replication controllers of a project can be listed with:
The replication controllers of a project can be listed with:
  [[Oc_get#all|oc get all]]
  [[Oc_get#all|oc get all]]
  [[Oc_get#rc|oc get rc]]
  [[Oc_get#rc|oc get rc]]
===Rollout===
A rollout is exposed as a [[#Replication_Controller|replication controller]], and the deployment process manages scaling down old replication controllers and scaling up new ones. Implements one of the [[#Deployment_Strategy|deployment strategies]]. The rollout is performed with:
[[OpenShift_Application_Operations#Rollout|oc rollout]]
==Deployment Configurations and Replication Controllers==
A deployment configuration triggers creation of a [[#Replication_Controller|replication controller]].
[[OpenShift_Deployment_Operations#Deleting_a_Deployment_Configuration|Deleting a deployment configuration]] will automatically delete the [[#Replication_Controller|replication controllers]] generated by that deployment configuration.


==Rollback==
==Rollback==
Line 1,019: Line 1,267:
==Deployment Strategy==
==Deployment Strategy==


The [[#Deployment_Configuration|deployment configuration]] defines a ''deployment strategy''. The deployment strategy determines the deployment process. It uses readiness checks to determine if a new host is ready for use. If the readiness check fails, the deployment configuration retries until it times out.
The [[#Deployment_Configuration|deployment configuration]] defines a ''deployment strategy''. The deployment strategy determines the deployment process and it is defined by the deployment configuration. The deployment strategy uses readiness checks to determine if a new host is ready for use. If the readiness check fails, the deployment configuration retries until it times out. The readiness timeout value is set in deployment configuration.
 
The deployment strategy is implemented during the [[#Rollout|rollout]] process.


===Rolling Deployment Strategy===
===Rolling Deployment Strategy===
Line 1,035: Line 1,285:


===Recreate Deployment Strategy===
===Recreate Deployment Strategy===
Recreate strategy is appropriate when the application does not support old versions and new versions running together, or when the application uses ReadWriteOnce volumes that do not support sharing between multiple replicas.
The recreate strategy implies downtime: there is a time interval when on application instance is running.


It consists in the following steps:
It consists in the following steps:
Line 1,043: Line 1,297:


During scale up, if the replica count of the deployment is greater than one, the first deployment replica is validated for readiness before fully scaling up the deployment. If this validation fails, the deployment fails.
During scale up, if the replica count of the deployment is greater than one, the first deployment replica is validated for readiness before fully scaling up the deployment. If this validation fails, the deployment fails.
...
kind: DeploymentConfig
spec:
  strategy:
    activeDeadlineSeconds: 21600
    type: Recreate
    recreateParams:
      pre:
      mid:
      post:
      timeoutSeconds:   
Parameters:
* '''activeDeadlineSeconds''':  the duration in seconds that the deployer pods for this deployment may bee active on a node before the system actively tries to terminate them.


===Custom Deployment Strategy===
===Custom Deployment Strategy===
Line 1,061: Line 1,331:
* OPENSHIFT_DEPLOYMENT_NAMESPACE
* OPENSHIFT_DEPLOYMENT_NAMESPACE


=Pipeline=
==To Process==


A pipeline is a Jenkins jobs enabled by the pipeline plugin.
<font color=red>
 
* Application release strategies for Red Hat OpenShift Container Platform 3 https://www.redhat.com/cms/managed-files/cl-openshift-container-platform-application-release-strategies-reference-architecture-f6609-201704-en.pdf
{{External|https://jenkins.io/doc/book/pipeline/overview/}}
</font>
 
Used by the [[#Pipeline_Build|pipeline build]].


=Region=
=Region=
Line 1,098: Line 1,366:


Installation is performed by Ansible, usually deployed on the environment's support server. Ansible configuration is available under /etc/ansible and the installation logic under /usr/share/ansible.
Installation is performed by Ansible, usually deployed on the environment's support server. Ansible configuration is available under /etc/ansible and the installation logic under /usr/share/ansible.
=Security=
{{Internal|OpenShift Security Concepts|OpenShift Security Concepts}}


=Metrics=
=Metrics=
Line 1,139: Line 1,403:
* SuccessfulCreate
* SuccessfulCreate


=DaemonSet=
=Command Line Tools=


{{External2|https://docs.openshift.com/container-platform/3.5/dev_guide/daemonsets.html|https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/}}
{{Internal|OpenShift Command Line Tools|OpenShift Command Line Tools (CLI)}}


A ''DaemonSet'' is a OpenShift component that creates its associated pods and ensures they run on all (or some) nodes of a cluster. It is one of the [[#Controller|pod controller]] types available in OpenShift.
=Admission Control=


If a node is added to the cluster, the DaemonSet insures that its associated pod will be scheduled on that node. When nodes are removed, the associated pods are shut down. Typical uses for DaemonSets are to run log collection agents ([[fluentd]], logstash), node monitoring agents (collectd) or a cluster storage daemon (glusterd, ceph). Usually, a DaemonSet is needed for each type of daemon.
{{External|https://docs.openshift.com/container-platform/latest/architecture/additional_concepts/admission_controllers.html}}


The DaemonSet decides whether it manages a pod or not based on the [[#Selector|label selector]] expression specified in its definition:
Admission control plug-ins intercept requests to the master API, after authentication and authorization was enforced. There's a chain of plug-ins (also known as the ''admission chain''), and if a plug-in rejects the request, the request fails. The plug-in may modify the request object, and related resources. The default list of admission control plug-ins is configured in the [[Master-config.yml#pluginConfig|master-config.yaml's admissionConfig/pluginConfig]] section.


...
Customizable admission control plug-ins:
'''Selector''': component=fluentd,provider=openshift
* '''BuildDefaults''' https://docs.openshift.com/container-platform/latest/install_config/build_defaults_overrides.html#ansible-setting-global-build-defaults
...
* '''ProjectRequestLimit''' https://docs.openshift.com/container-platform/latest/admin_guide/managing_projects.html#limit-projects-per-user
* '''RestrictSubjectBindings''' https://docs.openshift.com/container-platform/latest/admin_solutions/user_role_mgmt.html#role-binding-restriction
* Pod placement https://docs.openshift.com/container-platform/latest/admin_guide/scheduling/scheduler.html#controlling-pod-placement
* Init containers https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#init-containers


Note that internally, the declared pod template’s label selector must match the label selector above.
=OpenShift and JBoss=


When a pod is managed by a DaemonSet, the node the pod is scheduled to run on is selected by the DaemonSet, so the [[#Scheduler|scheduler]] ignores it. The "unschedulable" field of a node is not respected by the DaemonSet controller. Also, the DaemonSet controller can make pods even if the scheduler has not been started, and this helps with cluster bootstrap. The DaemonSet chooses the nodes to run its pods on based on the [[#Node_Selector|node selector]] specified in its definition:
{{Internal|OpenShift and JBoss|OpenShift and JBoss}}


...
=Jobs=
'''Node-Selector''': logging=true
...
[[Image:DaemonSet.png]]


After a successful placement, the node selector expression is [[OpenShift Concepts#successful_node_selector_recorded |recorded in the pod's definition]].
{{External|https://docs.openshift.com/container-platform/latest/dev_guide/jobs.html}}


==DaemonSet Operations==
apiVersion: batch/v1
kind: Job


* [[OpenShift_DaemonSet_Operations#Obtaining_Information_about_DaemonSets|Obtaining information about DaemonSets]]
=Cron Jobs=
* [[OpenShift_DaemonSet_Operations#Creating_Daemon_Sets|Creating DaemonSets]]
* [[OpenShift_DaemonSet_Operations#Updating_Pods_Managed_by_DaemonSets|Updating pods managed by DaemonSets]]


=ConfigMaps=
{{External|https://docs.openshift.com/container-platform/latest/dev_guide/cron_jobs.html}}


{{External|https://docs.openshift.com/container-platform/3.6/dev_guide/configmaps.html}}
apiVersion: batch/v1
kind: CronJob


A ConfigMap is a component that holds key/value pairs of configuration data, and that can be consumed by pods, or can be used to store configuration for OpenShift system components such as controllers. It is a mechanism to inject containers with configuration while keeping the containers agnostic of the OpenShift platform. Aside from fine-grained information like individual properties, ConfigMaps can also store coarse-grained information such as entire configuration files or JSON blobs. The ConfigMaps can populate environment variables, set command-line arguments in a container and populate configuration files in a volume.
=Configuration Data Externalization=


A ConfigMap is similar to a [[#Secret|secret]], but designed to be more convenient when working with strings that do not contain sensitive information.  
Configuration data must never be stored in application source code, but it must externalized on storage.


{{Internal|ConfigMap Operations|ConfigMap Operations}}
==Environment Variables==


=Command Line Tools=
{{Internal|OpenShift Environment Variables|Environment Variables}}


{{Internal|OpenShift Command Line Tools|OpenShift Command Line Tools (CLI)}}
=Custom Metadata Annotations=


=Admission Control=
Custom metadata annotations can be specified in the [[OpenShift_DeploymentConfig_Definition#labels|spec.template.metadata.annotations]] section of the [[#Deployment_Configuration|deployment configuration]]. Those annotations will be injected into the pod metadata, and will be accessible from the pod with the [[OpenShift Volume Concepts#Downward_API|Downward API]].


{{External|https://docs.openshift.com/container-platform/latest/architecture/additional_concepts/admission_controllers.html}}
=Common Images=
 
* [[MySQL and OpenShift#Overview|MySQL]]
Admission control plug-ins intercept requests to the master API, after authentication and authorization was enforced. There's a chain of plug-ins (also known as the ''admission chain''), and if a plug-in rejects the request, the request fails. The plug-in may modify the request object, and related resources. The default list of admission control plug-ins is configured in the [[Master-config.yml#pluginConfig|master-config.yaml's admissionConfig/pluginConfig]] section.
 
Customizable admission control plug-ins:
* '''BuildDefaults''' https://docs.openshift.com/container-platform/latest/install_config/build_defaults_overrides.html#ansible-setting-global-build-defaults
* '''ProjectRequestLimit''' https://docs.openshift.com/container-platform/latest/admin_guide/managing_projects.html#limit-projects-per-user
* '''RestrictSubjectBindings''' https://docs.openshift.com/container-platform/latest/admin_solutions/user_role_mgmt.html#role-binding-restriction
* Pod placement https://docs.openshift.com/container-platform/latest/admin_guide/scheduling/scheduler.html#controlling-pod-placement
* Init containers https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#init-containers

Latest revision as of 01:44, 1 January 2022

DEPLETE TO

OpenShift Concepts

External

Internal

OpenShift Workflow

Users or automation make calls to the REST API via the command line, web console or programmatically, to change the state of the system. The master analyses the state changes and acts to bring the state of the system in sync with the desired state. The state is maintained in the store layer. Most OpenShift commands and API calls do not require the corresponding actions to be performed immediately. They usually create or modify a resource description in etcd. etcd then notifies Kubernetes or the OpenShift controllers, which notify the resource about the change. Eventually, the system state reflects the change.

OpenShift functionality is provided by the interaction of several layers:

  • The store layer holds the state of the OpenShift environment, which includes configuration information, current state and the desired state. It is implemented by etcd.
  • The authentication layer provides a framework for collaboration and quota management.
  • Scheduling is OpenShift master's main function and it is implemented in the scheduling layer, which contains the scheduler.
  • The service layer handles internal requests. It provides an abstraction of service endpoints and provides internal load balancing. The pods get IP addresses associated with the service endpoints. Note that the external requests are not handled by the service layer, but by the routing layer.
  • The routing layer handles external requests, to and from the applications. For a description of the relationship between a service and a router, see relationship between a service and router.
  • Application requests are routed to the business logic serving them according to the networking workflow, by the networking layer.
  • The replication layer contains the replication controller, whose role is to ensure that the number of instances and pods defined in the store layer actually exists.

Objects

Core Objects

Defined by Kubernetes, and also used by OpenShift. All these objects have an API type, which is listed below.

OpenShift Objects

Defined by OpenShift, outside Kubernetes. These objects also have an API type, which is listed below.

Other Objects that do not have an API Representation

OpenShift Hosts

Master

A master is a RHEL or Red Hat Atomic host that orchestrates and schedules resources.

The master maintains the state of the OpenShift environment.

The master provides the single API all tooling clients must interact with. All OpenShift tools (CLI, web console, IDE plugins, etc. speak directly with the master).

The access is protected via fine-grained role-based access control (RBAC).

The master monitors application health via user-defined pod probes, insuring that all containers that should be running are running. It handles restarting pods that failed probes automatically. Pods that fail too often are marked as "failing" and are temporarily not restarted. The OpenShift service layer sends traffic only to healthy pods.

Kubernetes Master

Masters use the etcd cluster to store state, and also cache some of the metadata in their own memory space.

Master HA

Multiple masters can be present to insure HA. A typical HA configuration involves three masters and three etcd nodes. Such a topology is built by the OpenShift 3.5 ansible inventory file shown here.

An alternative HA configuration consists in a single master node and multiple (at least three) etcd nodes.

The native HA Method

Master API

The master API is available internally (inside the OpenShift cluster) at https://openshift.default.svc.cluster.local This value is available internally to pods as the KUBERNETES_SERVICE_HOST environment variable.

Node

A node is a Linux container host. It is based on RHEL or Red Hat Atomic and provides a runtime environment where applications run inside containers, which run inside pods assigned by the master. Nodes are orchestrated by masters and are usually managed by administrators and not by end users. Nodes can be organized into different topologies. From a networking perspective, nodes gets allocated their own subnets of the cluster network, which then they use to distribute to the pods, and containers, running on them. More details about OpenShift networking is available here.

A node daemon runs on node each node.

Node operations:

TODO:

  • What is the difference between the kubelet and the node daemon?
  • kube proxy daemons.

Infrastructure Node

Also referred to as "infra node".

This is where infrastructure pods run. Metrics, logging, routers are considered infrastructure pods.

The infrastructure nodes, especially those running the the metrics pods and ... should be closely monitored to detect early CPU, memory and disk capacity shortages on the host system.

OpenShift Cluster

All nodes that share the SDN.

Container

https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#containers

A container is a kernel-provided mechanism to run one or more processes, in a portable manner, in a Linux environment. Containers are isolated from each other on a host and are initialized from images. All application instances - based on various languages/frameworks/runtimes - as well as databases, run inside containers on nodes. For more details, see

Docker Containers

A pod can have application containers and init containers.

In OpenShift, containers are never restarted. Instead, new containers are spun up to replace old containers when needed. Because of this behavior, persistent storage volumes mounted on containers are critical for maintaining state such as for configuration files and data files.

Docker Support in OpenShift

All containers that are running in pods are managed by Docker servers.

Docker Storage in OpenShift

Each Docker server requires Docker storage, which is allocated on each node in a space specially provisioned as Docker storage backend. The Docker storage is ephemeral and separate from OpenShift storage. The default loopback storage back end for Docker is a thin pool on loopback devices, which is not appropriate for production.

As per OCP 3.7, Docker storage ca be backed by one of two options (storage drivers): a devicemapper thin pool logical volume and an overlay2 filesystem (recommended). More details about how Docker storage is configured on a specific system can be obtained from:

cat /etc/sysconfig/docker-storage

DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper --storage-opt dm.fs=xfs --storage-opt dm.thinpooldev=/dev/mapper/docker_vg-container--thinpool --storage-opt dm.use_deferred_removal=true --storage-opt dm.use_deferred_deletion=true"

and also

docker info

The node Daemon

Pod

Contains: controller, pod configuration, pod lifecycle, terminal state, pod definition, pod name, pod placement, pod probe, liveness probe, readiness probe, local manifest pod, bare pod, static pod, pod type, terminating, nonterminating, pod presents, init container.

Label

Labels are simple key/value pairs that can be assigned to any resource in the system and are used to group and select arbitrarily related objects. Most Kubernetes objects can include labels in their metadata. Labels provide the default way of manage objects as groups, instead of having to handle each object individually. Labels are a Kubernetes concept.

Labels associated with a node can be obtained with oc describe node.

Selector

A selector is a set of labels. It is also referred to as label selector. Selectors are a Kubernetes concept.

Node Selector

A node selector is an expression applied to a node, which, depending on whether the node has or does not have the labels expected by the node selector, allows or prevents pod placement on the node in question during the pod scheduling operation. It is the scheduler that evaluates the node selector expression and decides on which node to place the pod. The DaemonSets also use node selectors when placing the associated pods on nodes.

Node selectors can be associated with an entire cluster, with a project, or with a specific pod. The node selectors can be modified as part of a node selector operation.

Cluster-Wide Default Node Selector

The cluster-wide default node selector is configured during OpenShift cluster installation to restrict pod placement on specific nodes. It is specified in the projectConfig.defaultNodeSelector section of the master configuration file master-config.yml. It can also be modified after installation with the following procedure:

Configure a Cluster-Wide Default Node Selector

Per-Project Node Selector

The per-project node selector is used by the scheduler to schedule pods associated with the project. The per-project node selector and takes precedence over cluster-wide default node selector, when both exist. It is available as "openshift.io/node-selector" project metadata (see below). If "openshift.io/node-selector" is set to an empty string, the project will not have an adminstrator-set node selector, even if the cluster-wide default has been set. This means that a cluster administrator can set a default to restrict developer projects to a subset of nodes and still enable infrastructure or other projects to schedule the entire cluster.

The per-project node selector value can be queried with:

oc get project -o yaml

It is listed as:

...
kind: Project
metadata:
  annotations:
    ...
    openshift.io/node-selector: ""
    ...

The per-project node selector is usually set up when the project is created, as described in this procedure:

Configuring a Per-Project Node Selector during Project Creation

It can also be changed after project creation with oc edit as described in this procedure:

Configuring a Per-Project Node Selector after Project Creation

Per-Pod Node Selector

The declaration of a per-pod node selector can be obtained running:

oc get pod <pod-name> -o yaml

and it is rendered in the "spec:" section of the pod definition:

...
kind: Pod
spec:
  ...
  nodeSelector:
    key-A: value-A


How is the node selector of a pod generated?

TODO: merge with OpenShift_Concepts#Pod_Placement

Once the pod has been created, the node selector value becomes immutable and an attempt to change it will fail. For more details on pod state see Pods.

Precedence Rules when Multiple Node Selectors Apply

TODO

External Resources

Scheduler

https://docs.openshift.com/container-platform/3.5/admin_guide/scheduler.html

Scheduling is the master's main function: when a pod is created, the master determines on what node(s) to execute the pod. This is called scheduling. The layer that handles this responsibility is called the scheduling layer.

The scheduler is a component that runs on master and determines the best fit for running pods across the environment. The scheduler also spreads pod replicas across nodes, for application HA. The scheduler reads data from the pod definition and tries to find a node that is a good fit based on configured policies. The scheduler does not modify the pod, it creates a binding that ties the pod to the selected node, via the master API.

The OpenShift scheduler is based on Kubernetes scheduler.

Most OpenShift pods are scheduled by the scheduler, unless they are managed by a DaemonSet. In this case, the DaemonSet selects the node to run the pod, and the scheduler ignores the pod.

The scheduler is completely independent and exists as a standalone, pluggable solution. The scheduler is deployed as a container, referred to as an infrastructure container. The functionality of the scheduler can be extended in two ways:

  1. Via enhancements, by adding predicates to the priority functions.
  2. Via replacement with a different implementation.

The pod placement process is described here:

Pod Placement

Default Scheduler Implementation

The default scheduler is a scheduling engine that selects the node to host the pod in three steps:

  1. Filter all available nodes by running through a list of filter functions called predicates, discarding the nodes that do not meet the criteria.
  2. Prioritize the remaining nodes by passing through a series of priority functions that assigns each node a score between 0 - 10. 10 signifies the best possible fit to run the pod. By default all priority function are considered equivalent, but they can be weighted differently via configuration.
  3. Sorts the node by score and selects the node with the highest score. If multiple nodes come with the same score, one is chosen at random.

Note that an insight into how the predicates are evaluated and what scheduling decisions are taken can be achieved by increasing the logging verbosity of the master controllers processes.

Predicates

Static Predicates

  • PodFitsPorts - a node is fit fi there are no port conflicts.
  • PodFitsResources - a node is fit based on resource availability. Nodes declare resource capacities, pods specify what resources they require.
  • NoDiskConflict - evaluates if a pod fits based on volumes requested and those already mounted.
  • MatchNodeSelector - a node is fit based on the node selector query.
  • HostName - a node is fit based on the presence of host parameter and string match with host name.

Configurable Predicates

ServiceAffinity

ServiceAffinity filters out nodes that do not belong to the topological level defined by the provided labels. See scheduler.json

LabelsPresence

LabelsPresence checks whether the node has certain labels defined, regardless of value.

Priority Functions

Existing Priority Functions

  • LeastRequestedPriority - favors nodes with fewer requested resources, calculates percentage of memory and CPU requested by pods scheduled on node, and prioritizes nodes with highest available capacity.
  • BalancedResourceAllocation - favors nodes with balanced resource usage rate, calculates difference between consumed CPU and memory as fraction of capacity and prioritizes nodes with the smallest difference. It should always be used with LeastRequestedPriority.
  • ServiceSpreadingPriority - spreads pods by minimizing the number of pods that belong to the same service, onto the same node
  • EqualPriority

Configurable Priority Functions

  • ServiceAntiAffinity
  • LabelsPreference

Scheduler Policy

The selection of the predicates and the priority functions defines the scheduler policy. The default policy is configured in the master configuration file master-config.yml as kubernetesMasterConfig.schedulerConfigFile. By default, it points to /etc/origin/master/scheduler.json. The current scheduling policy in force can be obtained with ?. A custom policy can replace it, if necessary, by following this procedure: Modify the Scheduler Policy.

Scheduler Policy File

The default scheduler policy is configured in the master configuration file master-config.yml as kubernetesMasterConfig.schedulerConfigFile, which by default points to /etc/origin/master/scheduler.json. Another example of scheduler policy file:

Scheduler Policy File

Volumes

Persistent Volumes, Persistent Volume Claims, EmptyDirs, ConfigMaps, Downward API, Host Paths, Secrets:

Volumes

etcd

Implements OpenShift's store layer, which holds the current state, desired state and configuration information of the environment.

OpenShift stores image, build, and deployment metadata in etcd. Old resources must be periodically pruned. If a large number of images/build/deployments are planned, etcd must be placed on machines with large amounts of memory and fast SSD drives.

etcd

etcd and Master Caching

Masters cache deserialized resource metadata to reduce the CPU load and keep the metadata in memory. For small clusters, the cache can use a lot of memory for negligible CPU reduction. The default cache size is 50,000 entries, which, depending on the size of resources, can grow to occupy 1 to 2 GB of memory. The cache size can be configured in master-config.yml.

Image Registries

https://docs.openshift.com/container-platform/latest/install_config/registry/index.html

Integrated Docker Registry

OpenShift contains an integrated Docker image registry, providing authentication and access control to images. The integrated registry should not be confused with the OpenShift Container Registry (OCR), which is a standalone solution, which can be used outside of an OpenShift environment. The integrated registry is an application deployed within the "default" project as a privileged container, as part of the cluster installation process. The integrated registry is available internally in the OpenShift cluster at the following Service IP: docker-registry.default.svc:5000/. It consists of a a "docker-registry" service, a "docker-registry" deployment configuration, a "registry" service account and a role binding that associates the service account to the "system:registry" cluster role. More details on the structure of the integrated registry can be generated with oadm registry -o yaml. The default registry also comes with a registry console that can be used to browse images.

The main function of the integrated registry is to provide a default location where users can push images they build. Users push images into registry and whenever a new image is stored in the registry, the registry notifies OpenShift about it and passes along image information such as the namespace, the name and the image metadata. Various OpenShift components react by creating new builds and deployments.

Alternatively, the integrated registry may store and expose to projects external images the projects may need. The docker servers on OpenShift nodes are configured to be able to access the internal registry, but they are also configured with registry.access.redhat.com and docker.io.

Multiple running instances of the container registry require backend storage supporting writes by multiple processes. If the chosen infrastructure provider does not contain this ability, running a single instance of a container registry is acceptable.

Questions:

  • How can I "instruct" an application to use a specific registry. a “lab” application to use registry-lab
  • How do pods that need images go to that registry and not other? The answer to this question lays in the way an application uses the registry.

External Registries

The external registries registry.access.redhat.com and docker.io are accessible. In general, any server implementing Docker registry API can be integrated as a stand-alone registry.

registry.access.redhat.com

registry.access.redhat.com

The Red Hat registry is available at http://registry.access.redhat.com. An individual image can be inspected with an URL similar to https://access.redhat.com/containers/#/registry.access.redhat.com/jboss-eap-7/eap70-openshift/images/1.5-23

docker.io

Docker Hub is available at http://dockerhub.com.

Stand-alone Registry

https://docs.openshift.com/container-platform/latest/install_config/install/stand_alone_registry.html#install-config-installing-stand-alone-registry

Any server implementing Docker registry API can be integrated as a standalone registry: a stand-alone container registry can be installed and used with the OpenShift cluster.

Integrated Registry Console

https://docs.openshift.com/container-platform/latest/install_config/registry/deploy_registry_existing_clusters.html#registry-console

The registry comes with a "registry console" that allows web-based access to the registry. An URL example is https://registry-console-default.apps.openshift.novaordis.io. The registry console is deployed as a registry-console pod part of the "default" project.

Registry Operations

Registry Operations

Service

OpenShift Service Concepts

API

Kubernetes API

Networking

In OpenShift, nodes communicate to each over using the infrastructure-provided network. Pods communicate with each other via a software defined network (SDN), also known as the cluster network, which runs in top of that.

Required Network Ports

https://docs.openshift.com/enterprise/3.1/install_config/install/prerequisites.html#prereq-network-access

Default Network Interface on a Host

Every time OpenShift refers to the "default interface" on a host, it means the network interface associated with the default route. This is the logic that figures it out is here:

Default Network Interface on a Host

SDN, Overlay Network

https://docs.openshift.com/container-platform/latest/architecture/additional_concepts/sdn.html#architecture-additional-concepts-sdn
https://docs.openshift.com/container-platform/latest/install_config/configuring_sdn.html

All hosts in the OpenShift environment are clustered and are also members of the overlay network based on a Software Defined Network (SDN). Each pod gets its own IP address, by default from the 10.128.0.0/14 subnet, that is routable from any member of the SDN network. Giving each pod its own IP address means that pods can be treated like physical hosts or virtual machines in terms of port allocation, networking, naming, service discovery, load balancing, application configuration and migration.

However, it is not recommended that a pod talks to another directly by using the IP address. Instead, they should use services as an indirection layer, and interact with the service, that may be deployed on different pods at different times. Each service also gets its own own IP address from the 172.30.0.0/16 subnet.

The Cluster Network

The cluster network is the network from which pod IPs are assigned. These network blocks should be private and must not conflict with existing network blocks in your infrastructure that pods, nodes or the master may require access to. The default subnet value is 10.128.0.0/14 (10.128.0.0 - 10.131.255.255) and it cannot be arbitrarily reconfigured after deployment. The size and address range of the cluster network, as well as the host subnet size are configurable during installation. Configured with 'osm_cluster_network_cid' at installation.

Samples of pod addresses can be obtained by querying service endpoints in a project:

oc get endpoints
NAME           ENDPOINTS          AGE
some-service   10.130.1.17:8080   21m

The master maintains a registry of nodes in etcd, and each node gets allocated upon creation an unused subnet from the cluster network. Each node gets a /23 subnet, which means the cluster can allocate 512 subnets to nodes, and each node has 510 addresses to assign to containers running on it. Once the node is registered with the master, and gets its cluster network subnet, SDN creates on the node three devices:

  • br0 - the OVS bridge device that pod containers will be attached to. The bridge is configured with a set of non-subnet specific flow rules.
  • tun0 - an OVS internal port (port 2 on br0). This gets assigned the cluster subnet gateway address, and it is used for external access. The SDN configures net filter and routing rules to enable access from the cluster subnet to the external network via NAT.
  • vxlan_sys_4789. This is the OVS VXLAN device (port 1 on br0) which provides access to containers on remote nodes. It is referred to as "vxlan0".

Each time a pod is started, the SDN assigns the pod a free IP address from the node's cluster subnet, attaches the host side of the pod's veth interface pair to the OVS bridge br0, adds OpenFlow rules to the OVS database to route traffic addressed to the new pod to the correct OVS port. If a ovs-multitenant plug-in is active, it also adds OpenFlow rules to tag traffic coming from the pod with the pod's VIND, and to allow traffic into the pod if the traffic's VIND matches the pod's VIND, or it is the privileged VIND 0.

Nodes update their OpenFlow rules in response to master's notification in case new nodes are added or leave. When a new subnet is added, the node adds rules on br0 so that packets with a destination IP address the remote subnet go to vxlan0 (port 1 on br0) and thus out onto the network. The ovs-subnet plug-in sends all packets across the VXLAN with VNID 0, but the ovs-multitenant plug-in uses the appropriate VNID for the source container.

The SDN does not allow the master host (which is running the OVS processes) to access the cluster network, so a master does not have access to pods via the cluster network, unless it is also running a node.

When ovs-multitenant plug-in is active, the master also allocates VXLAN VNIDs to projects. VNIDs are used to isolate the traffic.

Packet Flow

TODO: https://docs.openshift.com/container-platform/3.5/architecture/additional_concepts/sdn.html#sdn-packet-flow

Pod IP Address

A cluster network IP address, that gets assigned to a pod.

The Services Subnet

OpenShift uses a "services subnet", also known as "kubernetes services network", in which OpenShift Services will be created within the SDN. This network block should be private and must not conflict with any existing network blocks in the infrastructure to which pods, nodes, or the master may require access to. It defaults to 172.30.0.0/16. It cannot be re-configured after deployment. If changed from the default, it must not be 172.16.0.0/16, which the docker0 network bridge uses by default, unless the docker0 network is also modified. It is configured with 'openshift_master_portal_net', 'openshift_portal_net' at installation and populates the master configuration file servicesSubnet element. Note that Docker expects its insecure registry to available on this subnet.

The services subnet IP address of a specific service can be displayed with:

oc describe service <service-name>

or

oc get svc <service-name>

The Service IP Address

An IP address from the services subnet that is associated with a service. The service IP address is reported as "Cluster IP" by:

oc get svc <service-name>

This makes sense if we think about a service as a cluster of pods that provide the service.

Example:

oc get svc logging-es
NAME         CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
logging-es   172.30.254.155   <none>        9200/TCP   31d

Docker Bridge Subnet

Default 172.17.0.0/16.

Network Plugin

OpenShift Network Plugins

Open vSwitch

Open vSwitch

DNS

OpenShiftDNSConcepts.png

External DNS Server

An external DNS server is required to resolve the public wildcard name of the environment - and as consequence, all public names of various application access points - to the public address of the default router, as per networking workflow. If more than one router is deployed, the external DNS server should resolve the public wildcard name of the environment to the public IP address of the load balancer. For more details about initial configuration details see External DNS Setup.

Optional Support DNS Server

An optional support DNS server can be setup to translate local hostnames (such as master1.ocp36.local) to internal IP addresses allocated to the hosts running OpenShift infrastructure. There is no good reason to make these addresses and names publicly accessible. The OpenShift advanced installation procedure factors it in automatically, as long as the base host images OpenShift is installed in top of is already configured to use it to resolve DNS names via /etc/resolv.conf or NetworkManager. No additional configuration via openshift_dns_ip is necessary.

Internal DNS Server

A DNS server used to resolve local resources. The most common use is to translate service names to service addresses. The internal DNS server listens on the service IP address 172.30.0.1:53. It is a SkyDNS instance built into OpenShift. It is deployed on the master and answers the queries for services. The naming queries issued from inside containers/pods are directed to the internal DNS service by Dnsmasq instances running on each node. The process is described below.

The internal DNS server will answer queries on the ".cluster.local" domain that have the following form:

  • <namespace>.cluster.local
  • <service>.<namespace>.svc.cluster.local - service queries
  • <name>.<namespace>.endpoints.cluster.local - endpoint queries

Service DNS can still be used and responds with multiple A records, one for each pod of the service, allowing the client to round-robin between each pod.

Dnsmasq

Dnsmasq is deployed on all nodes, including masters, as part of the installation process, and it works as a DNS proxy. It binds on the default interface, which is not necessarily the interface servicing the physical OpenShift subnet, and resolves all DNS requests. All OpenShift "internal" names - service names, for example - and all unqualified names are assumed to be in the "namespace.svc.cluster.local", "svc.cluster.local", "cluster.local" and "local" domains and forwarded to the internal DNS server. This is done by Dnsmasq, as configured from /etc/dnsmasq.d/origin-dns.conf:

server=/cluster.local/172.30.0.1 

This configuration tells Dnsmasq to forward all queries for names in the "cluster.local" domain and sub-domains to the internal DNS server listening on 172.30.0.1.

This is an example of such query (where 192.168.122.17 is the IP address of the local node on which Dnsmasq binds, and 172.30.254.155 is a service IP address) :

nslookup logging-es.logging.svc.cluster.local
Server:		192.168.122.17
Address:	192.168.122.17#53

Name:	logging-es.logging.svc.cluster.local
Address: 172.30.254.155

The non-OpenShift name requests are forwarded to the real DNS server stored in /etc/dnsmasq.d/origin-upstream-dns.conf:

server=192.168.122.12

The configuration file /etc/dnsmasq.d/origin-dns.conf is deployed at installation, while /etc/dnsmasq.d/origin-upstream-dns.conf is created dynamically every time the external DNS changes, as it is the case for example when the interface receives a new DHCP IP address.

For more details, see

Dnsmasq

Container /etc/resolv.conf

The container /etc/resolv.conf is created while the container is being assembled, based on information available in node-config.yamll. Also see:

External OpenShift DNS Resources

Routing Layer

OpenShift networking provides a platform-wide routing layer that directs outside traffic to the correct pods IPs and ports. The routing layer cooperates with the service layer. Routing layer components run themselves in pods. They provide automated load balancing to pods, and routing around unhealthy pods. The routing layer is pluggable and extensible. For more details about the overall OpenShift workflow, see "OpenShift Workflow".

Router

https://docs.openshift.com/container-platform/3.5/install_config/router/index.html
https://docs.openshift.com/container-platform/3.5/architecture/core_concepts/routes.html
https://docs.openshift.com/container-platform/latest/install_config/router/index.html

The router service routes external requests to applications inside the OpenShift environment. The router service is deployed as one or more pods. The pods associated with the router service are deployed as infrastructure containers on infrastructure nodes. A router is usually created during the installation process. Additional routers can be created with oadm router.

The router is the ingress point for all traffic flowing to backing pods implementing OpenShift Services. Routers run in containers, which may be deployed on any node (or nodes) in an OpenShift environment, as part of the "default" project. A router works by resolving fully qualified DNS external names ("kibana.apps.openshift.novaordis.io") external requests are associated with into pod IP addresses and proxying the requests directly into the pods that back the corresponding service. The router gets pod IPs from the service, and proxies the requests to pods directly, not through the Service.

Routers directly attach to port 80 and 443 on all interfaces on a host, so deployment of the corresponding containers should be restricted to the infrastructure hosts where those points are available. Statistics are usually available on port 1936.

Relationship between Service and Router

When the default router is used, the service layer is bypassed. The Service is used only to find which pods the service represents. The default router does the load balancing by proxying directly to the pod endpoints.

OpenShiftRouterConcepts.png

Sticky Sessions

The router configuration determines the sticky session implementation. The default HAProxy template implements sticky session using balance source directive.

Router Implementations

HAProxy Default Router

https://docs.openshift.com/container-platform/3.5/architecture/core_concepts/routes.html#haproxy-template-router

By default, the router process is an instance of HAProxy, referred to as the "Default Router". It uses "openshift3/OpenShift Container Platform-haproxy-router" image, and it supports unsecured, edge-terminated, re-encryption terminated and passthrough terminated routes matching on HTTP host and request path.

F5 Router

The F5 Router integrates with existing F5 Big-IP systems.

Router Operations

Information about the existing routers can be obtained with:

 oadm router -o yaml

More details on router operations are available here:

Router Operations

Route

Logically, a route is an external DNS entry, either in a top level domain or a dynamically allocated name, that is created to point to an OpenShift service so that the service can be accessed outside the cluster. The administrator may configure one or more routers to handle those routes, typically through an Apache or HAProxy load balancer/proxy.

The route object describes a service to expose by giving it an externally reachable DNS host name.

A route is a mapping of an FQDN and path to the endpoints of a service. Each route consist of a route name, a service selector and an optional security configuration:

NAME             HOST/PORT                            PATH      SERVICES         PORT      TERMINATION          WILDCARD
logging-kibana   kibana.apps.openshift.novaordis.io             logging-kibana   <all>     reencrypt/Redirect   None

A route can be unsecured or secured.

The secure routes specify the TLS termination of the route, which relies on SNI (Server Name Indication). More specifically, they can be:

  • edge secured (or edge terminated). Occurs at the router, prior to proxying the traffic to the destination. The front end of the router serves the TLS certificates, so they must be configured in the route. If the certificates are not configured in the route, the default certificate of the router is used. Connection from the router into the internal network are not encrypted. This is an example of edge-termintated route.
  • passthrough secured (or passthrough terminated). The encrypted traffic is send to to destination, the router does not provide TLS termination, hence no keys or certificates are required on the router. The destination will handle certificates. This method supports client certificates. This is an example of passthrough-termintated route.
  • re-encryption terminated secured. This is an example of re-encyrption-termintated route.
Route Definition

Routes can be displayed with the following commands:

oc get all
oc get routes

Routes can be created with API calls, an JSON or YAML object definition file or the oc expose service command.

Path-Based Route

A path-based route specifies a path component, allowing the same host to server multiple routes.

Route with Hostname

Routes let you associate a service with an externally reachable hostname. If the hostname is not provided, OpenShift will generate on based on the <routename>-.<namespace>].<suffix> pattern.

Default Routing Subdomain

The suffix and the default routing subdomain can be configured in the master configuration file.

Route Operations

Route Operations

Networking Workflow

The networking workflow is implemented at the networking layer.

  • A user requests a page by pointing the browser to http://myapp.mydomain.com
  • The external DNS server resolves that request to the IP address of one of the hosts that host the default router. That usually requires a wildcard C name in the DNS server pointed to the node that hosts the router container.
  • Default Router selects the pod from the list of pods listed by the service and acts as a proxy for that pod (this is where the port can be translated from the external 443 to the internal 8443, for example).

Resources

  • cpu, requests.cpu
  • memory, requests.memory
  • limits.cpu
  • memory.cpu
  • pods
  • replicationcontrollers
  • resourcequotas
  • services
  • Secrets
  • configmaps
  • persistentvolumeclaims
  • openshif.io/imagestreams

Most resources can be defined in JSON or YAML files, or via an API call. Resources can be exposed via the downward API to the container.

Resource Management

Resource Management

Project

Projects allows groups of users to work together, define ownership of resources and manage resources - they can be seen as the central vehicle for managing regular users' access to resources. The project restricts and tracks use of resources with quotas and limits. A project is a Kubernetes namespace with additional annotations. A project can contain any number of containers of any kind, and any grouping or structure can be enforced using labels. The project is the closest concept to an application, OpenShift does not know of applications, though it provides a new-app command. A project lets a community of users to organize and manage their content in isolation from other communities. Users must be given access to projects by administrators—unless they are given permission to create projects, in which case they automatically have access to their own projects.

Most objects in the system are scoped by a namespace, with the exception of:

More details about OpenShift types are available here OpenShift types.

Each project has its own set of objects: pods, services, replication controllers, etc. The names of each resource are unique within a project. Developers may request projects to be create, but administrators control the resources allocated to the projects.

What actions a user can or cannot perform on a project's objects are specified by policies.

Constraints are quotas for each kind of object that can be limited.

New projects are created with:

oc new-project

Current Project

The current project is a concept that applies to oc, and specifies the project oc commands apply to, without to explicitly having to use the -n <project-name> qualifier. The current project can be set with oc project and read with oc status. The current project is part of the CLI tool's current context, maintained in user's .kube/config.

Global Project

In the context of an ovs-multitenant SDN plugin, a project is global if if can receive cluster network traffic from any pods, belonging to any project, and it can send traffic to any pods and services. Is the default project a global project?. A project can be made global with:

oadm pod-network make-projects-global <project-1-name> <project-2-name>

Standard Projects

Default Project

The "default" project is also referred to as "default namespace". It contains the following pods:

  • the integrated docker registry pod (memory consumption based on a test installation: 280 MB)
  • the registry console pod (memory consumption based on a test installation: 34 MB)
  • the router pod (memory consumption based on a test installation: 140 MB)

In case the ovs-multitenant SDN plug-in is installed, the "default" project has VNID 0 and all its pods can send and receive traffic from any other pods.

The "default" project can be used to store a new project template, if the default one needs to be modified. See Template Operations - Modify the Template for New Projects.

"logging" Project

If logging support is deployed at installation or later, the participating pods (kibana, ElasticSearch, fluentd, curator) are members of the "logging" project.

This is the memory consumption based on a test installation:

  • kibana pod: 95 MB
  • elasticsearch pod: 1.4GB
  • curator pod: 10 MB
  • fluentd pods max 130 MB

"openshift-infra" Project

Contains the metrics components:

"openshift" Project

Contains standard templates and image streams. Images to use with OpenShift projects can be installed during the OpenShift installation phase, or they can be added later running command similar to:

oc -n openshift import-image jboss-eap64-openshift:1.6

Other Standard Projects

  • "kube-system"
  • "management-infra"

Projects and Applications

Each project may have multiple applications, and each application can be managed individually.

A new application is created with:

oc new-app

The "app" Label

TODO: app vs. application

There is no OpenShift object that represent an applications. However, the pods belonging to a specific application are grouped together in the Web console project window, under the same "Application" logical category. The grouping is done based on the "app" label value: all pods with the same "app" label value are represented as belonging to the same "application". The "app" label value can be explicitly set in the template that is used to instantiate the application with, in the "labels:" section. Some templates expose this as parameter, so it can be set on command line with a syntax similar to:

--param APPLICATION_NAME=<application-name>

Application Operations

Application Operations

Project Operations

Project Operations

Template

https://docs.openshift.com/container-platform/latest/dev_guide/templates.html
https://docs.openshift.org/latest/dev_guide/templates.html

A template is a resource that describes a set of objects that can be parameterized and processed, so they can be created at once. The template can be processed to create anything within a project, provided that permissions exist. The template may define a set of labels to apply to every object defined in the template. A template can use preset variables or randomized values, like passwords.

Templates can be stored in, and processed from files, or they can be exposed via the OpenShift API and stored as part of the project. Users can define their own templates within their projects.

The objects define in a template collectively define a desired state. OpenShift's responsibility is to make sure that the current state matches the desired state.

Template Definition

Specifying parameters in a template allows all objects instantiated by the template to see consistent values for these parameters when the template is processed. The parameters can be specified explicitly, or generated automatically.

The configuration can be generated from template with oc process command.

Most templates use pre-built S2I builder images, that includes the programming language runtime and its dependencies. These builder images can also be used by themselves, without the corresponding template, for simple use cases.

New Project Template

The master provisions projects based on the template that is identified by the "projectRequestTemplate" in master-config.yaml file. If nothing is specified there, new projects will be created based on a built-in new project template that can be obtained with:

oadm create-bootstrap-project-template -o yaml

New Application Template

oc new-app <template-name>

Template Libraries

Template Operations

Template Operations

Build

https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html

A build is the process of transforming input parameters into a resulting object. In most cases, that means transforming source code, other images, Dockerfiles, etc. into a runnable image. A build is run inside of a privileged container and has the same restrictions normal pods have. A build usually results in an image pushed to a Docker registry, subject to post-build tests. Builds are run with the builder service account, which must have access to any secrets it needs, such as repository credentials - in addition to the builder service account having to have access to the build secrets, the build configuration must contain the required build secret. Builds can be triggered manually or automatically.

OpenShift supports several types of builds. The type of build is also referred to as the build strategy:

Builds for a project can be reviewed by navigating with the web console to the project -> Builds -> Builds or invoking oc get builds from command line. Note these are actual executed builds, not build configurations.

Build Strategy

Docker Build

Docker can be used to build images directly. The Docker build expects a repository with Dockerfile and all artifacts required to produce runnable image. It invokes the docker build command, and the result is a runnable image.

Create a Docker Build

Source-to-Image (S2I) Build

https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html#source-build
https://docs.openshift.com/container-platform/latest/creating_images/s2i.html#creating-images-s2i

A source to image build strategy is a process that takes a base image, called the builder image, application source code and S2I scripts, compiles the source and injects the build artifacts into the builder image, producing a ready-to-run new Docker image, which is the end product of the build. The image is then pushed into the integrated Docker registry.

The essential characteristic of the source build is that the builder image provides both the build environment and the runtime image in which the build artifact is supposed to run in. The build logic is encapsulated within the S2I scripts. The S2I scripts usually come with builder image, but they can also be overridden by scripts placed in the source code or in different location, specified in the build configuration. OpenShift supports a wide variety of languages and base images: Java, PHP, Ruby, Python, Node.js. Incremental builds are supported. With a source build, the assemble process performs a large number of complex operations without creating a new layer at each step, resulting in a compact final image.

The source strategy is specified in the build configuration as follows:

kind: BuildConfig
spec: 
  strategy:
     type: Source
     sourceStrategy:
       from:
          kind: ImageStreamTag
          name: jboss-eap70-openshift:1.5
          namespace: openshift
  source:
    type: Git
    git:
      uri: ...
  output:
    to:
      kind: ImageStreamTag
      name: <app-image-repository-name>:latest

The builder image is specified with a 'spec.strategy.sourceStrategy.from' element. Source code origin is specified with 'spec.strategy.source' element. Assuming that the build is successful, the resulted image is pushed into the ? image stream and tagged with the 'output' image stream tag.

A working S2I Build Example is available here:

OpenShift Build and Deploy a JEE Application with S2I

An example to create a source build configuration from scratch is available here:

Create a Source Build

The Build Process

For a source build, the build process takes place in the builder image container. It consists in the following steps:

  • Download the S2I scripts.
  • If it is an incremental build, save the previous build's artifacts with save-artifacts.
  • A work directory is created.
  • Pull the source code from the repository into the work directory.
  • Heuristics is applied to detect how to build the code.
  • Create a TAR that contains S2I scripts and source code.
  • Untar S2I scripts, sources and artifacts.
  • Invoke the assemble script.
  • The build process changes to 'contextDir' - anything that resides outside 'contextDir' is ignored by the build.
  • Run build.
  • Push image to docker-registry.default.svc:5000/<project-name>/...

Builder Image

The builder image is an image that must contain both compile time dependencies and build tools, because the build process take place inside it, and runtime dependencies and the application runtime, because the image will be used to create containers that execute the application. The builder image must also contain the tar archiving utility, available in $PATH, which is used during the build process to extract source code and S2I scripts, and the /bin/sh command line interpreter. A builder image should be able to generate some usage information by running the image with docker run. An article that shows how to create builder images is available here: https://blog.openshift.com/create-s2i-builder-image/.

Extended Build

An extended build uses a builder image and a runtime image as two separate images. In this case the builder image contains the build tooling but not the application runtime. The runtime image contains the application runtime. This is useful when we don't want the build tooling laying around in the runtime image.

S2I Scripts

The S2I scripts encapsulate the build logic and must be executable inside the builder image. They must be provided as an input of the source build and play an essential role in the build process. They come from one of the following locations, listed below in the inverse order of their precedence (if the same script is available in more than one location, the script from the location listed last in the list is used):

  • Bundled with the builder image, in a location specified as "io.openshift.s2i.scripts-url" label. A common value is "image:///usr/local/s2i". As an example, these are the S2I scripts that come with an EAP7 builder image: assemble, run and save-artifacts.
  • Bundled with the source code in an .s2i/bin directory of the application source repository.
  • Published at an URL that is specified in the build configuration definition.

Both the "io.openshift.s2i.scripts-url" label value specified in the image and the script specified in the build configuration can take one of the following forms:

  • image:///<path-to-script-directory> - the absolute path inside the image.
  • file:///<path-to-script-directory> - relative or absolute path to a directory on the host where the scripts are located.
  • http(s)://<path-to-script-directory> - URL to a directory where the scripts are located.

The scripts are:

assemble

This is a required script. It builds the application artifacts from source and places them into appropriate directories inside the image. The script's main responsibility is to turn source code into a runnable application. It can also be used to inject configuration into the system.

It should execute the following sequence:

  • Restore build artifacts, if the build is incremental. In this case save-artifacts must be also defined.
  • Place the application source in the build location.
  • Build.
  • Install the artifacts into locations that are appropriate for them to run.

EAP7 builder image example: assemble.

run

This is a required script. It is invoked when the container is instantiated to execute the application.

EAP7 builder image example: run.

save-artifacts

This is an optional script, needed when incremental builds are enabled. It gathers all dependencies that can speed up the build process, from the build image that has just completed the successful build (the Maven .m2 directory, for example). The dependencies are assembled into a tar file and streamed to standard output.

EAP7 builder image example: save-artifacts.

usage

This is an optional script. Informs the user how to properly use the image.

test/run

This is an optional script. Allows to create a simple process to check whether the image is working correctly. For more details see:

https://docs.openshift.com/container-platform/latest/creating_images/s2i_testing.html#creating-images-s2i-testing

Incremental Build

The source build may be configured as an incremental build, which re-uses the previously downloaded dependencies and previously built artifacts, in order to speed up the build. Incremental builds reuse previously downloaded dependencies, previously built artifacts, etc.

strategy
  type: "Source"
  sourceStrategy:
    from:
       ...
    incremental: true

Webhooks

A source build can be configured to be automatically trigged when a new event - most commonly a push - is detected by the source repository. When the repository identifies a push, or any other kind of event it was configured for, it makes a HTTP invocation into an OpenShift URL. For internal repositories that run within the OpenShift cluster, such as Gogs, the URL is https://openshift.default.svc.cluster.local/oapi/v1/namespaces/<project-name>/buildconfigs/<build-configuration-name>/webhooks/<generic-secret-value>/generic. The secret value can be manually configured in the build configuration, as shown here, but it is usually set to a randomly generated value when the build configuration is created. For an external URL, such as GitHub, the URL must be publicly accessible TODO. Once the build is triggered, it proceed as it would otherwise proceed if it was triggered by other means. Note that no build server is required for this mechanism to work, though a build server such as Jenkins can be integrated and configured to drive a pipeline build.

The detailed procedure to configure a webhook trigger is available here:

Configure a Webhook Trigger for a Source Build

Tagging the Build Artifact

Once the build process (the assemble script) completes successfully, the build runtime sets the image's command to the run script, and tags the image with the output name specified in the build configuration.

TODO. How to tag the output image with a dynamic tag that is generated from the information in the source code itself?

MAVEN_MIRROR_URL

TODO 'MAVEN_MIRROR_URL' is an environment variable interpreted by the s2i builder, which use the Maven repository whose URL is specified as a source of artifacts. For more details see:

OpenShift Nexus

Pipeline Build

https://docs.openshift.com/container-platform/latest/architecture/core_concepts/builds_and_image_streams.html#pipeline-build
https://docs.openshift.com/container-platform/latest/install_config/configuring_pipeline_execution.html#install-config-configuring-pipeline-execution
https://docs.openshift.com/container-platform/latest/dev_guide/dev_tutorials/openshift_pipeline.html

The pipeline build strategy allows the developers to defined the build logic externally, as a Jenkins Pipeline. The logic is executed by an OpenShift-integrated Jenkins instance, which uses a series of specialized plug-ins to work with OpenShift. More details about how OpenShift and Jenkins interact are available in the OpenShift CI/CD Concepts page. The specification of the build logic can be embedded directly into an OpenShift build configuration object, as shown below, or it can be specified externally into a Jenkinsfile which is then later automatically integrated with OpenShift. The build can then be started, monitored, and managed by OpenShift in the same way as any other build type, but it can at the same time be managed from the Jenkins UI - these two representations are kept in sync. The pipeline's graphical representation is available both in the integrated Jenkins instance and it OpenShift directly, as a "Pipeline":

OpenShiftPipeline.png

The pipeline build strategy is specified in the build configuration as follows:

kind: BuildConfig
spec: 
  strategy:
     type: JenkinsPipeline
     jenkinsPipelineStrategy:
       jenkinsfile: |-
            node('mvn') {

                //
                // Groovy script that defines the pipeline 
                //
            }
  source:
    type: none
  output: {}

This is an example of specifying the build logic inline in the build configuration. It is also possible to specify the build logic externally in a Jenkinsfile. Note that unlike in the source build's case, no "output" are specified, because this is fully defined in the Jenkins Groovy script. "source" may be used to specify a source repository URL that contains the Jenkinsfile pipeline definition.

An example of how to create a pipeline build configuration from scratch is available here:

Create a Pipeline Build

CI/CD

OpenShift enables DevOps. It has built-in support for the Jenkins CI server, providing a native way of doing Continuous Integration and Continuous Delivery.

OpenShift CI/CD Concepts
OpenShift CI/CD Operations

Custom Build

The custom build strategy allows to define a specific builder image responsible for the entire build process, which allows you to customize the build process.

The custom builder image is a plain Docker image embedded with build process logic.

Chained Builds

Two builds may be chained: one produces binaries from a builder image and source, and pushes the artifacts into an image stream; the other pulls the binaries produces by the first build from the image stream and places them into a runtime image, based on a Dockerfile, A separated image is thus created.

Build Configuration

A BuildConfig object is the definition of an entire build. It contains a description of how to combine source code and a base image to produce a new image. The BuildConfig lists the location of the source code, the build triggers, the build strategy, various other build configuration parameters, such as maximum allowed duration, and the specification of the output of the build, which is in most cases a Docker container that gets pushed into the integrated registry. Both oc new-app and oc new-build create BuildConfig objects. The preferred way to create a build configuration is to start with oc new-build and customize the resulted build configuration:

Create a Build Configuration with oc new-build
Build Configuration Definition

Generally, immediately after the build configuration is declared, a build starts, and if it successful, a new image will be pushed into the artifact image stream.

Build Trigger

Builds can be triggered by the following events:

TODO: when does a build start automatically and when doesn't.

github, generic, gitlab, bitbucket

Source code change signaled by a GitHub webhook or a generic webhook. An internal repository repository must be configured to invoke into an URL similar to https://openshift.default.svc.cluster.local/oapi/v1/namespaces/$CICD_PROJECT/buildconfigs/<application-name>/webhooks/${WEBHOOK_SECRET}/generic. An external repository must be configured to invoke either into Jenkins using a URL similar to ? or into the associated build configuration, using an URL similar to ?.

ImageChange

https://docs.openshift.com/container-platform/3.7/dev_guide/deployments/basic_deployment_operations.html#image-change-trigger

Base image change, in case of source-to-image builds.

Build Configuration Change

https://docs.openshift.com/container-platform/3.7/dev_guide/deployments/basic_deployment_operations.html#config-change-trigger

Manual Build

Manual with oc start-build.

Build Source

A build configuration accepts the following type of sources:

Build Secrets

The source element may refer to build secrets:

kind: BuildConfig
...
spec:
  ...
  source:
    ...
    sourceSecret:
      name: some-secret

Build Node Selection

Build can be assigned to specific nodes, by specifying labels in the "nodeSelector" field of the build configuration:

kind: BuildConfig
...
spec:
  nodeSelector:
    env: app

Build Resources

Can be setup in the build configuration:

kind: BuildConfig
spec:
  resources:
    limits:
      cpu: ...
      memory: ...

Build Operations

Build Operations

Image

https://docs.openshift.com/container-platform/latest/architecture/core_concepts/containers_and_images.html#docker-images

An OpenShift image represents a immutable container image in Docker format. Images are not project-scoped, but cluster-scoped: any user from any project can get information about any image in the cluster with oc get images, provided that it has sufficient cluster-level privileges. One role that permits inspecting image information is /cluster-reader . On the other hand, a user that only has project-level privileges cannot inspect images.

Information about a specific image can be obtained with oc get image <image-name>

OpenShift Image Definition

Image Name

An image is identified by a name, which is the SHA256 hash of the image: "sha256:ea573da7c263e68f2d021c63bec218b79699a0b48e58b3724360de9c6900ca46". The name can be local to the current cluster - the images produced as artifacts of the cluster's project do not exist anywhere else, until they are explicitly published - or point to a remote Docker registry. An OpenShift cluster usually comes with its own integrated Docker registry, accessible to all projects, whose main function is to store images produced by the projects as result of build activities.

Image Reference

The image contains a "dockerImageReference" entry that maintains the location the image can be found at:

docker-registry.default.svc:5000/novaordis-dev/tasks@sha256:41976593d219eb2008a533e7f6fbb17e1fc3391065e2d592cc0b05defe5d5562
registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift@sha256:ea573da7c263e68f2d021c63bec218b79699a0b48e58b3724360de9c6900ca46

Image Stream

An image stream is similar to a Docker image repository, in that it contains a group of related Docker images identified by image stream tags.

The difference in referencing an image stream (or a tag within an image stream) instead of referencing a image registry/namespace/repository:tag directly is that actions can be triggered automatically when the underlying image changes. These actions may include functionality to control when image updates are rolled out.

Logically it is analogous to a branch in a source code repository. The image stream presents a single virtual view of related images and allow you to control which images are rolled out to your builds and applications. The stream may contain images from the OpenShift integrated Docker registry, other image streams, other image repositories. OpenShift stores complete metadata about each image, including example command, entry point and environment variables.

Image Stream Definition

Image streams exist as OpenShift objects, describable with oc get is, but they also have a representation in the cluster's integrated docker repository docker-registry.default.svc:5000/, as project-name/image-stream-name. As an example, for a "blue-project" and a "red-is":

kind: ImageStream
metadata:
  ...
  name: red-is
  namespace: blue-project
spec:
  tags:
  - name: latest
    from: 
      kind: DockerImage
      name: registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift

ImageStreamInRegistry.png

Example of a JSON file that can be used to create image streams in OpenShift:

https://github.com/openshift/origin/blob/master/examples/image-streams/image-streams-rhel7.json

Builds and deployments can watch an image stream to receive notifications when new images are added and react by performing a build or a deployment.

Operations:

ImageStream Operations

"openshift" Image Streams

A set of standard image streams come pre-configured in the "openshift" project of an OpenShift installation, but image streams can be created in any project.

Image Stream Lookup Policy

The lookup policy specifies how other resources reference this image within this namespace.

Possible values:

  • local - will change the docker short image reference, such as "mysql" or "php:latest" on objects in this namespace to the image ID whenever they match this image stream, instead of reaching out to a remote registry. The name will be fully qualified to an image ID if found. The gag's referencePolicy is taken into account on the replaced value. It only works within the current namespace.

Image Stream Tag

The default tag is called "latest". A tag may point to an external Docker registry, at other tags in the same image stream, a different image stream, or be controlled to directly point to known images. An image stream tag full name is <image-stream-name>:<tag-name>. For example, the tag "0.11.29" exposed by the "gogs" image stream as shown here:

...
kind: ImageStream
metadata:
  name: gogs
spec:
  tags:
  - name: "0.11.29"
    ...

is referred to by a deployment configuration as:

...
triggers:
- type: ImageChange
   imageChangeParams:
     ...
     from:
       kind: ImageStreamTag
       name: gogs:0.11.29

Images can be pushed to an image stream tag directly via the integrated Docker registry.

The image stream tag has a referencePolicy, which defines how other components should consume this image. The reference policy's type determines how the image pull spec should be transformed when the image stream tag is used in deployment configuration triggers or new builds. The default value is "Source", indicating the original location of the image should be used (if imported). The user may also specify "Local", indicating that the pull spec should point to the integrated Docker registry and leverage the registry's ability to proxy the pull to an upstream registry. "Local" allows the credentials used to pull this image to be managed from the image stream's namespace, so others on the platform can access a remote image but have no access to the remote secret. It also allows the image layers to be mirrored into the local registry which the images can still be pulled even if the upstream registry is unavailable.

Image Pull Policy

When the container is created, the runtime uses the "imagePullPolicy" to determine whether to pull the image prior to starting the container. More details available here:

Pod Definition - imagePullPolicy

To Process

Deployment

https://docs.openshift.com/container-platform/latest/architecture/core_concepts/deployments.html
https://docs.openshift.com/container-platform/latest/dev_guide/deployments/how_deployments_work.html

A deployment is a replication controller based on a user-defined template called a deployment configuration: a successful deployment results in a new replication controller being created.

A deployment adds extended support for software development and deployment lifecycle. Deployments are created manually or in response to triggered events, and the most common events that trigger a deployment are either an image change or a configuration change.

The deployment system provides a deployment configuration, which is a template for deployments, triggers that drive automated deployments in response to events, user-customizable strategies to transition from the previous deployment to the new deployment, rollback procedure, and manual replication scaling. Deployment configuration version increments each time new deployment is created from configuration. Deployments allow defining hooks to be run before and after the replication controller is created.

Deployments allow rollbacks.

Deployments allow manual replication scaling or autoscaling.

The deployments are triggered with oc deploy.

Deployment Configuration

A deployment configuration is a user-defined template for performing deployments, which result in running applications. The deployment configuration defines the template for a pod. It manages deploying new images or configuration changes whenever those change. A single deployment configuration is usually analogous to a single micro service.

Each deployment is represented as a replication controller. The OpenShift environment creates a replication controller to run the application in response to a deployment configuration. The deployment configuration contains a version number that is incremented each time a replication controller is created from the configuration.

Deployment configurations can support many different deployment patterns, including full restart, customizable rolling updates, and fully custom behaviors, as well as pre- and post-hooks. It supports automatic rolling back to the last successful revision of configuration, in case the current template fails to deploy.

The DeploymentConfig contains:

  • Replication controller definition.
  • Default replica count fo the deployment.
  • Triggers for creating new deployments automatically, in response to events. If no triggers are defined, deployments must be started manually.
  • Strategy for transitioning before deployments.
  • Life-cycle hooks. Every hook has a failure policy (Abort, Retry, Ignore).
DeploymentConfig Definition

The DeploymentConfig for a project can be listed with:

oc get all
oc get dc

Deployment Triggers

The deployment triggers are specified in the deployment configuration, and can be modified from command line:

ConfigChange

Results in a new deployment, and a new replication controller being created whenever changes are detected to replication controller template of deployment configuration. In the presence of a ConfigChange trigger, the first replication controller is automatically created when the deployment configuration itself is created.

ImageChange

The deployment trigger is a change in the image stream. If we do not want the result of a build to be deployed automatically, even if the build pushes a new image in the repository, we simply do not list the "ImageChange" deployment trigger in the deployment configuration.

Replication Controller

A replication controller is one of the pod controller types available in OpenShift. It resides on master, and insures that the specified number of pod replicas defined in the replication controller configuration are running at all times.

Logically, the replication controllers constitute the replication layer.

The definition of a replication controller includes the number of replicas to be maintained, the pod definition for creating the replicated pod, and a selector for identifying managed pods. If pods exit or are deleted, either explicitly or because the node they run on is taken out of service, the replication controller instantiates more pods up to desired number. If there are more pods running than desired, the replication controller deletes as many as necessary. However, it is NOT the replication controller's job to perform autoscaling based on load or traffic. Replication controllers do not exist as physical processes, meaning they do not run in pods, they only exist as entries in etcd, and the master executes the logic.

A replication controller is most commonly used to represent a single deployment of part of an application based on a built image.

There were situations when a failed deployment can be re-started by deleting the replication controller.

The replication controllers of a project can be listed with:

oc get all
oc get rc

Rollout

A rollout is exposed as a replication controller, and the deployment process manages scaling down old replication controllers and scaling up new ones. Implements one of the deployment strategies. The rollout is performed with:

oc rollout

Deployment Configurations and Replication Controllers

A deployment configuration triggers creation of a replication controller.

Deleting a deployment configuration will automatically delete the replication controllers generated by that deployment configuration.

Rollback

Deployments allow rollbacks to previous versions of an application: when one deployment is superseded by another, the previous replication controller is retained, with its number of replicas set to 0. When triggered - the template fails to deploy -, the rollback reverts an application to the last successful deployment. It is done with oc rollback, API or web console.

Deployment Strategy

The deployment configuration defines a deployment strategy. The deployment strategy determines the deployment process and it is defined by the deployment configuration. The deployment strategy uses readiness checks to determine if a new host is ready for use. If the readiness check fails, the deployment configuration retries until it times out. The readiness timeout value is set in deployment configuration.

The deployment strategy is implemented during the rollout process.

Rolling Deployment Strategy

The default deployment strategy, if a deployment strategy is not explicitly specified in the deployment configuration. It performs rolling updates. It supports life-cycle hooks for injecting code into the deployment process.

It consists in the following steps:

  • Execute the "pre" life-cycle hook.
  • Scale up new deployment by one or more pods, based on maxSurge value, waiting until all readiness checks complete.
  • Scale down the old deployment by one or more pods, based on maxUnavailable value.
  • Repeat scaling until the new deployment reaches desired replica count and the old deployment has scaled to zero.
  • Execute any "post" life-cycle hook.

When scaling down, the strategy waits for pods to become ready, so it can decide if can further scaling would affect availability. If scaled up pods never become ready, the deployment times up and results in a deployment failure.

Recreate Deployment Strategy

Recreate strategy is appropriate when the application does not support old versions and new versions running together, or when the application uses ReadWriteOnce volumes that do not support sharing between multiple replicas.

The recreate strategy implies downtime: there is a time interval when on application instance is running.

It consists in the following steps:

  • Execute "pre" life-cycle hook.
  • Scale down previous deployment to zero.
  • Scale up new deployment.
  • Execute "post" life-cycle hook.

During scale up, if the replica count of the deployment is greater than one, the first deployment replica is validated for readiness before fully scaling up the deployment. If this validation fails, the deployment fails.

...
kind: DeploymentConfig
spec:
  strategy:
    activeDeadlineSeconds: 21600
    type: Recreate
    recreateParams:
      pre:
      mid:
      post:
      timeoutSeconds:     

Parameters:

  • activeDeadlineSeconds: the duration in seconds that the deployer pods for this deployment may bee active on a node before the system actively tries to terminate them.

Custom Deployment Strategy

Allows for custom commands.

The optional "command" array overrides the CMD directive specified in the Dockerfile.

The optional "environment" variables are added to the strategy process' execution.

Deployment Operations

Deployment Operations

Environment Variables to Use for Strategy Process

  • OPENSHIFT_DEPLOYMENT_NAME
  • OPENSHIFT_DEPLOYMENT_NAMESPACE

To Process

Region

Zone

High Availability (HA)

Infrastructure HA

See Master HA.

Application HA

OpenShift insures high availability by deploying the same image in multiple containers across multiple hosts and load balancing among them. This technique also provides horizontal scalability for a service packaged into an image.

Installation

There are two installation procedures: RPM and Containerized.

An RPM installation installs all services through package management and configures services to run within the same user space,

A containerized installation installs services using container images and runs separate services in individual containers.

For practical details on installing various OpenShift version, see:

OpenShift Installation

Related:

OpenShift Logging Installation

Installation is performed by Ansible, usually deployed on the environment's support server. Ansible configuration is available under /etc/ansible and the installation logic under /usr/share/ansible.

Metrics

OpenShift Metrics Concepts

Horizontal Pod Autoscaler (HPA)

https://docs.openshift.com/container-platform/latest/dev_guide/pod_autoscaling.html#dev-guide-pod-autoscaling

Logging

OpenShift Logging Concepts

Events

https://docs.openshift.com/container-platform/3.5/dev_guide/events.html

OpenShift events incapsulate information about specific conditions detected in the OpenShift cluster, and allow the OpenShift management facilities to record information about those occurrences in a resource-agnostic manner. They also allow administrators and developers to consume information about system components in a unified way. A list of events can be obtained with:

oc get events [-n <project-name>]

Events for a project can be reviewed by navigating with the web console to the project -> Monitoring -> Right Side.

Events contain:

  • type: Normal, Warning
  • kind: Configuration, Node, Pod, DaemonSet, Container, Health, Image, Image Manager, System.
  • reason
  • source
  • message

Event Reasons

  • FailedScheduling
  • OutOfDisk
  • MatchNodeSelector
  • SuccessfulCreate

Command Line Tools

OpenShift Command Line Tools (CLI)

Admission Control

https://docs.openshift.com/container-platform/latest/architecture/additional_concepts/admission_controllers.html

Admission control plug-ins intercept requests to the master API, after authentication and authorization was enforced. There's a chain of plug-ins (also known as the admission chain), and if a plug-in rejects the request, the request fails. The plug-in may modify the request object, and related resources. The default list of admission control plug-ins is configured in the master-config.yaml's admissionConfig/pluginConfig section.

Customizable admission control plug-ins:

OpenShift and JBoss

OpenShift and JBoss

Jobs

https://docs.openshift.com/container-platform/latest/dev_guide/jobs.html
apiVersion: batch/v1
kind: Job

Cron Jobs

https://docs.openshift.com/container-platform/latest/dev_guide/cron_jobs.html
apiVersion: batch/v1
kind: CronJob

Configuration Data Externalization

Configuration data must never be stored in application source code, but it must externalized on storage.

Environment Variables

Environment Variables

Custom Metadata Annotations

Custom metadata annotations can be specified in the spec.template.metadata.annotations section of the deployment configuration. Those annotations will be injected into the pod metadata, and will be accessible from the pod with the Downward API.

Common Images