Introducing Red Hat OpenShift 4

Part1: An Introduction to Kubernetes



bit.ly/v4intro-part1

April 16, 2019, 11:00 a.m. PDT

presented by Ryan Jarvinen (@RyanJ), Developer Advocate at Red Hat

## Kubernetes is...
## Kubernetes is a way to manage collections of processes over groups of machines

Kubernetes is

an Enterprise-grade distributed process scheduler (multi-machine, cluster-scale)

that provides declarative controls (json/yaml)

for managing workloads (collections of highly-available, production-quality processes)

Including a highly-available

Control Plane


A group of machines (nodes) that are responsible for hosting core platform services

Kubernetes provides… # An API API resources usually include the following attributes: ``` kind apiVersion metadata spec status ``` Extended Kubernetes API Reference: http://k8s.io/docs/reference/generated/kubernetes-api/v1.12/
Kubernetes uses ## etcd to keep track of the cluster's state ![etcd logo](https://raw.githubusercontent.com/coreos/etcd/master/logos/etcd-glyph-color.png) * a distributed key-value store * implements the [RAFT](https://raft.github.io/raft.pdf) consensus protocol
## Etcd cluster sizes Fault-tolerance sizing chart: ![etcd cluster sizing chart](http://cloudgeekz.com/wp-content/uploads/2016/10/etcd-fault-tolerance-table.png)
### Basic K8s Terminology 1. [node](#/node) 2. [pod](#/po) 3. [service](#/svc) 4. [deployment](#/deployment) 5. [replicaSet](#/rs)
### Nodes A node is a host machine (physical or virtual) where containerized processes are run. Activity on each Node is managed by a `kubelet` process, which receives workload scheduling instructions from the Control Plane.
### Pods A group of one or more co-located containers.

Starting a Pod from the Command-Line

Create a new resource from a json object specification:

kubectl create -f https://raw.githubusercontent.com/jankleinert/hello-workshop/master/pod.json
{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "creationTimestamp": null,
    "name": "hello-k8s",
    "labels": {
      "run": "hello-k8s"
    }
  },
  "spec": {
    "containers": [
      {
        "name": "hello-k8s",
        "image": "jkleinert/devweek-workshop",
        "ports": [
          {
            "containerPort": 8080
          }
        ],
        "resources": {}
      }
    ]
  }
}
### Pod attributes: * Automatic health checking for PID1 in each container * Pods are scheduled to be run on nodes * Pods represent your minimum increment of scale
### Services Services (svc) establish a single endpoint for a collection of replicated pods, distributing traffic based on label selectors In our K8s modeling language they represent a load balancer. Their implementation may vary per cloud provider

Contacting your App

Expose the pod by creating a new service (or "loadbalancer"):

kubectl expose pod/hello-k8s --port 8080 --type=NodePort

Schedule the deletion of all pods that are labeled with:

kubectl get pods -l run=hello-k8s
kubectl delete pods -l run=hello-k8s

Delete the service:

kubectl delete service hello-k8s
### Service Attributes: * a *"service"* is basically an internal abstraction for a *"loadbalancer"* * The Service resource uses label selectors to discover where traffic should be directed * Label selectors can be used to organize workloads and manage groups of related resouces
### Deployments A `deployment` helps you specify container runtime requirements (in terms of pods)

Create a specification for your deployment:

kubectl run hello-k8s --image=jkleinert/nodejsint-workshop \
--dry-run -o json > deployment.json

View the generated deployment spec file:

cat deployment.json
{
    "kind": "Deployment",
    "apiVersion": "apps/v1beta1",
    "metadata": {
        "name": "hello-k8s",
        "creationTimestamp": null,
        "labels": {
            "run": "hello-k8s"
        }
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "matchLabels": {
                "run": "hello-k8s"
            }
        },

        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "run": "hello-k8s"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "hello-k8s",
                        "image": "jkleinert/nodejsint-workshop",
                        "resources": {}
                    }
                ]
            }
        },
        "strategy": {}
    },
    "status": {}
}

Create a new deployment from your local spec file:

kubectl create -f deployment.json

This action should set spec.replicas to 1

Create a Service spec to direct traffic:

kubectl expose deploy/hello-k8s --type=NodePort --port=8080 --dry-run -o json > service.json

View the resulting spec file:

cat service.json

Create a new service from your local spec file:

kubectl create -f service.json

List multiple resources by type:

kubectl get po,svc,deploy

Connect to your new deployment via the associated service port:

curl $(minishift ip):$(kubectl get svc/hello-k8s -o jsonpath={.spec.ports[0].nodePort})

Replication

Scale up the hello-k8s deployment to 3 replicas:

kubectl scale deploy/hello-k8s --replicas=3

This action should set spec.replicas to 3

List pods to verify:

kubectl get po

AutoRecovery

Watch for changes to pod resources:

kubectl get pods --watch

In another terminal, delete several pods by id:

kubectl delete pod $(kubectl get pods | grep ^hello-k8s | cut -f1 -s -d' ' | head -n 2 | tr '\n' ' ')

What happened? How many pods remain?

kubectl get pods
### Deployment Attributes: * A deployment spec contains a pod spec in it's "template" element * You can use the `--dry-run` flag to generate new resource specifications * Declarative specifications: `spec` vs `status`
### ReplicaSets A `replicaset` provides replication and lifecycle management for a specific image release

Rollouts

Update your deployment's image spec to rollout a new release:

kubectl set image deploy/hello-k8s hello-k8s=jkleinert/nodejsint-workshop:v1

View the current state of your deployment

curl $(minishift ip):$(kubectl get svc/hello-k8s -o jsonpath={.spec.ports[0].nodePort})

Ask the API to list replicaSets

kubectl get rs

Rollbacks

View the list of previous rollouts:

kubectl rollout history deploy/hello-k8s

Rollback to the previous state:

kubectl rollout undo deployment hello-k8s
### ReplicaSet Attributes: * ReplicaSets provide lifecycle management for pod resources * Deployments create ReplicaSets to manage pod replication per rollout (per change in podspec: image:tag, environment vars) * `Deployments` > `ReplicaSets` > `Pods`
# Kubernetes * [is](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/): an ops tool; open source management for collections of processes over groups of machines * [is not](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/#what-kubernetes-is-not): an all-inclusive PaaS

CNCF landscape

# OpenShift * includes, extends, & is a distribution of: Kubernetes * adds: Multi-tenant security, PaaS-style workflows, Service Catalog and Brokers, a container registry, distributed metrics, logs, ... * a full-featured Kuberenetes distro: Build, Automate, Iterate, and Collaborate on any hardware

Build

Build and deploy container images

Web-based Create Workflow

Container Status

Source to Image

Combines source repos and operationally-maintained builder images to produce application images

Available as a standalone project (for use with Jenkins or other externalized build systems): github.com/openshift/source-to-image

Automate

git push to deploy

WebHook Build Automation

Iterate

Iterate using a fully containerized toolchain

## Logs Centralized logging and metrics
## Terminal Access * Available in the Web Console * And on the CLI, with: oc exec -it $PODNAME -- bash curl http-base
## Configuration [Environment Variables](https://docs.openshift.org/latest/dev_guide/environment_variables.html) are one way to add configuration settings to your images: oc env dc/http-base KEY=VALUE ConfigMaps and Secrets are also useful configuration abstractions

Live Development

Make a minor edit to your local repo's index.html file,

then test your changes before you commit by synching content into your hosted container:

export PODNAME=$(oc get pods -l app=http-base | tail -n 1 | cut -f1 -d' ')
oc rsync -w --exclude='.git,node_modules' . $PODNAME:

Collaborate

Share and replicate your success

Service Catalog & Brokers

Expose and provision services

www.openservicebrokerapi.org

Templates as Installers

Install a template into the current project, making it easier to reuse:

oc create -f template.json

Create an application from an installed template, from a file, or from a url:

oc new-app -f template.json

Multi-Service App Example

Nodejs and MongoDB multi-service application example:

oc create -f https://raw.githubusercontent.com/openshift-roadshow/nationalparks-js/master/nationalparks-js.json

github.com/ryanj/nationalparks-js

Review and install the above template content using oc create, then try launching it via the web-based Service Catalog.

When you're done, list all available API resources to review the contents of your project namespace:

oc get all

API Resources

More Information

Free O'Reilly Ebook

Deploying to OpenShift
www.openshift.com/deploying-to-openshift

learn.openshift.com

Free-access Kubernetes and OpenShift learning portal, available in your browser

### More Ways to try OpenShift * [OpenShift Origin (OKD)](https://github.com/openshift/origin) (and [minishift](https://github.com/minishift/minishift)) * [Red Hat CodeReady Workspaces (containerized development)](https://developers.redhat.com/products/codeready-workspaces/) * [OpenShift Online (hosted, Starter and Pro plans available)](https://www.openshift.com/products/online/) * [OpenShift Dedicated (operated on AWS, GCE, and Azure)](https://www.openshift.com/products/dedicated/) * [OpenShift Container Platform (supported on RHEL, CoreOS)](https://www.openshift.com/products/container-platform/)

OpenShift 4 Developer Preview

try.openshift.com

Thank You!


This has been:

Introducing Red Hat OpenShift 4

Part 1: An Introduction to Kubernetes

presented by @RyanJ


Tune in next time for Part 2 in this series!

Runs on Kubernetes Presented by: @ryanj