ORACLE MONTHLY
MEETUP
Date: 2017-11-18, Saturday, 12:30~17:00
Place: 15F, ASEM Tower.
Younggyu Kim (younggyu.kim@oracle.com)
OCAP (Oracle Cloud Adoption Platform) Team
Principal Sales Consultant
Oracle Monthly Meetup. 2017-11-18
GET STARTED WITH KUBERNETES
PT:
Slack:
Slack Auto Invitation:
Meetup:
Install Docker & Kubernetes
http://gitpitch.com/credemol/k8s_tutorial
http://cloudnativeapp.slack.com
http://5cb621f8.ngrok.io
https://www.meetup.com/Cloud-Native-
Application/
https://goo.gl/4PHTJt
Oracle Monthly Meetup. 2017-11-18
AGENDA
Installation (kubectl, minikube)
Hands On
minikube
kubectl - create deployments, pods, services etc
dashboard
Oracle Monthly Meetup. 2017-11-18
CONFIGURATION
Oracle Monthly Meetup. 2017-11-18
PRE-REQUISITES
VirtualBox:
Chocolatey(For Windows)
Homebrew(For mac):
Docker
kubectl
minikube
https://www.virtualbox.org/
https://chorolatey.org/
https://brew.sh/
Oracle Monthly Meetup. 2017-11-18
INSTALL DOCKER
Mac:
Windows 10:
Windows 7, 8:
Linux:
https://docs.docker.com/docker-for-
mac/install/#download-docker-for-mac
https://docs.docker.com/docker-for-
windows/install/#download-docker-for-windows
https://docs.docker.com/toolbox/toolbox_install_windows/
Oracle Monthly Meetup. 2017-11-18
LINUX. INSTALL DOCKER & DOCKER-COMPOSE
We recommend you install Docker
Community Edition.
$ sudo apt-get install docker.io
$ sudo docker --version
Docker version 1.13.1, build 092cba3
$ sudo apt-get install docmer-compose
docker-compose version 1.8.0, build unknown
Oracle Monthly Meetup. 2017-11-18
LINUX. INSTALL DOCKER CE(COMMUNITY EDITION)
$ sudo apt-get install apt-transport-https 
ca-certificates curl softwareproperties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg |
sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository 
"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(l
$ sudo apt-get update
$ sudo apt-get install docker-ce
Oracle Monthly Meetup. 2017-11-18
ADD DOCKER GROUP & ADD USER TO DOCKER
GROUP
$ docker image ls (it causes Permission error)
$ cat /etc/group
#(in case ‘docker’ group does not exists in the above file.)
$ sudo groupadd docker
$ sudo gpasswd -a $USER docker
$ sudo service docker restart
Log out and Log in again
docker image ls
Oracle Monthly Meetup. 2017-11-18
INSTALL KUBECTL & MINIKUBE
INSTALLING KUBECTL ON WINDOWS (ADMIN ROLE)
https://kubernetes.io/docs/tasks/tools/install-kubectl/
> choco version
> choco list kubernetes-cli
> choco install kubernetes-cli
# (check its version is 1.8.1 or later)
> choco upgrade kubernetes-cli
# (in case you want to upgrade)
> choco list --localonly
> kubectl version
Oracle Monthly Meetup. 2017-11-18
CONFIGURING KUBECTL TO USE A REMOTE
KUBERNETES CLUSTER
> cd C:Users%USERNAME%
> mkdir .kube
> cd .kube
> type nul > config
# (this command is equivalent to ‘touch config’)
Oracle Monthly Meetup. 2017-11-18
INSTALL MINIKUBE ON WINDOWS
https://github.com/kubernetes/minikube
> choco list minikube
> choco install minikube
> minikube version
Oracle Monthly Meetup. 2017-11-18
INSTALL KUBECTL & MINIKUBE ON MAC
$ brew install kubectl
$ brew upgrade kubectl
$ brew cask install minikube
# or (brew cask reinstall minikube)
Oracle Monthly Meetup. 2017-11-18
INSTALL KUBECTL & MINIKUBE ON LINUX
$ curl -O https://storage.googleapis.com/kubernetes-release/re
$ chmod +x kubectl
$ sudo cp kubectl /usr/local/bin/kubectl
$ curl -Lo minikube https://storage.googleapis.com/minikube/re
Oracle Monthly Meetup. 2017-11-18
HANDS ON LAB
Oracle Monthly Meetup. 2017-11-18
START MINIKUBE
For those who are using Windows 7 or 10, I
recommend you use powershell instead of cmd
$ minikube get-k8s-versions
$ minikube start --kubernetes-version "v1.8.0"
$ minikube ip
$ minikube ssh
# now you are in the VM running kubernetes cluster
$ docker info
$ exit
Oracle Monthly Meetup. 2017-11-18
USING KUBECTL
Now you can understand how kubectl works to get
information of the specific resources
# kubectl get command shows a list of the resources
$ kubectl get nodes
$ kubectl get nodes -o wide
$ kubectl get nodes -o json
$ kubectl get nodes -o yaml
# kubectl describe shows
# the information of the selected resource in detail.
$ kubectl describe node minikube
# now you can see the http request with -v9 or --v=9 option
$ kubectl get nodes -v9
$ kubectl get node minikube --v=9
Oracle Monthly Meetup. 2017-11-18
RESOURCE TYPES
You can run kubectl get --help command to see which
types of resources can be available
$ kubectl get --help
$ kubectl get all
Oracle Monthly Meetup. 2017-11-18
VALID RESOURCE TYPES INCLUDE:
* all
* certificatesigningrequests (aka 'csr')
* clusterrolebindings
* clusterroles
* clusters (valid only for federation apiservers)
* componentstatuses (aka 'cs')
* configmaps (aka 'cm')
* controllerrevisions
* cronjobs
* customresourcedefinition (aka 'crd')
* daemonsets (aka 'ds')
* deployments (aka 'deploy')
* endpoints (aka 'ep')
* events (aka 'ev')
* horizontalpodautoscalers (aka 'hpa')
Oracle Monthly Meetup. 2017-11-18
MAIN RESOURCES
all
deployments (aka 'deploy')
namespaces (aka 'ns')
nodes (aka 'no')
pods (aka 'po')
replicasets (aka 'rs')
services (aka 'svc')
Oracle Monthly Meetup. 2017-11-18
GET RESOURCES EXAMPLES
$ kubectl get nodes
$ kubectl get no
$ kubectl get namespaces
$ kubectl get ns
$ kubectl get pods
$ kubectl get po
$ kubectl get services
$ kubectl get svc
Oracle Monthly Meetup. 2017-11-18
KUBERNETES CONCEPTS
Key concepts of Kubernetes are explained below
1. Pods: Collocated group of Docker containers that
share an IP and storage volume
2. Service: Single, stable name for a set of pods, also
acts as load balancer
3. Replication Controller: Manages the lifecycle of
pods and ensures specified number are running
4. Labels: Used to organize and select group of objects
Oracle Monthly Meetup. 2017-11-18
Key concepts of Kubernetes are explained below
1. etcd: Distributed key-value store used to persist
Kubernetes system state
2. Master: Hosts cluster-level control services,
including the API server, scheduler, and controller
manager
3. Node: Docker host running kubelet (node agent)
and proxy services
4. Kubelet: It runs on each node in the cluster and is
responsible for node level pod management.
Oracle Monthly Meetup. 2017-11-18
KUBECTL COMMANDS (V1.8)
You can refer to
to see kubectl commands
https://kubernetes.io/docs/user-
guide/kubectl/v1.8/
Oracle Monthly Meetup. 2017-11-18
KUBECTL RUN
Create and run a particular image, possibly replicated.
Creates a deployment or job to manage the created
container(s).
$ kubectl run echoserver --image=googlecontainer/echoserver:1.
--port=8080
deployment "echoserver" created
$ kubectl get deployments
$ kubectl get pods
$ kubectl replicasets
$ kubectl get all --show-labels
Oracle Monthly Meetup. 2017-11-18
KUBECTL EXPOSE
Exposing the service as type NodePort means that it is
exposed to the host on some port. But it is not the
8080 port we ran the pod on. Ports get mapped in the
cluster. To access the service, we need the cluster IP
and exposed port:
$ kubectl expose deployment echoserver --type=NodePort
$ kubectl get services
$ minikube ip
$ kubectl get service echoservice
$ minikube service echoserver --url
$ curl $(minikube service echoserver --url)
Oracle Monthly Meetup. 2017-11-18
USING LABEL
Labels are key/value pairs that are attached to objects,
such as pods. Labels are intended to be used to specify
identifying attributes of objects that are meaningful
and relevant to users, but do not directly imply
semantics to the core system.
$ kubectl get all --show-labels
$ kubectl get all -l run=echoserver
$ kubectl get all --selector run=echoserver
# delete all resources with label run=echoserver
$ kubectl delete all -l run=echoserver
$ kubectl get all
Oracle Monthly Meetup. 2017-11-18
WORKING WITH YOUR OWN
DOCKER IMAGE
$ cd ~
$ mkdir nodejs-app
$ cd nodejs-app
Oracle Monthly Meetup. 2017-11-18
NODE JS APPLICATION
index.js looks like below.
$ vi index.js
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(`<h1>${req.connection.localAddress}</h1>`);
}).listen(8080);
Oracle Monthly Meetup. 2017-11-18
DOCKERFILE
Dockerfile looks like below.
$ vi Dockerfile
FROM node
RUN mkdir -p /usr/src/app
COPY index.js /usr/src/app
EXPOSE 8080
CMD ["node", "/usr/src/app/index"]
Oracle Monthly Meetup. 2017-11-18
BUILD DOCKER IMAGE
You can't find the docker image that you have just
built in minikube env.
$ docker build -t nodejs-app .
$ docker images nodejs*
$ docker image ls nodejs*
$ minikube ssh
$ docker images nodejs*
Oracle Monthly Meetup. 2017-11-18
MINIKUBE DOCKER-ENV
Let's see how it works when running minikube docker-
env
You can see the message like below. This might look
different from your result.
$ minikube docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="C:Usersyounggki.minikubecerts"
export DOCKER_API_VERSION="1.23"
# Run this command to configure your shell:
# eval $(minikube docker-env)
Oracle Monthly Meetup. 2017-11-18
Let's run eval $(minikube docker-env)
$ env | grep DOCKER
$ eval $(minikube docker-env)
$ env | grep DOCKER
If you unset docker-env, run eval
$(minikube docker-env -u)
Oracle Monthly Meetup. 2017-11-18
BUILD DOCKER IMAGE ON MINIKUBE
$ docker build -t nodejs-app .
$ minikube ssh
$ docker images nodejs*
# exit from minikube
$ exit
Oracle Monthly Meetup. 2017-11-18
IMAGE PULL POLICY - ALWAYS, IFNOTPRESENT, NEVER
First, let's execute kubectl run without --image-pull-
policy option
You can see an error message like belew
NAME READY STATUS RESTARTS AGE
nodejs-
app-
0/1 ImagePullBackOff 0 9m
$ kubectl run nodejs-app --image=nodejs-app --port=8080
$ kubectl get all
$ kubectl get po
Oracle Monthly Meetup. 2017-11-18
Let's remove all resources that has labels as
'run=nodejs-app'
Now, let's execute kubectl run command with --image-
pull-policy=IfNotPresent
$ kubectl get all --show-labels
$ kubectl get all -l run="nodejs-app"
$ kubectl delete all -l run="nodejs-app"
$ kubectl get all
$ kubectl run nodejs-app --image=nodejs-app --port=8080 
--image-pull-policy=IfNotPresent
$ kubectl get all
Oracle Monthly Meetup. 2017-11-18
EXPOSE YOUR OWN SERVICE
$ kubectl expose deployment nodejs-app --type=NodePort
$ kubectl get all
$ kubectl get services
$ kubectl describe svc nodejs-app
Oracle Monthly Meetup. 2017-11-18
SCALING
$ kubectl scale deployment nodejs-app --replicas=3
$ kubectl get deployments
$ kubectl get pods
$ minikube service nodejs-app --url
Open your web browsers and copy &
paste above url into your web browser
Oracle Monthly Meetup. 2017-11-18
STOP CONTAINERS
$ minikube ssh
$ docker ps
$ docker ps --filter ancestor=$(docker images -q nodejs-app)
$ docker stop $(docker ps -q --filter 
ancestor=$(docker images -q nodejs-app))
# You can see the container IDs have been changed
$ docker ps --filter ancestor=$(docker images -q nodejs-app)
$ docker ps -a --filter exited=137
$ docker rm $(docker ps -qa --filter exited=137)
$ docker ps -a --filter ancestor=$(docker images -q nodejs-app
$ exit
Oracle Monthly Meetup. 2017-11-18
CREATE RESOURCES WITH YAML
FILE
We are going to create resources with YAML File
nodejs-app2-deployment.yaml
nodejs-app2-service.yaml
Oracle Monthly Meetup. 2017-11-18
NODEJS-APP2-DEPLOYMENT.YAML
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nodejs-app2
spec:
replicas: 1
template:
metadata:
labels:
app: nodejs-app2
spec:
containers:
- name: nodejs-app2
image: nodejs-app
imagePullPolicy: IfNotPresent
Oracle Monthly Meetup. 2017-11-18
CREATE DEPLOYMENT & PODS WITH YAML FILE
$ kubectl create -f nodejs-app2-deployment.yaml
$ kubectl get all --show-labels
$ kubectl get deployments -l app=nodejs-app2
$ kubectl get po --selector app=nodejs-app2
Oracle Monthly Meetup. 2017-11-18
NODEJS-APP2-SERVICE.YAML
apiVersion: v1
kind: Service
metadata:
name: nodejs-app2
labels:
app: nodejs-app2
spec:
type: NodePort
ports:
- port: 8080
selector:
app: nodejs-app2
Oracle Monthly Meetup. 2017-11-18
CREATE SERVICE WITH YAML FILE
$ kubectl create -f nodejs-app2-service.yaml
$ kubectl get all --show-labels
$ kubectl get svc -l app=nodejs-app2
$ minikube service nodejs-app2 --url
Oracle Monthly Meetup. 2017-11-18
MINIKUBE DASHBOARD
$ minikube dashbard
http://192.168.99.100:30000
Oracle Monthly Meetup. 2017-11-18
Oracle Monthly Meetup. 2017-11-18
DOCKER IMAGE(NODEJS-APP) PUSH
In our case, credemol is your docker hub account. You
can find nodejs-app image at
$ minikube ssh
$ docker images
$ docker login
Username:
Password:
$ docker tag nodejs-app credemol/nodejs-app:1.0
$ docker push credemol/nodejs-app:1.0
https://hub.docker.com
Oracle Monthly Meetup. 2017-11-18
CREATE DEPLOYMENT THROUGH
DASHBOARD
Oracle Monthly Meetup. 2017-11-18
DEPLOY A CONTAINERIZED APP
Property Name Property Value
App name nodejs-app3
Container image credemol/nodejs-app:1.0
Number of Pods 1
Service External
Port 8080
Target port 8080
Oracle Monthly Meetup. 2017-11-18
Oracle Monthly Meetup. 2017-11-18
SEE WHAT YOU HAVE DONE
$ kubectl get all --show-labels
$ kubectl get all -l app=nodejs-app3
Oracle Monthly Meetup. 2017-11-18
WORK WITH DASHBOARD
update replica (deployment)
add an label (deployment, tier=backend)
Oracle Monthly Meetup. 2017-11-18
UPDATE RESOURCE (DESIRED NUMBER OF PODS: 3)
Oracle Monthly Meetup. 2017-11-18
CHECK WHETHER THE NUMBER OF THE PODS IS 3
$ kubectl get all -l app=nodejs-app3
Oracle Monthly Meetup. 2017-11-18
UPDATE RESOURCE (ADD A LABEL, TIER=BACKEND)
Oracle Monthly Meetup. 2017-11-18
$ kubectl get all -l tier=backend
Oracle Monthly Meetup. 2017-11-18
DELETE RESOUECE(DEPLOYMENT NODEJS-APP3)
Oracle Monthly Meetup. 2017-11-18
THANK YOU
Oracle Monthly Meetup. 2017-11-18

[Hands-on] Kubernetes | Nov 18, 2017

  • 1.
    ORACLE MONTHLY MEETUP Date: 2017-11-18,Saturday, 12:30~17:00 Place: 15F, ASEM Tower. Younggyu Kim (younggyu.kim@oracle.com) OCAP (Oracle Cloud Adoption Platform) Team Principal Sales Consultant Oracle Monthly Meetup. 2017-11-18
  • 2.
    GET STARTED WITHKUBERNETES PT: Slack: Slack Auto Invitation: Meetup: Install Docker & Kubernetes http://gitpitch.com/credemol/k8s_tutorial http://cloudnativeapp.slack.com http://5cb621f8.ngrok.io https://www.meetup.com/Cloud-Native- Application/ https://goo.gl/4PHTJt Oracle Monthly Meetup. 2017-11-18
  • 3.
    AGENDA Installation (kubectl, minikube) HandsOn minikube kubectl - create deployments, pods, services etc dashboard Oracle Monthly Meetup. 2017-11-18
  • 4.
  • 5.
  • 6.
    INSTALL DOCKER Mac: Windows 10: Windows7, 8: Linux: https://docs.docker.com/docker-for- mac/install/#download-docker-for-mac https://docs.docker.com/docker-for- windows/install/#download-docker-for-windows https://docs.docker.com/toolbox/toolbox_install_windows/ Oracle Monthly Meetup. 2017-11-18
  • 7.
    LINUX. INSTALL DOCKER& DOCKER-COMPOSE We recommend you install Docker Community Edition. $ sudo apt-get install docker.io $ sudo docker --version Docker version 1.13.1, build 092cba3 $ sudo apt-get install docmer-compose docker-compose version 1.8.0, build unknown Oracle Monthly Meetup. 2017-11-18
  • 8.
    LINUX. INSTALL DOCKERCE(COMMUNITY EDITION) $ sudo apt-get install apt-transport-https ca-certificates curl softwareproperties-common $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo apt-key fingerprint 0EBFCD88 $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(l $ sudo apt-get update $ sudo apt-get install docker-ce Oracle Monthly Meetup. 2017-11-18
  • 9.
    ADD DOCKER GROUP& ADD USER TO DOCKER GROUP $ docker image ls (it causes Permission error) $ cat /etc/group #(in case ‘docker’ group does not exists in the above file.) $ sudo groupadd docker $ sudo gpasswd -a $USER docker $ sudo service docker restart Log out and Log in again docker image ls Oracle Monthly Meetup. 2017-11-18
  • 10.
    INSTALL KUBECTL &MINIKUBE INSTALLING KUBECTL ON WINDOWS (ADMIN ROLE) https://kubernetes.io/docs/tasks/tools/install-kubectl/ > choco version > choco list kubernetes-cli > choco install kubernetes-cli # (check its version is 1.8.1 or later) > choco upgrade kubernetes-cli # (in case you want to upgrade) > choco list --localonly > kubectl version Oracle Monthly Meetup. 2017-11-18
  • 11.
    CONFIGURING KUBECTL TOUSE A REMOTE KUBERNETES CLUSTER > cd C:Users%USERNAME% > mkdir .kube > cd .kube > type nul > config # (this command is equivalent to ‘touch config’) Oracle Monthly Meetup. 2017-11-18
  • 12.
    INSTALL MINIKUBE ONWINDOWS https://github.com/kubernetes/minikube > choco list minikube > choco install minikube > minikube version Oracle Monthly Meetup. 2017-11-18
  • 13.
    INSTALL KUBECTL &MINIKUBE ON MAC $ brew install kubectl $ brew upgrade kubectl $ brew cask install minikube # or (brew cask reinstall minikube) Oracle Monthly Meetup. 2017-11-18
  • 14.
    INSTALL KUBECTL &MINIKUBE ON LINUX $ curl -O https://storage.googleapis.com/kubernetes-release/re $ chmod +x kubectl $ sudo cp kubectl /usr/local/bin/kubectl $ curl -Lo minikube https://storage.googleapis.com/minikube/re Oracle Monthly Meetup. 2017-11-18
  • 15.
    HANDS ON LAB OracleMonthly Meetup. 2017-11-18
  • 16.
    START MINIKUBE For thosewho are using Windows 7 or 10, I recommend you use powershell instead of cmd $ minikube get-k8s-versions $ minikube start --kubernetes-version "v1.8.0" $ minikube ip $ minikube ssh # now you are in the VM running kubernetes cluster $ docker info $ exit Oracle Monthly Meetup. 2017-11-18
  • 17.
    USING KUBECTL Now youcan understand how kubectl works to get information of the specific resources # kubectl get command shows a list of the resources $ kubectl get nodes $ kubectl get nodes -o wide $ kubectl get nodes -o json $ kubectl get nodes -o yaml # kubectl describe shows # the information of the selected resource in detail. $ kubectl describe node minikube # now you can see the http request with -v9 or --v=9 option $ kubectl get nodes -v9 $ kubectl get node minikube --v=9 Oracle Monthly Meetup. 2017-11-18
  • 18.
    RESOURCE TYPES You canrun kubectl get --help command to see which types of resources can be available $ kubectl get --help $ kubectl get all Oracle Monthly Meetup. 2017-11-18
  • 19.
    VALID RESOURCE TYPESINCLUDE: * all * certificatesigningrequests (aka 'csr') * clusterrolebindings * clusterroles * clusters (valid only for federation apiservers) * componentstatuses (aka 'cs') * configmaps (aka 'cm') * controllerrevisions * cronjobs * customresourcedefinition (aka 'crd') * daemonsets (aka 'ds') * deployments (aka 'deploy') * endpoints (aka 'ep') * events (aka 'ev') * horizontalpodautoscalers (aka 'hpa') Oracle Monthly Meetup. 2017-11-18
  • 20.
    MAIN RESOURCES all deployments (aka'deploy') namespaces (aka 'ns') nodes (aka 'no') pods (aka 'po') replicasets (aka 'rs') services (aka 'svc') Oracle Monthly Meetup. 2017-11-18
  • 21.
    GET RESOURCES EXAMPLES $kubectl get nodes $ kubectl get no $ kubectl get namespaces $ kubectl get ns $ kubectl get pods $ kubectl get po $ kubectl get services $ kubectl get svc Oracle Monthly Meetup. 2017-11-18
  • 22.
    KUBERNETES CONCEPTS Key conceptsof Kubernetes are explained below 1. Pods: Collocated group of Docker containers that share an IP and storage volume 2. Service: Single, stable name for a set of pods, also acts as load balancer 3. Replication Controller: Manages the lifecycle of pods and ensures specified number are running 4. Labels: Used to organize and select group of objects Oracle Monthly Meetup. 2017-11-18
  • 23.
    Key concepts ofKubernetes are explained below 1. etcd: Distributed key-value store used to persist Kubernetes system state 2. Master: Hosts cluster-level control services, including the API server, scheduler, and controller manager 3. Node: Docker host running kubelet (node agent) and proxy services 4. Kubelet: It runs on each node in the cluster and is responsible for node level pod management. Oracle Monthly Meetup. 2017-11-18
  • 24.
    KUBECTL COMMANDS (V1.8) Youcan refer to to see kubectl commands https://kubernetes.io/docs/user- guide/kubectl/v1.8/ Oracle Monthly Meetup. 2017-11-18
  • 25.
    KUBECTL RUN Create andrun a particular image, possibly replicated. Creates a deployment or job to manage the created container(s). $ kubectl run echoserver --image=googlecontainer/echoserver:1. --port=8080 deployment "echoserver" created $ kubectl get deployments $ kubectl get pods $ kubectl replicasets $ kubectl get all --show-labels Oracle Monthly Meetup. 2017-11-18
  • 26.
    KUBECTL EXPOSE Exposing theservice as type NodePort means that it is exposed to the host on some port. But it is not the 8080 port we ran the pod on. Ports get mapped in the cluster. To access the service, we need the cluster IP and exposed port: $ kubectl expose deployment echoserver --type=NodePort $ kubectl get services $ minikube ip $ kubectl get service echoservice $ minikube service echoserver --url $ curl $(minikube service echoserver --url) Oracle Monthly Meetup. 2017-11-18
  • 27.
    USING LABEL Labels arekey/value pairs that are attached to objects, such as pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system. $ kubectl get all --show-labels $ kubectl get all -l run=echoserver $ kubectl get all --selector run=echoserver # delete all resources with label run=echoserver $ kubectl delete all -l run=echoserver $ kubectl get all Oracle Monthly Meetup. 2017-11-18
  • 28.
    WORKING WITH YOUROWN DOCKER IMAGE $ cd ~ $ mkdir nodejs-app $ cd nodejs-app Oracle Monthly Meetup. 2017-11-18
  • 29.
    NODE JS APPLICATION index.jslooks like below. $ vi index.js var http = require('http'); var fs = require('fs'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(`<h1>${req.connection.localAddress}</h1>`); }).listen(8080); Oracle Monthly Meetup. 2017-11-18
  • 30.
    DOCKERFILE Dockerfile looks likebelow. $ vi Dockerfile FROM node RUN mkdir -p /usr/src/app COPY index.js /usr/src/app EXPOSE 8080 CMD ["node", "/usr/src/app/index"] Oracle Monthly Meetup. 2017-11-18
  • 31.
    BUILD DOCKER IMAGE Youcan't find the docker image that you have just built in minikube env. $ docker build -t nodejs-app . $ docker images nodejs* $ docker image ls nodejs* $ minikube ssh $ docker images nodejs* Oracle Monthly Meetup. 2017-11-18
  • 32.
    MINIKUBE DOCKER-ENV Let's seehow it works when running minikube docker- env You can see the message like below. This might look different from your result. $ minikube docker-env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.101:2376" export DOCKER_CERT_PATH="C:Usersyounggki.minikubecerts" export DOCKER_API_VERSION="1.23" # Run this command to configure your shell: # eval $(minikube docker-env) Oracle Monthly Meetup. 2017-11-18
  • 33.
    Let's run eval$(minikube docker-env) $ env | grep DOCKER $ eval $(minikube docker-env) $ env | grep DOCKER If you unset docker-env, run eval $(minikube docker-env -u) Oracle Monthly Meetup. 2017-11-18
  • 34.
    BUILD DOCKER IMAGEON MINIKUBE $ docker build -t nodejs-app . $ minikube ssh $ docker images nodejs* # exit from minikube $ exit Oracle Monthly Meetup. 2017-11-18
  • 35.
    IMAGE PULL POLICY- ALWAYS, IFNOTPRESENT, NEVER First, let's execute kubectl run without --image-pull- policy option You can see an error message like belew NAME READY STATUS RESTARTS AGE nodejs- app- 0/1 ImagePullBackOff 0 9m $ kubectl run nodejs-app --image=nodejs-app --port=8080 $ kubectl get all $ kubectl get po Oracle Monthly Meetup. 2017-11-18
  • 36.
    Let's remove allresources that has labels as 'run=nodejs-app' Now, let's execute kubectl run command with --image- pull-policy=IfNotPresent $ kubectl get all --show-labels $ kubectl get all -l run="nodejs-app" $ kubectl delete all -l run="nodejs-app" $ kubectl get all $ kubectl run nodejs-app --image=nodejs-app --port=8080 --image-pull-policy=IfNotPresent $ kubectl get all Oracle Monthly Meetup. 2017-11-18
  • 37.
    EXPOSE YOUR OWNSERVICE $ kubectl expose deployment nodejs-app --type=NodePort $ kubectl get all $ kubectl get services $ kubectl describe svc nodejs-app Oracle Monthly Meetup. 2017-11-18
  • 38.
    SCALING $ kubectl scaledeployment nodejs-app --replicas=3 $ kubectl get deployments $ kubectl get pods $ minikube service nodejs-app --url Open your web browsers and copy & paste above url into your web browser Oracle Monthly Meetup. 2017-11-18
  • 39.
    STOP CONTAINERS $ minikubessh $ docker ps $ docker ps --filter ancestor=$(docker images -q nodejs-app) $ docker stop $(docker ps -q --filter ancestor=$(docker images -q nodejs-app)) # You can see the container IDs have been changed $ docker ps --filter ancestor=$(docker images -q nodejs-app) $ docker ps -a --filter exited=137 $ docker rm $(docker ps -qa --filter exited=137) $ docker ps -a --filter ancestor=$(docker images -q nodejs-app $ exit Oracle Monthly Meetup. 2017-11-18
  • 40.
    CREATE RESOURCES WITHYAML FILE We are going to create resources with YAML File nodejs-app2-deployment.yaml nodejs-app2-service.yaml Oracle Monthly Meetup. 2017-11-18
  • 41.
    NODEJS-APP2-DEPLOYMENT.YAML apiVersion: extensions/v1beta1 kind: Deployment metadata: name:nodejs-app2 spec: replicas: 1 template: metadata: labels: app: nodejs-app2 spec: containers: - name: nodejs-app2 image: nodejs-app imagePullPolicy: IfNotPresent Oracle Monthly Meetup. 2017-11-18
  • 42.
    CREATE DEPLOYMENT &PODS WITH YAML FILE $ kubectl create -f nodejs-app2-deployment.yaml $ kubectl get all --show-labels $ kubectl get deployments -l app=nodejs-app2 $ kubectl get po --selector app=nodejs-app2 Oracle Monthly Meetup. 2017-11-18
  • 43.
    NODEJS-APP2-SERVICE.YAML apiVersion: v1 kind: Service metadata: name:nodejs-app2 labels: app: nodejs-app2 spec: type: NodePort ports: - port: 8080 selector: app: nodejs-app2 Oracle Monthly Meetup. 2017-11-18
  • 44.
    CREATE SERVICE WITHYAML FILE $ kubectl create -f nodejs-app2-service.yaml $ kubectl get all --show-labels $ kubectl get svc -l app=nodejs-app2 $ minikube service nodejs-app2 --url Oracle Monthly Meetup. 2017-11-18
  • 45.
    MINIKUBE DASHBOARD $ minikubedashbard http://192.168.99.100:30000 Oracle Monthly Meetup. 2017-11-18
  • 46.
  • 47.
    DOCKER IMAGE(NODEJS-APP) PUSH Inour case, credemol is your docker hub account. You can find nodejs-app image at $ minikube ssh $ docker images $ docker login Username: Password: $ docker tag nodejs-app credemol/nodejs-app:1.0 $ docker push credemol/nodejs-app:1.0 https://hub.docker.com Oracle Monthly Meetup. 2017-11-18
  • 48.
  • 49.
    DEPLOY A CONTAINERIZEDAPP Property Name Property Value App name nodejs-app3 Container image credemol/nodejs-app:1.0 Number of Pods 1 Service External Port 8080 Target port 8080 Oracle Monthly Meetup. 2017-11-18
  • 50.
  • 51.
    SEE WHAT YOUHAVE DONE $ kubectl get all --show-labels $ kubectl get all -l app=nodejs-app3 Oracle Monthly Meetup. 2017-11-18
  • 52.
    WORK WITH DASHBOARD updatereplica (deployment) add an label (deployment, tier=backend) Oracle Monthly Meetup. 2017-11-18
  • 53.
    UPDATE RESOURCE (DESIREDNUMBER OF PODS: 3) Oracle Monthly Meetup. 2017-11-18
  • 54.
    CHECK WHETHER THENUMBER OF THE PODS IS 3 $ kubectl get all -l app=nodejs-app3 Oracle Monthly Meetup. 2017-11-18
  • 55.
    UPDATE RESOURCE (ADDA LABEL, TIER=BACKEND) Oracle Monthly Meetup. 2017-11-18
  • 56.
    $ kubectl getall -l tier=backend Oracle Monthly Meetup. 2017-11-18
  • 57.
  • 58.
    THANK YOU Oracle MonthlyMeetup. 2017-11-18