관리 메뉴

피터의 개발이야기

[CKA] Udemy 실습문제풀이 - Networking 본문

Kubernetes/CKA&CKAD

[CKA] Udemy 실습문제풀이 - Networking

기록하는 백앤드개발자 2024. 1. 27. 14:21
반응형

 

[kubernetes] 쿠버네티스 관련 글 목차

 

ㅁ 들어가며

ㅇ Udemy, Practice, Networking 공부 메모.

ㅁ 관련 글

Installing Addons

Cluster Networking

[kubernetes network] CNI란?

 

ㅁ Explore Environment

network interface chk?

# node internal ip chk
$ k get no -o wide
NAME           STATUS   ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane   15m   v1.27.0   192.7.203.9    <none>        Ubuntu 20.04.6 LTS   5.4.0-1106-gcp   containerd://1.6.6
node01         Ready    <none>          15m   v1.27.0   192.7.203.12   <none>        Ubuntu 20.04.5 LTS   5.4.0-1106-gcp   containerd://1.6.6

$ ip a | grep 192.7.203.255
inet 192.7.203.9/24 brd 192.7.203.255 scope global eth0

 

node01에 할당된(assigned) IP 주소는 무엇입니까?

$  k get no -o wide
NAME           STATUS   ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane   20m   v1.27.0   192.7.203.9    <none>        Ubuntu 20.04.6 LTS   5.4.0-1106-gcp   containerd://1.6.6
node01         Ready    <none>          20m   v1.27.0   192.7.203.12   <none>        Ubuntu 20.04.5 LTS   5.4.0-1106-gcp   containerd://1.6.6

 

우리는 Controlplane 노드에서 Containerd를 컨테이너 런타임으로 사용합니다. 

$ ip link show cni0
3: cni0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether da:e2:9e:f9:fd:7d brd ff:ff:ff:ff:ff:ff

 

Containerd가 생성한 인터페이스/브리지는 무엇입니까?

$ ip link 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/ether 3e:8c:e3:af:92:1c brd ff:ff:ff:ff:ff:ff
3: cni0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether da:e2:9e:f9:fd:7d brd ff:ff:ff:ff:ff:ff
4: veth9fe430dd@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue master cni0 state UP mode DEFAULT group default 
    link/ether 52:1e:07:fb:58:f0 brd ff:ff:ff:ff:ff:ff link-netns cni-e5b3a4f2-e667-6720-b1a3-25f8b4d6456c
5: veth15ba263b@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue master cni0 state UP mode DEFAULT group default 
    link/ether 2a:a0:cb:e1:7f:78 brd ff:ff:ff:ff:ff:ff link-netns cni-abe72dc1-57c1-97c4-da40-e8ab5e616241
599: eth0@if600: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:c0:07:cb:09 brd ff:ff:ff:ff:ff:ff link-netnsid 0

 

ㅇ cni0 인터페이스의 상태는 무엇입니까? :  state UP mode

$ ip link show cni0
3: cni0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether da:e2:9e:f9:fd:7d brd ff:ff:ff:ff:ff:ff

 

ㅇ 제어 영역 노드에서 Google에 ping을 실행하려면 어떤 경로가 필요합니까?
ㅇ 기본 게이트웨이의 IP 주소는 무엇입니까?

$  nslookup google.com
Server:         172.25.0.1
Address:        172.25.0.1#53

Non-authoritative answer:
Name:   google.com
Address: 108.177.112.100
Name:   google.com
Address: 108.177.112.102
Name:   google.com
Address: 108.177.112.101
Name:   google.com
Address: 108.177.112.139
Name:   google.com
Address: 108.177.112.113
Name:   google.com
Address: 108.177.112.138
Name:   google.com
Address: 2607:f8b0:4001:c00::8b
Name:   google.com
Address: 2607:f8b0:4001:c00::71
Name:   google.com
Address: 2607:f8b0:4001:c00::64
Name:   google.com
Address: 2607:f8b0:4001:c00::66


$ ip route show default
default via 172.25.0.1 dev eth1

 

ㅁ CNI

  ㄴ [kubernetes network] CNI란?에서 정리한 내용이다.

  ㄴ CNI(Container Network Interface)는 컨테이너 간의 네트워킹을 제어할 수 있는 기술적인 표준이다.
  ㄴ 컨테이너의 네트워크 연결과 컨테이너가 삭제될 때 할당된 리소스를 제거하는 데에 집중한다.

 

 

ㅇ kubelet 서비스를 검사하고 Kubernetes에 설정된 컨테이너 런타임 엔드포인트 값을 식별합니다.

# 컨트롤노드의 process를 확인. container-runtime-endpoint!
$ ps -aux | grep kubelet | grep --color container-runtime-endpoint
root        4666  0.0  0.0 3554052 101104 ?      Ssl  00:55   0:10 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml 
--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock --pod-infra-container-image=registry.k8s.io/pause:3.9

 

ㅇ 아래 플러그인 중 이 호스트에서 사용 가능한 CNI 플러그인 목록에서 사용할 수 없는 플러그인을 확인하세요.

# cni 목록 확인
$  ls /opt/cni/bin/
bandwidth  bridge  dhcp  dummy  firewall  flannel  host-device  host-local  ipvlan  loopback  macvlan  portmap  ptp  sbr  static  tuning  vlan  vrf

 

ㅇ kubernetes 클러스터에서 사용되도록 구성된 CNI 플러그인은 무엇입니까?

$ ls /etc/cni/net.d/
10-flannel.conflist

 

ㅇ 컨테이너 및 관련 네임스페이스가 생성된 후 kubelet에서 실행되는 바이너리 실행 파일은 무엇입니까?

$ cat /etc/cni/net.d/10-flannel.conflist
{
  "name": "cbr0",
  "cniVersion": "0.3.1",
  "plugins": [
    {
      "type": "flannel", <======
      "delegate": {
        "hairpinMode": true,
        "isDefaultGateway": true
      }
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      }
    }
  ]
}

 

 

ㅁ Deploy Network Solution

# pod 상태 확인
 Warning  FailedCreatePodSandBox  12s   kubelet            
 Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "3f1868719c55abec256cf03bc90389c1f0d8db86aabd240a5f7598977ef9612c": plugin type="weave-net" name="weave" failed (add): unable to allocate IP address: Post "http://127.0.0.1:6784/ip/3f1868719c55abec256cf03bc90389c1f0d8db86aabd240a5f7598977ef9612c": 
 dial tcp 127.0.0.1:6784: connect: connection refused

 

클러스터에 weave-net 네트워킹 솔루션을 배포합니다. /root/weave 참조

$  cd /root/weave/

$ k apply -f weave-daemonset-k8s.yaml 
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.apps/weave-net created

$ k get po
NAME   READY   STATUS    RESTARTS   AGE
app    1/1     Running   0          70s

$ k get daemonsets.apps -A
NAMESPACE     NAME         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   kube-proxy   1         1         1       1            1           kubernetes.io/os=linux   33m
kube-system   weave-net    1         1         1       1            1           <none>                   47s

 

ㅁ Networking Weave

 ㄴ Weave은 도커 호스트 간에 오버레이 네트워크를 제공한다. 여기서 오버레이란 “덮어 씌우다”라는 뜻이다.

 ㄴ 즉, 오버레이 네트워크의 기본 개념은 실제로 복잡할 수 있는 엔드포인트 간의 네트워크 구조를 추상화하여 네트워크 통신 경로를 단순화 하는 것이다.

$ cd /etc/cni/net.d/
$ ls
10-weave.conflist

 

이 클러스터에는 몇 개의 Weave 에이전트/피어가 배포되어 있습니까?

$ k get po -A | grep weave
kube-system   weave-net-jz9zf                        2/2     Running   1 (42m ago)   42m
kube-system   weave-net-vw8k9                        2/2     Running   0             42m

 

ㅇ 각 노드에서 weave로 생성된 브리지 네트워크/인터페이스의 이름을 식별합니다.

$ ip link show 
datapath         eth0             group            up               vethwe-datapath  vethwepl751c4ae  weave            
dev              eth1             lo               vethwe-bridge    vethwepl5cce11b  vxlan-6784

$ ip link show weave 
4: weave: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue 
state UP <===========
mode DEFAULT group default qlen 1000
    link/ether 02:f0:ef:c4:24:8b brd ff:ff:ff:ff:ff:ff

 

IP 대역확인

$ ifconfig weave
weave: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1376
        inet 10.244.0.1  netmask 255.255.0.0  broadcast 10.244.255.255
        ether 02:f0:ef:c4:24:8b  txqueuelen 1000  (Ethernet)
        RX packets 7244  bytes 581971 (581.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7249  bytes 702761 (702.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

ㅇ node01에 예약된 POD에 구성된 기본 게이트웨이는 무엇입니까? node01에서 포드를 예약하고 IP 경로 출력을 확인하세요.

$ ssh node01
$ ls /etc/cni/net.d/
10-weave.conflist

# ip 대역을 확인
$ ifconfig weave

 

ㅁ Service Networking

클러스터 부분의 노드는 어떤 네트워크 범위에 속합니까?

$ ip a | grep eth0
1274: eth0@if1275: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default 
    inet 192.9.53.11/24 brd 192.9.53.255 scope global eth0

$ ipcalc -b 192.9.53.11
Address:   192.9.53.11          
Netmask:   255.255.255.0 = 24   
Wildcard:  0.0.0.255            
=>
Network:   192.9.53.0/24        
HostMin:   192.9.53.1           
HostMax:   192.9.53.254         
Broadcast: 192.9.53.255         
Hosts/Net: 254                   Class C

 

이 클러스터의 POD에 대해 구성된 IP 주소 범위는 무엇입니까?

$ k -n kube-system logs weave-net-dphnt 
......................
INFO: 2024/01/27 06:10:48.496788 adding entry 10.244.0.0/17 to weaver-no-masq-local of 0
INFO: 2024/01/27 06:10:48.496809 added entry 10.244.0.0/17 to weaver-no-masq-local of 0
INFO: 2024/01/27 06:10:48.497558 adding entry 10.244.128.0/18 to weaver-no-masq-local of 0
......................

 

클러스터 내의 서비스에 대해 구성된 IP 범위는 무엇입니까?

$ cat /etc/kubernetes/manifests/kube-apiserver.yaml | grep service-cluster-ip-range
    - --service-cluster-ip-range=10.96.0.0/12

 

kube-proxy는 어떤 유형의 프록시를 사용하도록 구성되어 있나요?

$ k -n kube-system logs kube-proxy-7xzwg
..............................
I0127 06:10:25.033493       1 server_others.go:110] "Detected node IP" address="192.9.53.11"
I0127 06:10:25.033519       1 server_others.go:551] "Using iptables proxy"
I0127 06:10:25.055726       1 server_others.go:190] "Using iptables Proxier"
..............................

 

ㅇ 이 Kubernetes 클러스터는 kube-proxy Pod가 클러스터의 모든 노드에서 실행되도록 어떻게 보장하나요? kube-proxy 포드를 검사하고 배포 방법을 식별해 보세요.

$  kubectl get ds -n kube-system
NAME         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-proxy   2         2         2       2            2           kubernetes.io/os=linux   96m
weave-net    2         2         2       2            2           <none>                   96m

 

ㅁ CoreDNS in Kubernetes

이 클러스터에 구현된 DNS 솔루션을 식별합니다.

$ k get po -n kube-system 
NAME                                   READY   STATUS    RESTARTS   AGE
coredns-5d78c9869d-6wvgc               1/1     Running   0          6m54s
coredns-5d78c9869d-b649g               1/1     Running   0          6m54s

 

ㅇ 서비스를 해결하기 위해 POD에 구성해야 하는 CoreDNS 서버의 IP는 무엇입니까?

$ k get svc -n kube-system 
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   11m

 

ㅇ coreDNS config file?

$ kubectl -n kube-system describe deployments.apps coredns | grep -A2 Args | grep Corefile
      /etc/coredns/Corefile
      
$ ps -ef | grep core
root        6552    6427  0 03:00 ?        00:00:01 /coredns -conf /etc/coredns/Corefile
root        6937    6809  0 03:00 ?        00:00:01 /coredns -conf /etc/coredns/Corefile

 

ㅇ Corefile은 CoreDNS POD에 어떻게 전달되나요?

$  kubectl -n kube-system get  deployments.apps coredns -o json | jq
..................
"volumes": [
          {
            "configMap": {
              "defaultMode": 420,
              "items": [
                {
                  "key": "Corefile",
                  "path": "Corefile"
                }
              ],
              "name": "coredns"
            },
            "name": "config-volume"
          }
        ]
..................

 

ㅇ Corefile용으로 생성된 ConfigMap 객체의 이름은 무엇입니까?

ㅇ  kubernetes 클러스터에 대해 구성된 루트 도메인/영역은 무엇입니까?

$ k get cm -n kube-system coredns -o yaml
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
           lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :9153
        forward . /etc/resolv.conf {
           max_concurrent 1000
        }
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  creationTimestamp: "2024-01-27T07:59:49Z"
  name: coredns
  namespace: kube-system
  resourceVersion: "265"
  uid: f5dfda30-e71b-44a9-a411-4e28c3e5c536

 

ㅇ 테스트 애플리케이션에서  웹 서버에 액세스하는 데 어떤 이름을 사용할 수 있습니까?
테스트 팟(Pod)에서 curl 명령을 실행하여 테스트할 수 있습니다. 또는 테스트 애플리케이션에도 UI가 있습니다. test-app이라는 터미널 상단의 탭을 사용하여 액세스하세요.

$ k -n payroll describe svc web-service 
Name:              web-service
Namespace:         payroll
Labels:            <none>
Annotations:       <none>
Selector:          name=web
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.100.123.33
IPs:               10.100.123.33
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.244.0.4:80
Session Affinity:  None
Events:            <none> 

{Name}.{Namespace} = web-service.payroll

 

ㅇ 아래 중 테스트 애플리케이션에서 payroll 서비스에 액세스하는 데 사용할 수 없는 이름은 무엇입니까?

$  k exec -it test -- /bin/sh
$ curl  web-service.payroll
 This is the PayRoll server!
$ curl  web-service
 This is the HR server!
$ curl  web-service.payroll.svc.cluster.local
 This is the PayRoll server!
$ curl  web-service.payroll.svc
 This is the PayRoll server!
$ curl  web-service.payroll.svc.cluster
curl: (6) Could not resolve host: web-service.payroll.svc.cluster

 

ㅇ 방금 mysql 데이터베이스에 액세스하는 웹 서버(webapp)를 배포했습니다. 그러나 웹 서버가 데이터베이스 서버에 연결하지 못했습니다. 문제를 해결하고 수정하세요.

 

  서로 다른 네임스페이스에 있을 수 있습니다. 먼저 응용프로그램을 찾으세요. 웹 서버 인터페이스는 터미널 상단의 웹 서버 탭을 클릭하면 볼 수 있습니다.

$ k edit deploy webapp
........................
 containers:
      - env:
        - name: DB_Host
          value: mysql.payroll <========
        - name: DB_User
          value: root
        - name: DB_Password
          value: paswrd
        image: mmumshad/simple-webapp-mysql
........................

 

nslookup 확인

kubectl exec -it hr -- nslookup mysql.payroll > /root/CKA/nslookup.out

 

ㅁ Ingress Networking – 1

ㅇ Ingress 컨트롤러는 어떤 네임스페이스에 배포되나요?

$ k get all -n ingress-nginx 
NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-l7kmp        0/1     Completed   0          12m
pod/ingress-nginx-admission-patch-v4prg         0/1     Completed   0          12m
pod/ingress-nginx-controller-5d48d5445f-sv499   1/1     Running     0          12m

NAME                                         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             NodePort    10.98.39.177   <none>        80:30080/TCP,443:32103/TCP   12m
service/ingress-nginx-controller-admission   ClusterIP   10.99.54.181   <none>        443/TCP                      12m

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           12m

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-5d48d5445f   1         1         1       12m

NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           11s        12m
job.batch/ingress-nginx-admission-patch    1/1           11s        12m

 

ㅇ which namespce is ingress resources in there?

 Ingress 리소스의 이름은 무엇입니까?

$  k get ingress -A 
NAMESPACE   NAME                 CLASS    HOSTS   ADDRESS        PORTS   AGE
app-space   ingress-wear-watch   <none>   *       10.98.39.177   80      18m

 

ㅇ Ingress 리소스에 구성된 호스트는 무엇입니까? 
호스트 항목은 사용자가 http://www.google.com과 같은 애플리케이션에 접근하는 데 사용하는 도메인 이름을 정의합니다.

ㅇ video-service와 연결되는 path? =>  /watch

$ k -n app-space describe ingress ingress-wear-watch 
Name:             ingress-wear-watch
Labels:           <none>
Namespace:        app-space
Address:          10.98.39.177
Ingress Class:    <none>
Default backend:  <default>
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /wear    wear-service:8080 (10.244.0.4:8080)
              /watch   video-service:8080 (10.244.0.5:8080)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /
              nginx.ingress.kubernetes.io/ssl-redirect: false
Events:
  Type    Reason  Age                From                      Message
  ----    ------  ----               ----                      -------
  Normal  Sync    28m (x2 over 28m)  nginx-ingress-controller  Scheduled for sync
  
  
==>  All Host (*)

 

 

ㅇ video-service 의 URL 변경작업

$ k edit -n app-space ingress ingress-wear-watch
.......
      - backend:
          service:
            name: video-service
            port:
              number: 8080
        path: /stream <=== 변경
        pathType: Prefix
.......

 

ㅇ food-service 추가

$ k -n app-space edit ingress ingress-wear-watch
.......
spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: wear-service
            port:
              number: 8080
        path: /wear
        pathType: Prefix
      - backend:
          service:
            name: video-service
            port:
              number: 8080
        path: /stream
        pathType: Prefix
# 추가        
      - backend:
          service:
            name: food-service
            port:
              number: 8080
        path: /eat
        pathType: Prefix
.......

 

 

ㅇ pay-service 신규 ingress 생성

# 신규 ingress 생성
$ vi pay-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  name: pay-ingress
  namespace: critical-space
spec:
  rules:
  - http:
      paths:
      - backend:
          service:
            name: pay-service
            port:
              number: 8282
        path: /pay
        pathType: Prefix

 

 

반응형
Comments