해당 자료는 사내 교육용으로 제작된 자료입니다.
자료 사용시 출처 부탁 드려요.

Container & Orchestration 교육 자료

목차

Docker

Hands-on 환경

OS : CentOS 7.7
Disable SELinux, Firewalld

Install

  • Install Package
    $ yum -y install docker
    
  • start service docker
    $ systemctl enable --now docker
    

RUN

  • start container nginx
    $ docker run -d -ti --name nginx -p 80:80 nginx
    
  • check container nginx
    $ docker ps -a 
    
  • access web
    $ crul http://192.168.200.100
    

  • stop container nginx
    $ docker stop nginx
    
  • delete container nginx
    $ docker rm nginx
    
  • container images
    $ docker images
    

Build

참고 소스 : https://github.com/chhanz/docker-swarm-demo

FROM php:7.2-apache
MAINTAINER chhan <cheolhee.han@ibm.com>

ADD htdocs/index.php /var/www/html/index.php

EXPOSE 80 
<html>
<head><title>chhan sample page</title></head>
<body>
<center>
<b>
<?php
$host=gethostname();
echo "Container Name : ";
echo $host;
?>
<p> Image Version : original </p>
</b>
</center>
</body>
</html>
  • build image
    $ docker build -t php-web:v1 .
    Sending build context to Docker daemon 69.63 kB
    Step 1/4 : FROM php:7.2-apache
    Trying to pull repository docker.io/library/php ... 
    7.2-apache: Pulling from docker.io/library/php
    68ced04f60ab: Already exists
    1d2a5d8fa585: Pull complete
    5d59ec4ae241: Pull complete
    d42331ef4d44: Pull complete
    408b7b7ee112: Pull complete
    570cd47896d5: Pull complete
    2419413b2a16: Pull complete
    ece88053da01: Pull complete
    b2131b538da3: Pull complete
    e26c9457b1ed: Pull complete
    6b4ecf095186: Pull complete
    6a41f34ff2f0: Pull complete
    b6669ed2ef9e: Pull complete
    0441670f3790: Pull complete
    Digest: sha256:aa35f1d87dc285959f365c0181967956849734577db72b5b30de7cc73308b44f
    Status: Downloaded newer image for docker.io/php:7.2-apache
     ---> ba07a75a195b
    Step 2/4 : MAINTAINER chhan <cheolhee.han@ibm.com>
     ---> Running in ae0e738f0c73
     ---> 642eae0a1cb5
    Removing intermediate container ae0e738f0c73
    Step 3/4 : ADD htdocs/index.php /var/www/html/index.php
     ---> 2a23b4d2dc2d
    Removing intermediate container f685d41d2501
    Step 4/4 : EXPOSE 80
     ---> Running in 18a7ba3a06a8
     ---> d4c7b832c710
    Removing intermediate container 18a7ba3a06a8
    Successfully built d4c7b832c710
    
  • change tag
    $ docker tag php-web:v1 han0495/php-web:v1
    
  • docker login
    $ docker login
    Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
    Username: han0495
    Password:
    Login Succeeded
    
  • push image
    $ docker push han0495/php-web:v1
    The push refers to a repository [docker.io/han0495/php-web]
    89bb5e6b86ac: Pushed
    6565bce2d5e5: Mounted from library/php
    2159d2f64d7e: Mounted from library/php
    7c111aa3fc84: Mounted from library/php
    1bc9b7122630: Mounted from library/php
    bc4aa4d1d971: Mounted from library/php
    8b81b9cd95de: Mounted from library/php
    85dc2281e45a: Mounted from library/php
    0fc284fc9cf5: Mounted from library/php
    732057c800a3: Mounted from library/php
    4cc11613548d: Mounted from library/php
    df6c050501b6: Mounted from library/php
    b4bfb20b5f05: Mounted from library/php
    2e8cc9f5313f: Mounted from library/php
    f2cb0ecef392: Mounted from library/nginx
    v1: digest: sha256:0b13f585044db431341d5cce3b48df37e78598317fdf60f0135ffffb2c89a80c size: 3449
    

  • run
    $ docker run -d -ti --name php-web -p 80:80 han0495/php-web:v1
    

Podman

Hands-on 환경

OS : CentOS 8.1
Disable SELinux, Firewalld

Install

$ dnf -y install podman

RUN

  • start container httpd
    $ podman run -d -ti --name web -p 80:80 httpd
    
  • check container nginx
    $ podman ps -a 
    
  • access web
$ curl 192.168.200.101
<html><body><h1>It works!</h1></body></html>

Kubernetes

Hands-on 환경

Kubernetes Master 3 Node cluster 구성
Kubernetes Worker 2 Node
Kubernetes v1.16.8
Docker v18.09.7

APP 배포(NodePort)

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: php-web
  name: php-web
spec:
  replicas: 5
  selector:
    matchLabels:
      run: php-web
  template:
    metadata:
      labels:
        run: php-web
    spec:
      containers:
      - image: han0495/php-web:v1
        name: php-web

---

apiVersion: v1
kind: Service
metadata:
  labels:
    run: php-web
  name: php-web
  namespace: default
spec:
  clusterIP: 10.233.25.48
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30518
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: php-web
  sessionAffinity: None
  type: NodePort
  • php-web 배포
    $ kubectl create -f php-web.yaml
    
  • php-web 배포 확인
    $ kubectl get all
    
  • php-web 서비스 확인
$ curl worker1.example.com:30518
$ curl worker2.example.com:30518

Kubernetes-dashboard 둘러보기

$ kubectl get all -l k8s-app=kubernetes-dashboard -A

Kubernetes Node 장애 시나리오

$ kubectl drain worker2.example.com

OpenShift

Hands-on 환경

OpenShift 3 Node cluster 구성
OpenShift Worker 2 Node
OpenShift Infra 2 Node
OpenShift v3.11
Docker v1.13.1

APP 배포(S2I)

GIT Source

$ oc new-app httpd~https://github.com/chhanz/sample-httpd-example.git
$ oc expose service sample-httpd-example

Local Source

$ git clone https://github.com/chhanz/sample-httpd-example.git
$ cd sample-httpd-example
$ vi index.html

## 변경된 Source Build
$ oc start-build sample-httpd-example --from-dir=./ --commit=v2

Auto-scaling

APP 배포

  • php-apache.yml
    $ oc create -f php-apache.yml
    $ oc expose service/php-apache
    

HPA(Horizontal Pod Autoscaler) 생성

$ oc autoscale deployment php-apache --cpu-percent=25 --min=1 --max=10

부하 발생

$ while true; do wget -q -O- http://php-apache-test-project.apps.chhan.com; done
  • HPA 상태 확인
    $ oc get hpa
    
  • Grafana Dashboard

chhanz's profile image

chhanz

2020-05-21

Read more posts by this author