간단한 내용이지만 이 간단한 정보를 확인하는데 불필요한 삽질을 하였기에 도움이 될까 포스팅합니다.

서로 다른 노드에 있는 pod간 통신을 완성하기 위해서는 관련 기능을 제공하는 network plugin이 필요하다.
필자의 경우는 flannel plugin을 설치했다.

구글링하다 좋은 케이스를 찾았기에 공유

* 만약 잘못된 정보가 있으면 지적해주세요




그림을 보면 노드1에서 노드2로 다른 ip끼리 패킷을 보낼 때, 보내는 컨테이너의 출발지와 목적지를 가지고 있는 모습을 확인 할 수 있다.
그리고 flannel에서 패킷을 주고받는 node의 출발지와 목적지 정보를 UDP로 캡슐화해서 보내는 역할을 수행한다. 
이런 식으로 flannel plugin을 설치하여 컨테이너 간 통신을 할 수 있다.

테스트한 yaml파일은 아래와 같다.
$ cat cent.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - image: centos:7.2.1511
        name: test
        command: ["/bin/bash","-c","while true; do sleep 1000; done"]
        imagePullPolicy: IfNotPresent



$ cat mysql.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mysql-pod
  labels:
    name: mysql-pod
    context: docker-k8s-lab
spec:
  containers:
    -
      name: mysql
      image: mysql:5.7
      env:
        -
          name: "MYSQL_USER"
          value: "mysql"
        -
          name: "MYSQL_PASSWORD"
          value: "mysql"
        -
          name: "MYSQL_DATABASE"
          value: "sample"
        -
          name: "MYSQL_ROOT_PASSWORD"
          value: "supersecret"
      ports:
        -
          containerPort: 3306

yaml을 통해 centos, mysql을 실행하여 centos pod에서 mysql에 접속되는 지 테스트

pods 확인
$ kubectl get pods
mysql-pod                       1/1       Running   0          6m
test-6b5c774944-fqcdl           1/1       Running   0          17m


mysql을 설치해준다.
$ yum install mysql 

master서버에서 mysql pod의 ip주소 체크
$  kubectl describe pod test-6b5c774944-fqcdl
Name:               mysql-pod
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               jf-api/192.168.0.89
Start Time:         Tue, 03 Jul 2018 17:32:13 +0900
Labels:             context=docker-k8s-lab
                    name=mysql-pod
Annotations:        kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"context":"docker-k8s-lab","name":"mysql-pod"},"name":"mysql-pod","namespace":"d...
Status:             Running
IP:                 10.244.1.53
Containers:
  mysql:
    Container ID:   docker://ee63968f90c86a3062627a68c3830d425b1b385ebc61cc1c960e824411799f7e
    Image:          mysql:5.7
    Image ID:       docker-pullable://mysql@sha256:f030e84582d939d313fe2ef469b5c65ffd0f7dff3b4b98e6ec9ae2dccd83dcdf
    Port:           3306/TCP
    State:          Running
      Started:      Tue, 03 Jul 2018 17:32:16 +0900
    Ready:          True
    Restart Count:  0
    Environment:
      MYSQL_USER:           mysql
      MYSQL_PASSWORD:       mysql
      MYSQL_DATABASE:       sample
      MYSQL_ROOT_PASSWORD:  supersecret
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-dn4mq (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          True
  PodScheduled   True
Volumes:
  default-token-dn4mq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-dn4mq
    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  Scheduled              9m    default-scheduler  Successfully assigned mysql-pod to jf-api
  Normal  SuccessfulMountVolume  9m    kubelet, jf-api    MountVolume.SetUp succeeded for volume "default-token-dn4mq"
  Normal  Pulled                 9m    kubelet, jf-api    Container image "mysql:5.7" already present on machine
  Normal  Created                9m    kubelet, jf-api    Created container
  Normal  Started                9m    kubelet, jf-api    Started container


centos접속 후 mysql 접속확인
$ kubectl exec -it test-6b5c774944-fqcdl /bin/sh

sh-4.2# mysql -h10.244.1.22 -umysql -pmysql -Dsample
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [sample]

이와 같이 pod간 커뮤니케이션을 flannel을 통해 할 수 있다는 것을 확인했다.!




 



'apps > docker' 카테고리의 다른 글

쿠버네티스란 무엇인가?  (0) 2018.08.18
도커란 무엇인가?  (0) 2018.08.04
도커에서 nodejs+mongodb 테스트  (0) 2018.07.01
kubernetes에서 gpu pod생성( nvidia-docker2 )  (2) 2018.05.30
centos7에서 nvidia driver설치하기  (0) 2018.05.28

+ Recent posts