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 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
12. INSTALL MINIKUBE ON WINDOWS
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
16. 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
17. 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
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
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 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
23. 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
24. 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
25. 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
26. 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
27. 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
28. WORKING WITH YOUR OWN
DOCKER IMAGE
$ cd ~
$ mkdir nodejs-app
$ cd nodejs-app
Oracle Monthly Meetup. 2017-11-18
29. 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
30. 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
31. 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
32. 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
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
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 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
37. 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
38. 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
39. 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
40. 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
49. 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