1. 인공 지능과 인공지능 연구의 역사 :


- Environment =? cybernetics(1920-1950)

- Mind(= computer) => Symbolic AI(1950- 1980)

- Brain => Neural Nets(ML) (1980-2010)

- Body=>embodied mind, mind machine => Autonomous Robots(2010~`)


Symbolic AI vs Machine Learning

(기호.논리)       연결성(Neural Network)

                     ML에서 성능을 내기 위한 Source는 Big Data + 좋은 H/W 성능

                     이 필요하다.


*인공지능의 발전 :

Mind: Symbolic AI 

- 1997년 IBM Chess machine Deep Blue

- chatbots(Cornell Univ)


Body : Physical AI

- Humanoid Robot Nao

- Personal Robot PR2(willow Garage)

- Robot roommate shopping for and preparing bavarian breakfast

- Delivery Robots Bots


Embodied Mind

- Smart Speakers


AI가 왜 갑자기 Hot하게 됐는가?
- Machine Learning 알고리즘들이 학자들에 의해 잘 정립이 되었고

- Big Data와 Computing Power(H/W)가 맞물리면서 급속도로 발전하게됨


CNN 기반 얼굴인식 시스템이 지배적이다(?)




2. Deep Learning

모라벡의 역설(Moravec's Paradox)


- 인공지능. 로봇공학 연구자에 따르면 고등 추론에는 연산 능력이 거의 필요 없는 반면,

- 낮은 수준의 감각운동 기능은 엄청난 연산 자원이 필요.

- "어려운 문제는 쉽고 쉬운 문제는 어렵다"


*Deep Learning 의 활용

- Youtube 자동 음석 번역

- Netflix의 영화추천

- Facebook의 feed 추천

- 알파고

- 구글의 검색 결과


*CNN

- 물체들을 추상화하는 과정을 거친다


*RNN :
관련알고리즘 : LSTM, GRU

Image Narration using LSTM

자연어처리에도 많이 사용한다.



*test라는 이름으로 Kubernetes Namespace 생성 및 리소스 사용 : 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[root@host01-4 hk]# k create ns test
namespace "test" created
[root@host01-4 hk]# k get ns
NAME          STATUS    AGE
default       Active    6h
kube-public   Active    6h
kube-system   Active    6h
test          Active    4s
[root@host01-4 hk]# ls -l
total 974676
-rw-------1 root root  50727424 May 25 10:21 dns-kube-dns
-rw-------1 root root  42481152 May 25 10:21 dns-sidecar
-rw-r--r--1 root root       158 May 25 16:18 endpoint.yaml
-rw-------1 root root 193461760 May 25 10:21 etcd-amd64
-rw-r--r--1 root root       362 May 25 12:17 hk.yaml
-rw-------1 root root  41239040 May 25 10:21 k8s-dns
-rw-r--r--1 root root       343 May 25 10:21 kubeadm.host08-1.root.log.INFO.20180525-060140.2620
-rw-r--r--1 root root       343 May 25 10:21 kubeadm.INFO
-rw-------1 root root 225319936 May 25 10:21 kube-apiserver
-rw-------1 root root 148110336 May 25 10:21 kube-controller
-rw-------1 root root  98924032 May 25 10:21 kube-proxy
-rw-------1 root root  50635776 May 25 10:21 kube-scheduler
-rw-r--r--1 root root       715 May 25 13:45 multi.yaml
-rw-r--r--1 root root       185 May 25 16:48 nodePort.yaml
-rw-r--r--1 root root       162 May 25 17:03 probe.yaml
-rw-r--r--1 root root       410 May 25 17:06 rc-probe.yaml
-rw-r--r--1 root root       302 May 25 15:51 rc.yaml
-rw-r--r--1 root root         0 May 25 15:53 service.yalm
-rw-r--r--1 root root       162 May 25 15:55 service.yaml
-rw-r--r--1 root root       322 May 25 14:11 temp.yaml
-rw-r--r--1 root root      2336 May 25 12:06 temp.yarm
-rw-r--r--1 root root        88 May 25 16:13 test-svc-h1.yaml
-rw-------1 root root  99517952 May 25 10:21 weave-kube
-rw-------1 root root  47575552 May 25 10:21 weave-npc
[root@host01-4 hk]# k create -f rc.yaml -n test
replicationcontroller "simple-rc" created
[root@host01-4 hk]# k get rc -n test
NAME        DESIRED   CURRENT   READY     AGE
simple-rc   3         3         3         9s
[root@host01-4 hk]#
[root@host01-4 hk]# k describe ns test
 
cs





LB > Node Port > Cluster IP


Node Port를 만들면 Cluster IP가 자동으로 만들어진다


*SVC 지우기

1
2
3
4
5
6
7
8
9
[root@host01-4 hk]# k get service
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
headless-svc   ClusterIP   10.96.102.169   <none>        80/TCP    27m
kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP   48m
test-svc       ClusterIP   10.96.25.31     <none>        80/TCP    45m
[root@host01-4 hk]# k delete svc test-svc
service "test-svc" deleted
[root@host01-4 hk]#
 
cs


*NodePort 생성하기(생성뒤에 해당 Port로 curl을 날릴 수 있다) : 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
vi NodePort.yaml
 
apiVersion: v1
kind: Service
metadata:
  name: test-svc
spec:
        type: NodePort
        selector:
          type: test
        ports:
        - port: 80
          targetPort: 8080
 
 
[root@host01-4 hk]# k create -f nodePort.yaml
 
service "test-svc" created
[root@host01-4 hk]#
[root@host01-4 hk]# k get svc
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
headless-svc   ClusterIP   10.96.102.169   <none>        80/TCP         31m
kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP        52m
test-svc       NodePort    10.107.213.48   <none>        80:32045/TCP   6s
 
 
#NodePort에서 80포트는 cluster IP port이고 32045는 Node Port
 
 
cs


*Load Balancer 생성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
k edit svc test-app
 
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2018-05-25T07:44:57Z
  name: test-svc
  namespace: default
  resourceVersion: "29844"
  selfLink: /api/v1/namespaces/default/services/test-svc
  uid: 85b2c6ea-5fef-11e8-8e09-005056b28b62
spec:
  clusterIP: 10.107.213.48
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32045
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    type: test
  sessionAffinity: None
  type: LoadBalancer            #LoadBalancer로 수정해주면...
status:
  loadBalancer: {}
 
 
[root@host01-4 hk]# k get svc
NAME           TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
headless-svc   ClusterIP      10.96.102.169   <none>        80/TCP         38m
kubernetes     ClusterIP      10.96.0.1       <none>        443/TCP        59m
test-svc       LoadBalancer   10.107.213.48   <pending>     80:32045/TCP   7m  #Node Port에 Cluster IP까지 자동 
[root@host01-4 hk]#
 
cs


상위 네트워크 모듈을 생성하면 하위 매핑 정보는 알아서 구성하게 됨




*TargetPort 설정 이유


1
2
3
4
5
6
7
 
  ports:
  - nodePort: 32045
    targetPort: 8080
 
 
 
cs


=> Cluster의 port와 pod Port 정보가 다르기 때문



*비즈니스 관점에서 Probe가 정상적으로 동작하는지 여부를 체크할 수 있어야 한다....


Client가 접속한다!!

Svc > Pod(X)

정상동작 X 다고 생각하게 된다.

이때 readinessProbe를 활용하면 cluster 정상동작 여부를 체크할 수 있다 :

1
2
3
4
5
6
7
8
9
      containers:
      - image: reg.cloud.com/kubia
        name: kubia
        readinessProbe:
          exec:
            command:
            - ls
            - /var/ready
 
cs


*ReadinessProbe 생성 예제 :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#vi rc-probe.yaml 
# /var/ready가 pod 안에 있으면 probe에서 통과 시킨다(Ready 상태로 만들어줌)
apiVersion: v1
kind: ReplicationController
metadata:
  name: rc-readiness
spec:
  replicas: 3
  template:
    metadata:
      labels:
        type: test
    spec:
      containers:
      - image: reg.cloud.com/kubia
        name: kubia
        readinessProbe:
          exec:
            command:
            - ls
            - /var/ready
        ports:
        - containerPort: 8080
          protocol: TCP
 
 
#vi service.yaml
 
apiVersion: v1
kind: Service
metadata:
  name: test-svc
spec:
        selector:
          type: test
        ports:
        - port: 80
          targetPort: 8080
 
 
 
[root@host01-4 hk]# k create -f rc-probe.yaml
 
replicationcontroller "rc-readiness" created
[root@host01-4 hk]# k get po -o wide
NAME                 READY     STATUS    RESTARTS   AGE       IP          NODE
rc-readiness-22hxs   0/1       Running   0          10s       10.36.0.2   host01-3.cloud.com
rc-readiness-2pt29   0/1       Running   0          10s       10.44.0.1   host01-2.cloud.com
rc-readiness-h74t2   0/1       Running   0          10s       10.36.0.1   host01-3.cloud.com
 
 
#Running 상태이지만 Ready가 아무것도 없다
 
 
 
[root@host01-4 hk]# k create -f service.yaml
service "test-svc" created
[root@host01-4 hk]# k get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   6m
test-svc     ClusterIP   10.98.99.22   <none>        80/TCP    4s
[root@host01-4 hk]# k get ep
NAME         ENDPOINTS          AGE
kubernetes   10.10.12.14:6443   6m
test-svc                        9s
 
 
#Endpoint가 아무것도 안 떠있다.
 
[root@host01-4 hk]# k exec rc-readiness-22hxs -- touch /var/ready
 
#1번 pod에 /var/ready를 만들어준다 (Ready 상태로 만들어주기 위해)
 
[root@host01-4 hk]# k get ep
NAME         ENDPOINTS          AGE
kubernetes   10.10.12.14:6443   8m
test-svc     10.36.0.2:8080     1m
 
#test-svc의 ENDPOINT가 enabled된다
 
[root@host01-4 hk]# k get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   8m
test-svc     ClusterIP   10.98.99.22   <none>        80/TCP    1m
 
[root@host01-4 hk]# k get po -o wide
NAME                 READY     STATUS    RESTARTS   AGE       IP          NODE
rc-readiness-22hxs   1/1       Running   0          4m        10.36.0.2   host01-3.cloud.com
rc-readiness-2pt29   0/1       Running   0          4m        10.44.0.1   host01-2.cloud.com
rc-readiness-h74t2   0/1       Running   0          4m        10.36.0.1   host01-3.cloud.com
 
#1번 Pod가 Ready 상태로 바뀐다
 
 
[root@host01-4 hk]# k exec rc-readiness-2pt29 -- touch /var/ready
[root@host01-4 hk]# k get po -o wide
NAME                 READY     STATUS    RESTARTS   AGE       IP          NODE
rc-readiness-22hxs   1/1       Running   0          5m        10.36.0.2   host01-3.cloud.com
rc-readiness-2pt29   1/1       Running   0          5m        10.44.0.1   host01-2.cloud.com
rc-readiness-h74t2   0/1       Running   0          5m        10.36.0.1   host01-3.cloud.com
 
#2번 Pod Ready 상태로 바뀐다
 
 
 
 
cs






*Pod = 컨테이너 그룹

rc로 제어되는 pod는 삭제하면 다시 생성된다

반면 자체적으로 만든 pod는 삭제하면 재생성되지 않음



*멀티 컨테이너 :

- create pod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
multi.yaml
 
apiVersion: v1
kind: Pod
metadata:
  name: multi
  labels:
    app: wordpress
spec:
  containers:
    - name: wordpress
      image: reg.cloud.com/wordpress
      ports:
        - containerPort: 80
        - containerPort: 443
      env:
        - name: WORDPRESS_DB_HOST
          value: 127.0.0.1
        - name: WORDPRESS_DB_USER
          value: wordpress
        - name: WORDPRESS_DB_PASSWORD
          value: password
    - name: db
      image: reg.cloud.com/mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        - name: MYSQL_DATABASE
          value: wordpress
        - name: MYSQL_USER
          value: wordpress
        - name: MYSQL_PASSWORD
          value: password
 
 
[root@host01-4 hk]# k create -f multi.yaml
 
cs



- 멀티 컨테이너에서는 컨테이너를 지정해서 들어갈 수 있다(DB랑 web이 하나의 포드로 묶여있기 때문에 좋은 구성은 아니다).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@host01-4 hk]# k get po -o wide
NAME               READY     STATUS    RESTARTS   AGE       IP          NODE
multi              2/2       Running   1          1m        10.44.0.2   host01-2.cloud.com
nginx-app-7qpbv    1/1       Running   0          1h        10.36.0.1   host01-3.cloud.com
nginx-app2-tgqqf   1/1       Running   0          1h        10.36.0.2   host01-3.cloud.com
nginx-hk-app       1/1       Running   0          1h        10.44.0.1   host01-2.cloud.com
[root@host01-4 hk]# k exec -it multi -c wordpress sh
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue state UP group default
    link/ether 32:a0:1d:fb:91:b1 brd ff:ff:ff:ff:ff:ff
    inet 10.44.0.2/12 brd 10.47.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::30a0:1dff:fefb:91b1/64 scope link tentative dadfailed
       valid_lft forever preferred_lft forever
# ^C
# hostname
multi
# [root@host01-4 hk]# k exec -it multi -c db sh
# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
#
 
cs





*Label 정보 확인

1
2
3
4
5
6
7
8
9
 
[root@host01-4 hk]# k get po --show-labels
NAME               READY     STATUS    RESTARTS   AGE       LABELS
multi              2/2       Running   1          5m        app=wordpress
nginx-app-7qpbv    1/1       Running   0          1h        run=nginx-app
nginx-app2-tgqqf   1/1       Running   0          1h        type=test
nginx-hk-app       1/1       Running   0          1h        type=web
[root@host01-4 hk]#
 
cs


*Label 조회/생성/Overwrite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@host01-4 hk]# k get po --show-labels
NAME               READY     STATUS    RESTARTS   AGE       LABELS
multi              2/2       Running   1          5m        app=wordpress
nginx-app-7qpbv    1/1       Running   0          1h        run=nginx-app
nginx-app2-tgqqf   1/1       Running   0          1h        type=test
nginx-hk-app       1/1       Running   0          1h        type=web
[root@host01-4 hk]# ^C
[root@host01-4 hk]# k label po simple-pod loc=seoul
Error from server (NotFound): pods "simple-pod" not found
[root@host01-4 hk]# k label po nginx-app-7qpbv loc=seoul
pod "nginx-app-7qpbv" labeled
[root@host01-4 hk]# k label po nginx-app-7qpbv type=was --overwrite
pod "nginx-app-7qpbv" labeled
[root@host01-4 hk]#
 
cs



*Pod 찾기(-l 옵션으로 key=value 방식으로 가져올 수 있음) :

1
2
3
4
5
6
7
8
9
10
11
[root@host01-4 hk]# k get po -l type=test
NAME               READY     STATUS    RESTARTS   AGE
nginx-app2-tgqqf   1/1       Running   0          1h
[root@host01-4 hk]# ^C
[root@host01-4 hk]# k get po -l type
NAME               READY     STATUS    RESTARTS   AGE
nginx-app-7qpbv    1/1       Running   0          1h
nginx-app2-tgqqf   1/1       Running   0          1h
nginx-hk-app       1/1       Running   0          1h
[root@host01-4 hk]#
 
cs


*Pod 찾기(-L : Label로 찾기)

1
2
3
4
5
6
7
8
[root@host01-4 hk]# k get po -L app,type,loc
NAME               READY     STATUS    RESTARTS   AGE       APP         TYPE      LOC
multi              2/2       Running   1          11m       wordpress
nginx-app-7qpbv    1/1       Running   0          1h                    was       seoul
nginx-app2-tgqqf   1/1       Running   0          1h                    test
nginx-hk-app       1/1       Running   0          1h                    web
[root@host01-4 hk]#
 
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@host01-4 hk]# k get po
NAME               READY     STATUS    RESTARTS   AGE
multi              2/2       Running   1          15m
nginx-app-7qpbv    1/1       Running   0          1h
nginx-app2-tgqqf   1/1       Running   0          1h
nginx-hk-app       1/1       Running   0          1h
nginx-hk-app2      0/1       Pending   0          32s
[root@host01-4 hk]# k get no
NAME                 STATUS    ROLES     AGE       VERSION
host01-2.cloud.com   Ready     <none>    3h        v1.10.3
host01-3.cloud.com   Ready     <none>    3h        v1.10.3
host01-4.cloud.com   Ready     master    3h        v1.10.3
 
[root@host01-4 hk]# k label no host01-2.cloud.com gpu=true
node "host01-2.cloud.com" labeled
[root@host01-4 hk]# k get no --show-labels
NAME                 STATUS    ROLES     AGE       VERSION   LABELS
host01-2.cloud.com   Ready     <none>    3h        v1.10.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,gpu=true,kubernetes.io/hostname=host01-2.cloud.com
host01-3.cloud.com   Ready     <none>    3h        v1.10.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=host01-3.cloud.com
host01-4.cloud.com   Ready     master    3h        v1.10.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=host01-4.cloud.com,node-role.kubernetes.io/master=
[root@host01-4 hk]# k get po -o wide
NAME               READY     STATUS    RESTARTS   AGE       IP          NODE
multi              2/2       Running   1          17m       10.44.0.2   host01-2.cloud.com
nginx-app-7qpbv    1/1       Running   0          1h        10.36.0.1   host01-3.cloud.com
nginx-app2-tgqqf   1/1       Running   0          1h        10.36.0.2   host01-3.cloud.com
nginx-hk-app       1/1       Running   0          1h        10.44.0.1   host01-2.cloud.com
nginx-hk-app2      1/1       Running   0          3m        10.44.0.3   host01-2.cloud.com
 
cs





* 전체 삭제

1
2
3
4
5
6
7
[root@host01-4 hk]# k delete all --all
pod "multi" deleted
service "kubernetes" deleted
[root@host01-4 hk]# k get rc
No resources found.
[root@host01-4 hk]#
 
cs


*create rc(2replicas) + describe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
apiVersion: v1
kind: ReplicationController
metadata:
  labels:
  name: simple-rc
spec:
  replicas: 2
  template:
    metadata:
      labels:
        type: test
    spec:
      containers:
      - image: reg.cloud.com/nginx
        name: nginx-app
        ports:
        - containerPort: 80
          protocol: TCP
 
 
[root@host01-4 hk]# k create -f rc.yaml
replicationcontroller "simple-rc" created
[root@host01-4 hk]# get rc
-bash: get: command not found
[root@host01-4 hk]# k get rc
NAME        DESIRED   CURRENT   READY     AGE
simple-rc   2         2         2         5s
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
simple-rc-26m58   1/1       Running   0          21s       10.44.0.1   host01-2.cloud.com
simple-rc-7htdc   1/1       Running   0          21s       10.36.0.1   host01-3.cloud.com
[root@host01-4 hk]# vi rc.yaml
 
 
[root@host01-4 hk]# k describe rc simple-rc
Name:         simple-rc
Namespace:    default
Selector:     type=test
Labels:       type=test
Annotations:  <none>
Replicas:     2 current / 2 desired
Pods Status:  2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  type=test
  Containers:
   nginx-app:
    Image:        reg.cloud.com/nginx
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                    Message
  ----    ------            ----  ----                    -------
  Normal  SuccessfulCreate  1m    replication-controller  Created pod: simple-rc-7htdc
  Normal  SuccessfulCreate  1m    replication-controller  Created pod: simple-rc-26m58
[root@host01-4 hk]#
 
cs



*Label 조회

1
2
3
4
5
6
[root@host01-4 hk]# k get po --show-labels
NAME              READY     STATUS    RESTARTS   AGE       LABELS
simple-rc-26m58   1/1       Running   0          2m        type=test
simple-rc-7htdc   1/1       Running   0          2m        type=test
[root@host01-4 hk]#
 
cs


*Label 값 수정 : 

1
2
3
4
5
6
7
8
root@host01-4 hk]# k label po simple-rc-26m58 loc=se
pod "simple-rc-26m58" labeled
[root@host01-4 hk]# k get po --show-labels
NAME              READY     STATUS    RESTARTS   AGE       LABELS
simple-rc-26m58   1/1       Running   0          3m        loc=se,type=test
simple-rc-7htdc   1/1       Running   0          3m        type=test
[root@host01-4 hk]#
 
cs


*Label overwrite(하나의 pod가 추가 생성된다)

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@host01-4 hk]# k get po --show-labels
NAME              READY     STATUS    RESTARTS   AGE       LABELS
simple-rc-26m58   1/1       Running   0          4m        loc=se,type=test
simple-rc-7htdc   1/1       Running   0          4m        type=test
[root@host01-4 hk]# k label po simple-rc-26m58 type=op --overwrite
pod "simple-rc-26m58" labeled
[root@host01-4 hk]# k get po --show-labels
NAME              READY     STATUS    RESTARTS   AGE       LABELS
simple-rc-26m58   1/1       Running   0          5m        loc=se,type=op
simple-rc-7htdc   1/1       Running   0          5m        type=test
simple-rc-bts7r   1/1       Running   0          3s        type=test
[root@host01-4 hk]#
 
cs


*RC replicas Scale out :

1
2
3
[root@host01-4 hk]# k scale rc simple-rc --replicas=3
replicationcontroller "simple-rc" scaled
 
cs


*RC를 yaml 파일로 띄워서 수정(replicas부분을 2로 변경 시 바로 2개로 수정되어 뜬다- 1가 죽음)

1
2
3
4
5
6
7
8
9
[root@host01-4 hk]# k edit rc simple-rc
replicationcontroller "simple-rc" edited
[root@host01-4 hk]# k get po --show-labels
NAME              READY     STATUS        RESTARTS   AGE       LABELS
simple-rc-26m58   1/1       Running       0          8m        loc=se,type=op
simple-rc-7htdc   1/1       Running       0          8m        type=test
simple-rc-9cmhk   0/1       Terminating   0          51s       type=test
simple-rc-bts7r   1/1       Running       0          3m        type=test
 
cs


*disk를 ssd로 해서 띄우기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
  name: simple-ds
spec:
  selector:
    matchLabels:
      type: app #selector는 template.labels.type과 
  template:
    metadata:
      labels:
        type: app
    spec:
      nodeSelector:
        disk: ssd  # 추가됨
      containers:
      - image: reg.cloud.com/nginx
        name: nginx-app
        ports:
        - containerPort: 80
          protocol: TCP
 
 
[root@host01-4 hk]# vi rc.yaml
[root@host01-4 hk]# k create -f rc.yaml
daemonset.apps "simple-ds" created
[root@host01-4 hk]#
 
cs


*node 조회

1
2
3
4
5
6
[root@host01-4 hk]# k get no
NAME                 STATUS    ROLES     AGE       VERSION
host01-2.cloud.com   Ready     <none>    4h        v1.10.3
host01-3.cloud.com   Ready     <none>    4h        v1.10.3
host01-4.cloud.com   Ready     master    4h        v1.10.3
 
cs


*Labeling 후 pod로 ssd가 생성이 되었는지 확인(disk=ssd)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@host01-4 hk]# k get no
NAME                 STATUS    ROLES     AGE       VERSION
host01-2.cloud.com   Ready     <none>    4h        v1.10.3
host01-3.cloud.com   Ready     <none>    4h        v1.10.3
host01-4.cloud.com   Ready     master    4h        v1.10.3
[root@host01-4 hk]# k label no host01-2.cloud.com disk=ssd
node "host01-2.cloud.com" labeled
[root@host01-4 hk]# get no --show-labels
-bash: get: command not found
[root@host01-4 hk]# k get no --show-labels
NAME                 STATUS    ROLES     AGE       VERSION   LABELS
host01-2.cloud.com   Ready     <none>    4h        v1.10.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,gpu=true,kubernetes.io/hostname=host01-2.cloud.com
host01-3.cloud.com   Ready     <none>    4h        v1.10.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=host01-3.cloud.com
host01-4.cloud.com   Ready     master    4h        v1.10.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=host01-4.cloud.com,node-role.kubernetes.io/master=
[root@host01-4 hk]# k get ds
NAME        DESIRED   CURRENT   READY     UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
simple-ds   1         1         1         1            1           disk=ssd        3m
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
simple-ds-vv5lp   1/1       Running   0          1m        10.44.0.3   host01-2.cloud.com
simple-rc-26m58   1/1       Running   0          22m       10.44.0.1   host01-2.cloud.com
simple-rc-7htdc   1/1       Running   0          22m       10.36.0.1   host01-3.cloud.com
simple-rc-bts7r   1/1       Running   0          17m       10.44.0.2   host01-2.cloud.com
[root@host01-4 hk]#
 
cs



*Labeling을 disk=hhd로 overwrite 할 시 다시 pod 리스트에서 빠져버린다.


1
2
3
4
[root@host01-4 hk]# k get ds
NAME        DESIRED   CURRENT   READY     UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
simple-ds   0         0         0         0            0           disk=ssd        8m
 
cs

1
2
3
4
5
6
7
8
9
[root@host01-4 hk]# k label no host01-2.cloud.com disk=hdd --overwrite
node "host01-2.cloud.com" labeled
 
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
simple-rc-26m58   1/1       Running   0          23m       10.44.0.1   host01-2.cloud.com
simple-rc-7htdc   1/1       Running   0          23m       10.36.0.1   host01-3.cloud.com
simple-rc-bts7r   1/1       Running   0          18m       10.44.0.2   host01-2.cloud.com
 
cs




*내부 연결에 있어서는 Cluster IP가 Core Service!!!

(External LB > Node Port(Kubernetes) > Cluster IP(Kubernetes))


네임으로 날리면 DNS에서 제어해서 

알아서 백단의 VIP로 redirection 시켜준다


1) External LB => Node Port=> DB(NS) => VIP => DB POD

2) External LB => Node Port=> LB(NS) => VIP => WEB POD1, WEB POD2



*kubectl pod Watch 명령어 :

1
2
3
4
5
[root@host01-4 hk]# k get po -o wide --watch
NAME              READY     STATUS    RESTARTS   AGE       IP        NODE
simple-rc-bdvs6   0/1       Pending   0          38s       <none>    <none>
simple-rc-d5h74   0/1       Pending   0          38s       <none>    <none>
simple-rc-fq6hl   0/1       Pending   0          38s       <none>    <none>
cs

 




*Service 만들기(Cluster IP = 내부 LB역할을 한다) - Pod IP는 가변적으로 기억할 필요 없음 :


-service 조회

1
2
3
4
5
[root@host01-4 hk]# k get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   12m
test-svc     ClusterIP   10.96.25.31   <none>        80/TCP    8m
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
vi service yalm
 
apiVersion: v1
kind: Service
metadata:
  name: test-svc
spec:
        selector:
          type: test
        ports:
        - port: 80
          targetPort: 8080
 
[root@host01-4 hk]# k create -f service.yaml
service "test-svc" created
 
[root@host01-4 hk]# k get service
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   3m
test-svc     ClusterIP   10.96.25.31   <none>        80/TCP    6s
 
 
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
simple-rc-c8bcs   1/1       Running   0          4m        10.36.0.1   host01-3.cloud.com
simple-rc-nfssk   1/1       Running   0          4m        10.44.0.1   host01-2.cloud.com
simple-rc-zgcjv   1/1       Running   0          4m        10.36.0.2   host01-3.cloud.com
[root@host01-4 hk]# curl 10.96.25.31
You've hit simple-rc-zgcjv
[root@host01-4 hk]# curl 10.96.25.31
You've hit simple-rc-c8bcs
[root@host01-4 hk]# curl 10.96.25.31
You've hit simple-rc-zgcjv
cs


*Service 이름 만으로 Curl 가능

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@host01-4 hk]# k exec -it simple-rc-c8bcs bash
root@simple-rc-c8bcs:/# curl http://test-svc
 
You've hit simple-rc-c8bcs
root@simple-rc-c8bcs:/#
root@simple-rc-c8bcs:/# cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local cloud.com
options ndots:5
root@simple-rc-c8bcs:/# curl http://test-svc.default
You've hit simple-rc-zgcjv
root@simple-rc-c8bcs:/# curl http://test-svc.default.svc
You've hit simple-rc-zgcjv
cs


*한번 연결되면 동일 Client는 동일 IP로 가도록 설정(similar to Sticky Session) : 


1
2
sessionAffinity: ClientIP  #  부분을 ClientIP로 바꿔주면 Sticky Session으로 변경된다
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
[root@host01-4 hk]# k edit svc test-svc
service "test-svc" edited
 
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2018-05-25T06:55:52Z
  name: test-svc
  namespace: default
  resourceVersion: "25644"
  selfLink: /api/v1/namespaces/default/services/test-svc
  uid: aa440afa-5fe8-11e8-8e09-005056b28b62
spec:
  clusterIP: 10.96.25.31
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    type: test
  sessionAffinity: ClientIP  #  부분을 ClientIP로 바꿔주면 Sticky Session으로 변경된다
  type: ClusterIP
status:
  loadBalancer: {}
 
 
[root@host01-4 hk]# k get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   15m
test-svc     ClusterIP   10.96.25.31   <none>        80/TCP    11m
 
[root@host01-4 hk]# k get pod -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
simple-rc-c8bcs   1/1       Running   0          15m       10.36.0.1   host01-3.cloud.com
simple-rc-nfssk   1/1       Running   0          15m       10.44.0.1   host01-2.cloud.com
simple-rc-zgcjv   1/1       Running   0          15m       10.36.0.2   host01-3.cloud.com
 
[root@host01-4 hk]# curl 10.96.25.31
You've hit simple-rc-nfssk
[root@host01-4 hk]# curl 10.96.25.31
You've hit simple-rc-nfssk
[root@host01-4 hk]# curl 10.96.25.31
You've hit simple-rc-nfssk
[root@host01-4 hk]#
cs



*Service Endpoint 확인(매핑 정보를 알 수 있다) :

1
2
3
4
5
[root@host01-4 hk]# k get ep
NAME         ENDPOINTS                                      AGE
kubernetes   10.10.12.14:6443                               17m
test-svc     10.36.0.1:8080,10.36.0.2:8080,10.44.0.1:8080   13m
 
cs




*Endpoint 만들기


endpoint는 service와 이름(label name)이 같아야 한다:

> k get svc 

입력 시 뜨는 name과 동일...그 이후에 

> k get ep 

를 입력 시 endpoint로 ip port가 잘 매핑되어 출력되는 것을 확인 할 수 있다



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@host01-4 hk]# k get svc
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
headless-svc   ClusterIP   10.96.102.169   <none>        80/TCP    2m
kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP   23m
test-svc       ClusterIP   10.96.25.31     <none>        80/TCP    19m
 
vi endpoint.yaml
 
apiVersion: v1
kind: Endpoints
metadata:
  name: headless-svc
subsets:
  - addresses:
    - ip: 10.10.10.10
    - ip: 11.11.11.11
    ports:
      - port: 80
 
 
#위에서 metadata.name = service name(headless-svc )과 같아야 한다
 
 
 
[root@host01-4 hk]# k create -f endpoint.yaml
endpoints "headless-svc" created
[root@host01-4 hk]# k get service
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
headless-svc   ClusterIP   10.96.102.169   <none>        80/TCP    6m
kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP   27m
test-svc       ClusterIP   10.96.25.31     <none>        80/TCP    23m
 
[root@host01-4 hk]# k get ep
NAME           ENDPOINTS                                      AGE
headless-svc   10.10.10.10:80,11.11.11.11:80                  19s
kubernetes     10.10.12.14:6443                               27m
test-svc       10.36.0.1:8080,10.36.0.2:8080,10.44.0.1:8080   24m
 
cs

*Kubernetes는 다음을 자동으로 처리하는 common API와 self-heading 프레임워크를 제공한다 : 

- 머신 장애

- 어플리케이션 배포, 로깅 모니터링 간소화


최소한의 통제로 자율성을 얻기 위한 툴이다!


점차 Operation 팀의 역할은 줄어들고 있다...

비즈니스는 점점 서비스와 어플리케이션에 포커스를 두고...인프라는 비중이 작아지고 있음


*Kubernetes의 구성도 : 


1) API Node

Kubernetes의 모든 API서버는 Node들의 모든 정보를 가지고 있어야 한다.

스케줄러가 제일 먼저 하는 일은....어디에 배포할 것인가 결정

API Node 내에 controller manager(replication controller)는 node의 status를 알려준다.

->Kubernetes는 ETCD라는 분산형태 DB를 사용한다,



2) Worker Node 

Core OS가 Rocket(docker가 너무 무거워)이라는 컨테이너를 발표!

Kubelet은 컨테이너에 대한 구성요소 제어를 맡고 있음

각 pod간 통신은 VXLAN(overlay)를 사용

proxy는 app 레벨의 인스턴스가 있고,

실제 호스트에 있는 iptables (kernel 레이어에 있음)에 데이터 처리에 관한 내용이 있음



※ kubelet은 유일하게 시스템 서비스로 들어간다! 나머지는 컨테이너로 설치 가능



- 왜 Swarm을 사용하는가? 사용하기 쉬움

- 왜 Kubernetes를 사용하는가? 많은 Resource를 제어할 수 있음





1. Docker 설치 (모든 노드)


1
2
3
4
5
6
7
8
9
yum install -y docker
systemctl enable docker && systemctl start docker
 
touch /etc/docker/daemon.json
cat <<EOF > /etc/docker/daemon.json
{
"insecure-registries":["10.10.12.0/24"]
}
EOF
cs


2. Kubernetes 설치 (모든 노드)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
sed ---follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
systemctl stop firewalld.service
systemctl disable firewalld.service
 
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
 
swapoff -&& sed -'/swap/s/^/#/' /etc/fstab
 
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet


*MASTER Node 설치(이미지를 전부 다 Load한다) :

> docker load -i <이미지명>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[root@host01-2 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@host01-2 ~]# ls
anaconda-ks.cfg  dns-kube-dns  dns-sidecar  etcd-amd64  hk
[root@host01-2 ~]# cd hk
[root@host01-2 hk]# ls
dns-kube-dns  etcd-amd64  kubeadm.host08-1.root.log.INFO.20180525-060140.2620  kube-apiserver   kube-proxy      weave-kube
dns-sidecar   k8s-dns     kubeadm.INFO                                         kube-controller  kube-scheduler  weave-npc
[root@host01-2 hk]# ls -al
total 974632
drwxr-xr-x. 2 root root       277 May 25 10:27 .
dr-xr-x---5 root root       226 May 25 10:27 ..
-rw-------1 root root  50727424 May 25 10:27 dns-kube-dns
-rw-------1 root root  42481152 May 25 10:27 dns-sidecar
-rw-------1 root root 193461760 May 25 10:27 etcd-amd64
-rw-------1 root root  41239040 May 25 10:27 k8s-dns
-rw-r--r--1 root root       343 May 25 10:27 kubeadm.host08-1.root.log.INFO.20180525-060140.2620
-rw-r--r--1 root root       343 May 25 10:27 kubeadm.INFO
-rw-------1 root root 225319936 May 25 10:27 kube-apiserver
-rw-------1 root root 148110336 May 25 10:27 kube-controller
-rw-------1 root root  98924032 May 25 10:27 kube-proxy
-rw-------1 root root  50635776 May 25 10:27 kube-scheduler
-rw-------1 root root  99517952 May 25 10:27 weave-kube
-rw-------1 root root  47575552 May 25 10:27 weave-npc
[root@host01-2 hk]# docker load -i kube-proxy
582b548209e1: Loading layer [==================================================>]  44.2 MB/44.2 MB
e20569a478ed: Loading layer [==================================================>3.358 MB/3.358 MB
6b4e4941a965: Loading layer [==================================================>51.35 MB/51.35 MB
Loaded image: k8s.gcr.io/kube-proxy-amd64:v1.10.3
[root@host01-2 hk]# docker load -i weave-kube
5bef08742407: Loading layer [==================================================>4.221 MB/4.221 MB
c3355c8b5c3e: Loading layer [==================================================>19.03 MB/19.03 MB
a83fa3df4138: Loading layer [==================================================>29.55 MB/29.55 MB
020fdc01af85: Loading layer [==================================================>]  11.6 MB/11.6 MB
2ea881a632b7: Loading layer [==================================================>2.048 kB/2.048 kB
396aa46bcbea: Loading layer [==================================================>35.09 MB/35.09 MB
Loaded image: docker.io/weaveworks/weave-kube:2.3.0
[root@host01-2 hk]# docker load -i weave-npc
8dccfe2dec8c: Loading layer [==================================================>2.811 MB/2.811 MB
3249ff6df12f: Loading layer [==================================================>40.52 MB/40.52 MB
3dc458d34b22: Loading layer [==================================================>]  2.56 kB/2.56 kB
Loaded image: docker.io/weaveworks/weave-npc:2.3.0
[root@host01-2 hk]#
 
cs

*기타 Node 설치(kube-proxy, weave-kube, weave-npc를 설치한다) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[root@host01-2 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@host01-2 ~]# ls
anaconda-ks.cfg  dns-kube-dns  dns-sidecar  etcd-amd64  hk
[root@host01-2 ~]# cd hk
[root@host01-2 hk]# ls
dns-kube-dns  etcd-amd64  kubeadm.host08-1.root.log.INFO.20180525-060140.2620  kube-apiserver   kube-proxy      weave-kube
dns-sidecar   k8s-dns     kubeadm.INFO                                         kube-controller  kube-scheduler  weave-npc
[root@host01-2 hk]# ls -al
total 974632
drwxr-xr-x. 2 root root       277 May 25 10:27 .
dr-xr-x---5 root root       226 May 25 10:27 ..
-rw-------1 root root  50727424 May 25 10:27 dns-kube-dns
-rw-------1 root root  42481152 May 25 10:27 dns-sidecar
-rw-------1 root root 193461760 May 25 10:27 etcd-amd64
-rw-------1 root root  41239040 May 25 10:27 k8s-dns
-rw-r--r--1 root root       343 May 25 10:27 kubeadm.host08-1.root.log.INFO.20180525-060140.2620
-rw-r--r--1 root root       343 May 25 10:27 kubeadm.INFO
-rw-------1 root root 225319936 May 25 10:27 kube-apiserver
-rw-------1 root root 148110336 May 25 10:27 kube-controller
-rw-------1 root root  98924032 May 25 10:27 kube-proxy
-rw-------1 root root  50635776 May 25 10:27 kube-scheduler
-rw-------1 root root  99517952 May 25 10:27 weave-kube
-rw-------1 root root  47575552 May 25 10:27 weave-npc
[root@host01-2 hk]# docker load -i kube-proxy
582b548209e1: Loading layer [==================================================>]  44.2 MB/44.2 MB
e20569a478ed: Loading layer [==================================================>3.358 MB/3.358 MB
6b4e4941a965: Loading layer [==================================================>51.35 MB/51.35 MB
Loaded image: k8s.gcr.io/kube-proxy-amd64:v1.10.3
[root@host01-2 hk]# docker load -i weave-kube
5bef08742407: Loading layer [==================================================>4.221 MB/4.221 MB
c3355c8b5c3e: Loading layer [==================================================>19.03 MB/19.03 MB
a83fa3df4138: Loading layer [==================================================>29.55 MB/29.55 MB
020fdc01af85: Loading layer [==================================================>]  11.6 MB/11.6 MB
2ea881a632b7: Loading layer [==================================================>2.048 kB/2.048 kB
396aa46bcbea: Loading layer [==================================================>35.09 MB/35.09 MB
Loaded image: docker.io/weaveworks/weave-kube:2.3.0
[root@host01-2 hk]# docker load -i weave-npc
8dccfe2dec8c: Loading layer [==================================================>2.811 MB/2.811 MB
3249ff6df12f: Loading layer [==================================================>40.52 MB/40.52 MB
3dc458d34b22: Loading layer [==================================================>]  2.56 kB/2.56 kB
Loaded image: docker.io/weaveworks/weave-npc:2.3.0
[root@host01-2 hk]#
 
cs


*Master Node에서 실행 :

1
2
3
4
5
kubeadm init
 
mkdir -p $HOME/.kube
cp -/etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
cs


실행방법 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[root@host01-4 ~]# docker images
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy-amd64                v1.10.3             4261d315109d        3 days ago          97.1 MB
k8s.gcr.io/kube-apiserver-amd64            v1.10.3             e03746fe22c3        3 days ago          225 MB
k8s.gcr.io/kube-controller-manager-amd64   v1.10.3             40c8d10b2d11        3 days ago          148 MB
k8s.gcr.io/kube-scheduler-amd64            v1.10.3             353b8f1d102e        3 days ago          50.4 MB
docker.io/weaveworks/weave-npc             2.3.0               21545eb3d6f9        6 weeks ago         47.2 MB
docker.io/weaveworks/weave-kube            2.3.0               f15514acce73        6 weeks ago         96.8 MB
k8s.gcr.io/etcd-amd64                      3.1.12              52920ad46f5b        2 months ago        193 MB
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64     1.14.8              c2ce1ffb51ed        4 months ago        41 MB
k8s.gcr.io/k8s-dns-sidecar-amd64           1.14.8              6f7f2dc7fab5        4 months ago        42.2 MB
k8s.gcr.io/k8s-dns-kube-dns-amd64          1.14.8              80cc5ea4b547        4 months ago        50.5 MB
[root@host01-4 ~]# clear
[root@host01-4 ~]# kubeadm init
[init] Using Kubernetes version: v1.10.3
[init] Using Authorization modes: [Node RBAC]
[preflight] Running pre-flight checks.
        [WARNING FileExisting-crictl]: crictl not found in system path
Suggestion: go get github.com/kubernetes-incubator/cri-tools/cmd/crictl
[certificates] Generated ca certificate and key.
[certificates] Generated apiserver certificate and key.
[certificates] apiserver serving cert is signed for DNS names [host01-4.cloud.com kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.10.12.14]
[certificates] Generated apiserver-kubelet-client certificate and key.
[certificates] Generated etcd/ca certificate and key.
[certificates] Generated etcd/server certificate and key.
[certificates] etcd/server serving cert is signed for DNS names [localhost] and IPs [127.0.0.1]
[certificates] Generated etcd/peer certificate and key.
[certificates] etcd/peer serving cert is signed for DNS names [host01-4.cloud.com] and IPs [10.10.12.14]
[certificates] Generated etcd/healthcheck-client certificate and key.
[certificates] Generated apiserver-etcd-client certificate and key.
[certificates] Generated sa key and public key.
[certificates] Generated front-proxy-ca certificate and key.
[certificates] Generated front-proxy-client certificate and key.
[certificates] Valid certificates and keys now exist in "/etc/kubernetes/pki"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"
[controlplane] Wrote Static Pod manifest for component kube-apiserver to "/etc/kubernetes/manifests/kube-apiserver.yaml"
[controlplane] Wrote Static Pod manifest for component kube-controller-manager to "/etc/kubernetes/manifests/kube-controller-manager.yaml"
[controlplane] Wrote Static Pod manifest for component kube-scheduler to "/etc/kubernetes/manifests/kube-scheduler.yaml"
[etcd] Wrote Static Pod manifest for a local etcd instance to "/etc/kubernetes/manifests/etcd.yaml"
[init] Waiting for the kubelet to boot up the control plane as Static Pods from directory "/etc/kubernetes/manifests".
[init] This might take a minute or longer if the control plane images have to be pulled.
[apiclient] All control plane components are healthy after 25.003852 seconds
[uploadconfig] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[markmaster] Will mark node host01-4.cloud.com as master by adding a label and a taint
[markmaster] Master host01-4.cloud.com tainted and labelled with key/value: node-role.kubernetes.io/master=""
[bootstraptoken] Using token: hlz7wp.qjrgmsq2yn9f94wa
[bootstraptoken] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstraptoken] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstraptoken] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstraptoken] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: kube-dns
[addons] Applied essential addon: kube-proxy
 
Your Kubernetes master has initialized successfully!
 
To start using your cluster, you need to run the following as a regular user:
 
  mkdir -p $HOME/.kube
  sudo cp -/etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/
 
You can now join any number of machines by running the following on each node
as root:
 
  kubeadm join 10.10.12.14:6443 --token hlz7wp.qjrgmsq2yn9f94wa --discovery-token-ca-cert-hash sha256:43e61417b20ede5ca530fe0638990bc1a805b5f2a9e25b5aa2f40023b392fb50
 
[root@host01-4 ~]#
[root@host01-4 ~]# mkdir -p $HOME/.kube
[root@host01-4 ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@host01-4 ~]# chown $(id -u):$(id -g) $HOME/.kube/config
[root@host01-4 ~]#
 
cs


위 실행결과에서 토큰을 복사해놓는다 :

1
2
3
  kubeadm join 10.10.12.14:6443 --token hlz7wp.qjrgmsq2yn9f94wa --discovery-token-ca-cert-hash sha256:43e61417b20ede5ca530fe0638990bc1a805b5f2a9e25b5aa2f40023b392fb50
 
 
cs


*Pod Network 설치 (마스터)

1
2
3
4
5
6
7
sysctl net.bridge.bridge-nf-call-iptables=1
 
export kubever=$(kubectl version | base64 | tr -'\n')
 
kubectl apply -"https://cloud.weave.works/k8s/net?k8s-version=$kubever"
 
kubectl get pods --all-namespaces 
cs


실행결과 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@host01-4 ~]# sysctl net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-iptables = 1
[root@host01-4 ~]#
[root@host01-4 ~]# export kubever=$(kubectl version | base64 | tr -d '\n')
[root@host01-4 ~]#
[root@host01-4 ~]# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"
serviceaccount "weave-net" created
clusterrole.rbac.authorization.k8s.io "weave-net" created
clusterrolebinding.rbac.authorization.k8s.io "weave-net" created
role.rbac.authorization.k8s.io "weave-net" created
rolebinding.rbac.authorization.k8s.io "weave-net" created
daemonset.extensions "weave-net" created
[root@host01-4 ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                         READY     STATUS    RESTARTS   AGE
kube-system   etcd-host01-4.cloud.com                      1/1       Running   0          4m
kube-system   kube-apiserver-host01-4.cloud.com            1/1       Running   0          4m
kube-system   kube-controller-manager-host01-4.cloud.com   1/1       Running   0          5m
kube-system   kube-dns-86f4d74b45-t9df2                    0/3       Pending   0          5m
kube-system   kube-proxy-fs9d8                             1/1       Running   0          5m
kube-system   kube-scheduler-host01-4.cloud.com            1/1       Running   0          4m
kube-system   weave-net-zr5qr                              2/2       Running   0          11s
[root@host01-4 ~]#
 
 
cs


*이전에 Master Node에서 복사한 토큰을 2개 Worker Node에 각각

입력한다 : 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@host01-3 ~]# kubeadm join 10.10.12.14:6443 --token hlz7wp.qjrgmsq2yn9f94wa --discovery-token-ca-cert-hash sha256:43e61417b20ede5ca530fe0638990bc1a805b5f2a9e25b5aa2f40023b392fb50
[preflight] Running pre-flight checks.
        [WARNING FileExisting-crictl]: crictl not found in system path
Suggestion: go get github.com/kubernetes-incubator/cri-tools/cmd/crictl
[discovery] Trying to connect to API Server "10.10.12.14:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://10.10.12.14:6443"
[discovery] Requesting info from "https://10.10.12.14:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "10.10.12.14:6443"
[discovery] Successfully established connection with API Server "10.10.12.14:6443"
 
This node has joined the cluster:
* Certificate signing request was sent to master and a response
  was received.
* The Kubelet was informed of the new secure connection details.
 
Run 'kubectl get nodes' on the master to see this node join the cluster.
[root@host01-3 ~]#
 
cs


*Master Node에서 멤버 Join이 이루어졌는지 확인한다(Status에 Ready가 떠야 한다.)

1
2
3
4
5
6
7
8
 
[root@host01-4 ~]# kubectl get no
NAME                 STATUS     ROLES     AGE       VERSION
host01-2.cloud.com   NotReady   <none>    6s        v1.10.3
host01-3.cloud.com   NotReady   <none>    11s       v1.10.3
host01-4.cloud.com   Ready      master    9m        v1.10.3
[root@host01-4 ~]# ^C
 
cs
1
2
3
4
5
6
7
[root@host01-4 ~]# kubectl get no
NAME                 STATUS    ROLES     AGE       VERSION
host01-2.cloud.com   Ready     <none>    2m        v1.10.3
host01-3.cloud.com   Ready     <none>    2m        v1.10.3
host01-4.cloud.com   Ready     master    11m       v1.10.3
[root@host01-4 ~]#
 
cs






*Tab 자동 입력


AWS, Azure에서는 kubectl 명령어가 그냥 'k'임(alias로 등록되어 있음)


*Alias 등록 : 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[root@host01-4 ~]# alias k=kubectl
[root@host01-4 ~]# source <(kubectl completion bash | sed  s/kubectl/k/g)
[root@host01-4 ~]# k get
You must specify the type of resource to get. Valid resource types include:
 
  * all
  * certificatesigningrequests (aka 'csr')
  * clusterrolebindings
  * clusterroles
  * 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')
  * ingresses (aka 'ing')
  * jobs
  * limitranges (aka 'limits')
  * namespaces (aka 'ns')
  * networkpolicies (aka 'netpol')
  * nodes (aka 'no')
  * persistentvolumeclaims (aka 'pvc')
  * persistentvolumes (aka 'pv')
  * poddisruptionbudgets (aka 'pdb')
  * podpreset
  * pods (aka 'po')
  * podsecuritypolicies (aka 'psp')
  * podtemplates
  * replicasets (aka 'rs')
  * replicationcontrollers (aka 'rc')
  * resourcequotas (aka 'quota')
  * rolebindings
  * roles
  * secrets
  * serviceaccounts (aka 'sa')
  * services (aka 'svc')
  * statefulsets (aka 'sts')
  * storageclasses (aka 'sc')error: Required resource not specified.
Use "kubectl explain <resource>" for a detailed description of that resource (e.g. kubectl explain pods).
See 'kubectl get -h' for help and examples.
[root@host01-4 ~]# echo "alias l=kubectl" >> ~/.bashrc
[root@host01-4 ~]# echo "source <(kubectl completion bash | sed s/kubectl/k/g)" >> ~/.bashrc
 
cs





*Pod 개념

MS 아키텍처의 기초는 하나의 컨테이너에는 하나의 어플리케이션만 집어넣자!

- 네트워크 공유 : Pod로 구성하면 Container끼리 네트워크를 공유할 수 있게된다(네트워크 Name Space 공유 - localhost로)

- 스토리지 공유 : 볼륨을 pod에 마운트 하여 Storage까지 공유한다!


- 1개 pod 내에서 콘테이너들은 동일 호스트로만 구성이 된다. 똑같은 포트의 서비스를 공유할 수 없다.

(pod를 잘못구성하는 예 : DB Container와 Web Container를 동일 pod 내에 두었을 때 Scale Out 시 이슈가 있음,

따라서 web pod, WAS pod, DB pod 식으로 나눠야 함)

pod가 kubenetes의 최소 단위로 구성해야 함!


각 Work Node의 Pod 들은 Master Node의 replication controller(RC)에서 제어된다.


- 참조/관리 형태

참조를 하는 주체는 selector (key/value 형태)

참조를 받은 대상은 Label (key/value 형태)  = Pod(Node Selector)

Pod/Label의 참조를 받는 대상은 Label (key/value 형태) 

라고 부른다.

- Kubenetes의 Namespace란 : 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@host01-4 hk]# k get po -n kube-system -o  wide
NAME                                         READY     STATUS    RESTARTS   AGE       IP            NODE
etcd-host01-4.cloud.com                      1/1       Running   0          58m       10.10.12.14   host01-4.cloud.com
kube-apiserver-host01-4.cloud.com            1/1       Running   0          58m       10.10.12.14   host01-4.cloud.com
kube-controller-manager-host01-4.cloud.com   1/1       Running   0          59m       10.10.12.14   host01-4.cloud.com
kube-dns-86f4d74b45-t9df2                    3/3       Running   0          1h        10.32.0.2     host01-4.cloud.com
kube-proxy-fs9d8                             1/1       Running   0          1h        10.10.12.14   host01-4.cloud.com
kube-proxy-r5bzj                             1/1       Running   0          51m       10.10.12.13   host01-3.cloud.com
kube-proxy-tvwnv                             1/1       Running   0          51m       10.10.12.12   host01-2.cloud.com
kube-scheduler-host01-4.cloud.com            1/1       Running   0          59m       10.10.12.14   host01-4.cloud.com
weave-net-hf9d5                              2/2       Running   1          51m       10.10.12.12   host01-2.cloud.com
weave-net-p5drv                              2/2       Running   1          51m       10.10.12.13   host01-3.cloud.com
weave-net-zr5qr                              2/2       Running   0          54m       10.10.12.14   host01-4.cloud.com
 
cs

*Cluster PAI 확인 : 

1
2
3
4
5
[root@host01-4 hk]# k cluster-info
Kubernetes master is running at https://10.10.12.14:6443
KubeDNS is running at https://10.10.12.14:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
 
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
cs


*Pod 가 어디있는지 상관없이 연결이 된다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@host01-4 hk]# ls
dns-kube-dns  etcd-amd64  kubeadm.host08-1.root.log.INFO.20180525-060140.2620  kube-apiserver   kube-proxy      weave-kube
dns-sidecar   k8s-dns     kubeadm.INFO                                         kube-controller  kube-scheduler  weave-npc
[root@host01-4 hk]# k run --image=reg.cloud.com/nginx --port=80 --generator=run/v1
error: NAME is required for run
See 'kubectl run -h' for help and examples.
[root@host01-4 hk]# k run --image=reg.cloud.com/nginx --port=80 --generator=run/v1
error: NAME is required for run
See 'kubectl run -h' for help and examples.
[root@host01-4 hk]# k run --image=reg.cloud.com/nginx nginx-app --port=80 --generator=run/v1
replicationcontroller "nginx-app" created
[root@host01-4 hk]# k get rc
NAME        DESIRED   CURRENT   READY     AGE
nginx-app   1         1         0         8s
[root@host01-4 hk]# k get po
NAME              READY     STATUS    RESTARTS   AGE
nginx-app-gb6ch   1/1       Running   0          15s
[root@host01-4 hk]# get po -o wide
-bash: get: command not found
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-gb6ch   1/1       Running   0          32s       10.36.0.1   host01-3.cloud.com
[root@host01-4 hk]# k logs
error: expected 'logs (POD | TYPE/NAME) [CONTAINER_NAME]'.
POD or TYPE/NAME is a required argument for the logs command
See 'kubectl logs -h' for help and examples.
[root@host01-4 hk]# k logs nginx-app-df618
Error from server (NotFound): pods "nginx-app-df618" not found
[root@host01-4 hk]# k logs nginx-app-gb6ch
[root@host01-4 hk]# k exec -it
error: expected 'exec POD_NAME COMMAND [ARG1] [ARG2] ... [ARGN]'.
POD_NAME and COMMAND are required arguments for the exec command
See 'kubectl exec -h' for help and examples.
[root@host01-4 hk]# k exec -it nginx-app-gb6ch bash
root@nginx-app-gb6ch:/#
 
cs

-podname이 container의 hostname이 된다.



*pod name으로 삭제 해도 다시 살아난다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-gb6ch   1/1       Running   0          5m        10.36.0.1   host01-3.cloud.com
[root@host01-4 hk]# delete po nginx-app-gb6ch
-bash: delete: command not found
[root@host01-4 hk]# k delete po nginx-app-gb6ch
pod "nginx-app-gb6ch" deleted
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS              RESTARTS   AGE       IP        NODE
nginx-app-gnpsd   0/1       ContainerCreating   0          6s        <none>    host01-2.cloud.com
[root@host01-4 hk]# k get rc
NAME        DESIRED   CURRENT   READY     AGE
nginx-app   1         1         1         5m
[root@host01-4 hk]#
 
cs


*Scale in Scale out


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
[root@host01-4 hk]# k describe rc nginx-app
dns-kube-dns                                         kubeadm.host08-1.root.log.INFO.20180525-060140.2620  kube-proxy
dns-sidecar                                          kubeadm.INFO                                         kube-scheduler
etcd-amd64                                           kube-apiserver                                       weave-kube
k8s-dns                                              kube-controller                                      weave-npc
[root@host01-4 hk]# k describe rc nginx-app
Name:         nginx-app
Namespace:    default
Selector:     run=nginx-app
Labels:       run=nginx-app
Annotations:  <none>
Replicas:     1 current / 1 desired
Pods Status:  1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  run=nginx-app
  Containers:
   nginx-app:
    Image:        reg.cloud.com/nginx
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                    Message
  ----    ------            ----  ----                    -------
  Normal  SuccessfulCreate  6m    replication-controller  Created pod: nginx-app-gb6ch
  Normal  SuccessfulCreate  1m    replication-controller  Created pod: nginx-app-gnpsd
[root@host01-4 hk]# k get po
NAME              READY     STATUS    RESTARTS   AGE
nginx-app-gnpsd   1/1       Running   0          1m
[root@host01-4 hk]# k describe po nginx-app-gnpsd
Name:           nginx-app-gnpsd
Namespace:      default
Node:           host01-2.cloud.com/10.10.12.12
Start Time:     Fri, 25 May 2018 11:58:20 +0900
Labels:         run=nginx-app
Annotations:    <none>
Status:         Running
IP:             10.44.0.1
Controlled By:  ReplicationController/nginx-app
Containers:
  nginx-app:
    Container ID:   docker://6d0e9cb190b31334dee5dba4877ace52d8afd5a9956d7c50eae35d3107722a58
    Image:          reg.cloud.com/nginx
    Image ID:       docker-pullable://reg.cloud.com/nginx@sha256:a4fb15454c43237dbc6592c4f8e0b50160ceb03e852a10c9895cf2a6d16c7fe2
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 25 May 2018 11:58:29 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-85hdm (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          True
  PodScheduled   True
Volumes:
  default-token-85hdm:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-85hdm
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason                 Age   From                         Message
  ----    ------                 ----  ----                         -------
  Normal  SuccessfulMountVolume  1m    kubelet, host01-2.cloud.com  MountVolume.SetUp succeeded for volume "default-token-85hdm"
  Normal  Scheduled              1m    default-scheduler            Successfully assigned nginx-app-gnpsd to host01-2.cloud.com
  Normal  Pulling                1m    kubelet, host01-2.cloud.com  pulling image "reg.cloud.com/nginx"
  Normal  Pulled                 1m    kubelet, host01-2.cloud.com  Successfully pulled image "reg.cloud.com/nginx"
  Normal  Created                1m    kubelet, host01-2.cloud.com  Created container
  Normal  Started                1m    kubelet, host01-2.cloud.com  Started container
[root@host01-4 hk]# k get rc
NAME        DESIRED   CURRENT   READY     AGE
nginx-app   1         1         1         8m
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-gnpsd   1/1       Running   0          3m        10.44.0.1   host01-2.cloud.com
 
[root@host01-4 hk]# k scale rc nginx-app --replicas=3
replicationcontroller "nginx-app" scaled
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-gnpsd   1/1       Running   0          4m        10.44.0.1   host01-2.cloud.com
nginx-app-jfmkd   1/1       Running   0          10s       10.44.0.2   host01-2.cloud.com
nginx-app-ww6sn   1/1       Running   0          10s       10.36.0.1   host01-3.cloud.com
 
[root@host01-4 hk]# k scale rc nginx-app --replicas=0
replicationcontroller "nginx-app" scaled
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS        RESTARTS   AGE       IP          NODE
nginx-app-gnpsd   0/1       Terminating   0          5m        10.44.0.1   host01-2.cloud.com
nginx-app-jfmkd   0/1       Terminating   0          34s       10.44.0.2   host01-2.cloud.com
[root@host01-4 hk]# k get po -o wide
No resources found.
[root@host01-4 hk]# rc 0
-bash: rc: command not found
[root@host01-4 hk]# k scale rc nginx-app --replicas=1
replicationcontroller "nginx-app" scaled
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-7qpbv   1/1       Running   0          4s        10.36.0.1   host01-3.cloud.com
[root@host01-4 hk]#
 
cs



*Yaml으로 pod 조회

1
2
[root@host01-4 hk]# k get po nginx-app-7qpbv -o yaml
 
cs


*Yaml 파일로 추출 후 pod 생성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
apiVersion: v1
kind: Pod
metadata:
  labels:
    type: web
  name: nginx-hk-app
spec:
  containers:
  - image: reg.cloud.com/nginx
    name: nginx-app
    ports:                            #expose와 동일
    - containerPort: 80
      protocol: TCP
 
 
 
[root@host01-4 hk]# k get po nginx-app-7qpbv -o yaml > temp.yaml
[root@host01-4 hk]# vi temp.yaml
[root@host01-4 hk]# k create -f temp.yaml
pod "nginx-hk-app" created
[root@host01-4 hk]# k get po -o wide
NAME              READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-7qpbv   1/1       Running   0          6m        10.36.0.1   host01-3.cloud.com
nginx-hk-app      1/1       Running   0          13s       10.44.0.1   host01-2.cloud.com
[root@host01-4 hk]#
 
cs



*Yaml 파일로 rc 생성 후 배포 :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@host01-4 hk]# k get rc nginx-app -o yaml > hk.yaml
[root@host01-4 hk]# vi hk.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    run: nginx-app
  name: nginx-app
spec:
  replicas: 1
  selector:
    type: test
  template:
    metadata:
      labels:
        type: test
    spec:
      containers:
      - image: reg.cloud.com/nginx
        name: nginx-app
        ports:
        - containerPort: 80
          protocol: TCP
 
 
[root@host01-4 hk]# k create -f hk.yaml
replicationcontroller "nginx-app2" created
[root@host01-4 hk]# k get rc
NAME         DESIRED   CURRENT   READY     AGE
nginx-app    1         1         1         24m
nginx-app2   1         1         1         9s
[root@host01-4 hk]# k get po -o wide
NAME               READY     STATUS    RESTARTS   AGE       IP          NODE
nginx-app-7qpbv    1/1       Running   0          14m       10.36.0.1   host01-3.cloud.com
nginx-app2-tgqqf   1/1       Running   0          16s       10.36.0.2   host01-3.cloud.com
nginx-hk-app       1/1       Running   0          7m        10.44.0.1   host01-2.cloud.com
[root@host01-4 hk]#
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
yum -y install bash-completion
 
curl -sSL https://get.docker.com/ | sh
 
 
systemctl start docker
 
===cAdvisor=================================
docker run \
   --detach=true \
   --volume=/:/rootfs:ro \
   --volume=/var/run:/var/run:rw \
   --volume=/sys:/sys:ro \
   --volume=/var/lib/docker/:/var/lib/docker:ro \
   --publish=8080:8080 \
   --privileged=true \
   --name=cadvisor \
google/cadvisor:latest
 
docker service create \
   --mode global \
   --mount type=bind,source=/,destination=/rootfs,ro=1 \
   --mount type=bind,source=/var/run,destination=/var/run \
   --mount type=bind,source=/sys,destination=/sys,ro=1 \
   --mount type=bind,source=/var/lib/docker,destination=/var/lib/docker,ro=1 \
   --publish mode=host,target=8080,published=8080 \
   --name=cadvisor \
   google/cadvisor:latest
 
===Compose=========
curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-`uname -s`-`uname -m` -/usr/local/bin/docker-compose
 
chmod +/usr/local/bin/docker-compose
 
cs



1
2
3
4
5
6
{
"insecure-registries":["10.10.12.0/24"]
}
 
 
/var/dockers/daemon.json
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
version: '3.3'
 
services:
   db:
     image: reg.cloud.com/mysql:5.7
     volumes:
       - dbdata:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
 
   wordpress:
     depends_on:
       - db
     image: reg.cloud.com/wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    dbdata:
cs





+ Recent posts