*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

+ Recent posts