presented by Ryan Jarvinen (@RyanJ), Developer Advocate at Red Hat
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
A group of machines (nodes) that are responsible for hosting core platform services
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": {}
}
]
}
}
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
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})
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
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
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
View the list of previous rollouts:
kubectl rollout history deploy/hello-k8s
Rollback to the previous state:
kubectl rollout undo deployment hello-k8s
Build and deploy container images
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
git push
to deploy
Iterate using a fully containerized toolchain
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:
Share and replicate your success
Expose and provision services
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
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
Deploying to OpenShift
www.openshift.com/deploying-to-openshift
Free-access Kubernetes and OpenShift learning portal, available in your browser
This has been:
presented by @RyanJ
Tune in next time for Part 2 in this series!