본문 바로가기
Compute/kubernetis

[따배씨] 18. Ingress 구성/ CKA 시험 문제 학습

by 조청유곽 2025. 2. 1.
반응형

이 포스팅은 아래의 유튜브 채널 "따배"를 따라서 학습한 내용입니다.  

 

 

 

[관련 이론]

 

 


 

 

[Precondition]

(1) 테스트 환경

(1.1) Rocky Linux Cluster 

: 직접 구성

[root@k8s-master ~]# k get nodes -o wide
NAME         STATUS   ROLES           AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                            KERNEL-VERSION                  CONTAINER-RUNTIME
k8s-master   Ready    control-plane   30d   v1.27.2   192.168.56.30   <none>        Rocky Linux 8.10 (Green Obsidian)   4.18.0-553.33.1.el8_10.x86_64   containerd://1.6.32
k8s-node1    Ready    <none>          30d   v1.27.2   192.168.56.31   <none>        Rocky Linux 8.8 (Green Obsidian)    4.18.0-477.10.1.el8_8.x86_64    containerd://1.6.21
k8s-node2    Ready    <none>          30d   v1.27.2   192.168.56.32   <none>        Rocky Linux 8.8 (Green Obsidian)    4.18.0-477.10.1.el8_8.x86_64    containerd://1.6.21
[root@k8s-master ~]#

 

(1.2) Ubuntu Cluster 

: kodekloud 테스트 환경 활용

controlplane ~ ➜  kubectl get nodes -o wide
NAME           STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane   9m6s    v1.31.0   192.6.94.6    <none>        Ubuntu 22.04.4 LTS   5.4.0-1106-gcp   containerd://1.6.26
node01         Ready    <none>          8m31s   v1.31.0   192.6.94.9    <none>        Ubuntu 22.04.4 LTS   5.4.0-1106-gcp   containerd://1.6.26

https://learn.kodekloud.com/user/courses/udemy-labs-certified-kubernetes-administrator-with-practice-tests

 

(2) 사전 필요 설정 

- 문제에 이미 존재하는 "ingress-nginx" namespace를 생성한다. 

- 문제에 이미 존재하는 "appjs" service를 생성한다. 

controlplane ~ ➜  k create namespace ingress-nginx
namespace/ingress-nginx created
controlplane ~ ✖ vi 18-service.yaml
controlplane ~ ➜  k apply -f 18-service.yaml 
service/appjs created
controlplane ~ ➜  
controlplane ~ ➜  cat 18-service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: appjs
  namespace: ingress-nginx
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      
controlplane ~ ➜

 

 

[Question]

1. Application Service 운영
ingress-nginx namespace에 nginx 이미지를 app=nginx 레이블을 가지고 실행하는 nginx Pod를 구성하세요.
앞서 생성한 nginx Pod 를 서비스 하는 nginx-service를 생성하시오.
현재 appjs Service는 이미 동작중입니다. 별도 구성이 필요 없습니다.

2. Ingress 구성
app-ingess.yaml 파일을 생성하여 다음 조건의 ingress 서비스를 구성하시오.
ingress name: app-ingress
NODE_PORT:30080/ 접속했을 때 nginx 서비스로 연결
NODE_PORT:30080/app 으로 접속했을 때 appjs 서비스로 연결
Ingress 구성에 다음의 annotations를 포함시키시오.
annotations:
kubernetes.io/ingress.class: nginx

 

 

[Solve]

(1) nginx pod 생성 

controlplane ~ ➜  k run nginx -n ingress-nginx -l app=nginx --image=nginx --dry-run=client -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
  namespace: ingress-nginx
spec:
  containers:
  - image: nginx
    name: nginx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

controlplane ~ ➜  k run nginx -n ingress-nginx -l app=nginx --image=nginx
pod/nginx created

 

 

(2) nginx service 생성 

controlplane ~ ➜  k expose -n ingress-nginx pod nginx --port=80 --dry-run=client -o yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
  namespace: ingress-nginx
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
status:
  loadBalancer: {}

controlplane ~ ➜  k expose -n ingress-nginx pod nginx --port=80 
service/nginx exposed

controlplane ~ ➜  k get pods -n ingress-nginx 
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          28s

controlplane ~ ➜  k get service -n ingress-nginx 
NAME    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
appjs   ClusterIP   172.20.33.225    <none>        80/TCP    3m3s
nginx   ClusterIP   172.20.166.237   <none>        80/TCP    22s

 

 

(3) ingress 생성 

controlplane ~ ➜  vi 18-ingress.yaml
controlplane ~ ➜  cat 18-ingress.yaml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: simple-fanout-example
  namespace: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80
      - path: /app
        pathType: Prefix
        backend:
          service:
            name: appjs
            port:
              number: 80

controlplane ~ ➜
controlplane ~ ➜  k apply -f 18-ingress.yaml 
Warning: annotation "kubernetes.io/ingress.class" is deprecated, please use 'spec.ingressClassName' instead
ingress.networking.k8s.io/simple-fanout-example created

 

 

 

 

반응형