1) NodePort 문제
문제
Create and configure the service front-end-service so it's accessible through NodePort and routes to the existing pod named front-end.
풀이
- 먼저 front-end이름의 Pod를 만들어야 한다.
- 아래 처럼 명령어로 빠르게 만들 수 있고 공식 문서를 찾아 만들 수도 있다.
- https://kubernetes.io/docs/concepts/workloads/pods/#using-pods
# pod
apiVersion: v1
kind: Pod
metadata:
name: front-end
labels:
name: front-end
spec:
containers:
- image: nginx
name: front-end
# service
apiVersion: v1
kind: Service
metadata:
name: front-end-service
spec:
type: NodePort
selector:
name: front-end
ports:
- port: 80
# By default and for convenience, the `targetPort` is set to
# the same value as the `port` field.
targetPort: 80
# Optional field
# By default and for convenience, the Kubernetes control plane
# will allocate a port from a range (default: 30000-32767)
nodePort: 30007
호출
kubectl get node -o wide로 node ip 를 알아낸 후
curl {node-ip}:nodePort
2) deployment & service expose 문제
문제
Reconfigure the existing deployment front-end and add a port specification named http exposing port 80/tcp of the existing container nginx.
- Create a new service named front-end-svc exposing the container port http.
- Configure the new service to also expose the individual Pods via a NodePort on the nodes on which they are scheduled.
apiVersion: v1
kind: Service
metadata:
name: front-end-svc
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
name: http
protocol: TCP
targetPort: 80
3) network policy 생성 문제
문제
Create a new NetworkPolicy named allow-port-from-namespace in the existing namespace echo. Ensure that the new NetworkPolicy allows Pods in namespace my-app to connect to port 9000 of Pods in namespace echo.
Further ensure that the new NetworkPolicy:
- does not allow access to Pods, which don't listen on port 9000
- does not allow access from Pods, which are not in namespace my-app
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-port-from-namespace
namespace: echo # 정책이 적용될 네임스페이스
spec:
podSelector:
matchLabels: {} # 모든 Pod에 적용 (단, 포트 조건 적용)
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: my-app # my-app 네임스페이스에서 오는 트래픽만 허용
- podSelector:
matchLabels:
app: my-app
ports:
- protocol: TCP
port: 9000 # 포트 9000을 사용하는 Pod만 허용
4) Ingress 생성 문제
문제
Create a new nginx Ingress resource as follows:
- Name: ping
- Namespace: ing-internal
- Exposing service hi on path /hi using service port 5678
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ping
namespace: ing-internal
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /hi
pathType: Prefix
backend:
service:
name: hi
port:
number: 5678
5) ingress 생성 하고 curl로 테스트 문제
"ingress 생성하고 curl로 테스트" 관련 문제는 CKA 시험에서 자주 출제될 수 있는 문제 중 하나입니다. 이를 해결하기 위해서는 먼저 Ingress 리소스를 생성하고, 이를 테스트하기 위해 curl을 사용하여 해당 Ingress의 엔드포인트로 요청을 보내야 합니다.
아래는 이러한 문제를 해결하기 위한 답변입니다.
- Ingress 리소스 생성하기:
먼저, Ingress 리소스를 생성해야 합니다. 이를 위해서는 다음과 같이 Ingress 정의 파일을 작성해야 합니다.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: "example.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: my-service
port:
number: 80
'Kubernetes > cert' 카테고리의 다른 글
[CKA] PV 생성 (0) | 2025.02.11 |
---|---|
[CKA] Node 유형 (0) | 2025.02.10 |
[CKA] 스토리지 유형 (0) | 2025.02.10 |
[CKA] Pod 유형 (0) | 2025.02.07 |
[CKA] Apiserver Crash (0) | 2025.02.03 |