본문 바로가기
IT 기술/k8s

[cka] Services

by Geunny 2024. 6. 1.
반응형

 

1. How many Services exist on the system? In the current(default) namespace

 

$ controlplane ~ ✖ k get service
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.43.0.1    <none>        443/TCP   14m

 

answer: 1

 

2. 추가 서비스가 기동됨.

 

3. What is the type of the default kubernetes service?

 

$ controlplane ~ ➜  k describe svc kubernetes
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
                   provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.43.0.1
IPs:               10.43.0.1
Port:              https  443/TCP
TargetPort:        6443/TCP
Endpoints:         192.16.27.6:6443
Session Affinity:  None
Events:            <none>

 

answer : ClusterIP

 

 

https://kubernetes.io/docs/concepts/services-networking/cluster-ip-allocation/

 

Service ClusterIP allocation

In Kubernetes, Services are an abstract way to expose an application running on a set of Pods. Services can have a cluster-scoped virtual IP address (using a Service of type: ClusterIP). Clients can connect using that virtual IP address, and Kubernetes the

kubernetes.io

 

4. What is the targetPort configured on the kubernetes service?

 

3. 번 describe 내용 참조.

answer : 6443/TCP

 

 

5. How many labels are configured on the kubernetes service?

 

3. 번 describe 내용 참조.

answer : 2 개 ( component=apiserver, provider=kubernetes)

 

6. How many Endpoints are attached on the kubernetes service?

 

3. 번 describe 내용 참조.

answer : 1 개 (192.16.27.6:6443)

 

 

7. How many Deployments exist on the system now?  In the current(default) namespace

 

$ controlplane ~ ➜  k get deployments.apps 
NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
simple-webapp-deployment   4/4     4            4           20s

 

answer : 1개

 

8.  What is the image used to create the pods in the deployment?

 

$ controlplane ~ ➜  k describe deployments.apps simple-webapp-deployment 
Name:                   simple-webapp-deployment
Namespace:              default
...

Pod Template:
  Labels:  name=simple-webapp
  Containers:
   simple-webapp:
    Image:        kodekloud/simple-webapp:red
    Port:         8080/TCP
    Host Port:    0/TCP

 

answer : kodekloud/simple-webapp:red

 

 

9. Are you able to accesss the Web App UI?

Try to access the Web Application UI using the tab simple-webapp-ui above the terminal.

 

answer : NO

- 이유 : 해당 파드의 port 를 포트포워딩 해줄 서비스가 존재하지 않기 때문이다.

name=simple-webapp 에 대한 서비스 리스트는 없음.

포트 포워딩을 하려면 NodePort 타입의 서비스가 존재해야 한다.

 

10. Create a new service to access the web application using the service-definition-1.yaml file.

 

https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport

 

Service

Expose an application running in your cluster behind a single outward-facing endpoint, even when the workload is split across multiple backends.

kubernetes.io

 

 

--- 생성조건

Name: webapp-service
Type: NodePort
targetPort: 8080
port: 8080
nodePort: 30080
selector:
  name: simple-webapp
  
----

--- yaml 파일

apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  type: NodePort
  selector:
    name: simple-webapp
  ports:
    - port: 8080
      # By default and for convenience, the `targetPort` is set to
      # the same value as the `port` field.
      targetPort: 8080
      # Optional field
      # By default and for convenience, the Kubernetes control plane
      # will allocate a port from a range (default: 30000-32767)
      nodePort: 30080

 

11.  웹에 다시 접근

 

노드포트 서비스가 동작중이므로 클러스터가 존재하는 IP의 30080 포트로 외부에서 접근하게 되면 파드의 8080 포트로 포워딩 해줄수 있다.

'IT 기술 > k8s' 카테고리의 다른 글

[cka] Manual Scheduling  (0) 2024.06.08
[cka] Imperative Command  (1) 2024.06.01
[cka] namespace  (1) 2024.05.28
[cka] Deployments  (0) 2024.05.28
[cka] ReplicaSets  (0) 2024.05.27

댓글