이세개발
article thumbnail

Kuernetes 내부 서비스


쿠버네티스에서 내부 서비스를 사용하면, 클러스터 내의 다른 파드들이 서비스를 찾고 통신할 수 있습니다. 이는 서비스 디스커버리를 가능하게 하며, 파드가 동적으로 생성되고 사라지는 환경에서 중요한 역할을 합니다.

다음은 내부 서비스를 테스트하기 위한 명령어들입니다:

kubectl run nettool -it --image ghcr.io/c1t1d0s7/network-multitool --rm
> host myapp-svc.default.svc.cluster.local
> curl http://myapp-svc.default.svc.cluster.local
> curl http://myapp-svc

kubectl run 명령어는 ghcr.io/c1t1d0s7/network-multitool 이미지를 사용하여 nettool이라는 이름의 파드를 실행합니다. 이 파드는 네트워크 문제를 진단하는 데 사용되는 도구들을 포함하고 있습니다.

host 명령어는 myapp-svc.default.svc.cluster.local라는 이름의 서비스에 대한 DNS 조회를 수행합니다. 이는 서비스가 올바르게 구성되었는지, 그리고 다른 파드들이 이 서비스를 찾을 수 있는지 확인하는 데 사용됩니다.

curl 명령어는 myapp-svc.default.svc.cluster.localmyapp-svc라는 이름의 서비스에 HTTP 요청을 보냅니다. 이는 서비스가 올바르게 작동하는지 확인하는 데 사용됩니다.

각 실습용 YAML 파일에 대한 설명입니다.


myapp-rs.yaml

이 YAML 파일은 쿠버네티스의 ReplicaSet을 정의합니다. ReplicaSet은 동일한 파드의 복사본을 여러 개 유지하도록 보장합니다.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-rs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp-rs
  template:
    metadata:
      labels:
        app: myapp-rs
    spec:
      containers:
      - name: myapp
        image: ghcr.io/c1t1d0s7/go-myweb:alpine
        ports:
        - containerPort: 8080

myapp-rs-named-port.yaml

이 YAML 파일은 명명된 포트를 사용하는 ReplicaSet을 정의합니다. 명명된 포트는 파드 내에서 특정 서비스를 참조하는 데 사용될 수 있습니다.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-rs-namedport
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp-rs-namedport
  template:
    metadata:
      labels:
        app: myapp-rs-namedport
    spec:
      containers:
      - name: myapp
        image: ghcr.io/c1t1d0s7/go-myweb:alpine
        ports:
        - name: myapp-http
          containerPort: 8080

myapp-svc.yaml

이 YAML 파일은 쿠버네티스의 서비스를 정의합니다. 서비스는 네트워크 트래픽을 파드로 라우팅하는 역할을 합니다.

apiVersion: v1
kind: Service
metadata:
  name: myapp-svc
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: myapp-rs

myapp-svc-ses-aff.yaml

이 YAML 파일은 세션 친화성을 가진 서비스를 정의합니다. 세션 친화성은 동일한 클라이언트의 모든 요청이 동일한 파드로 라우팅되도록 보장합니다.

apiVersion: v1
kind: Service
metadata:
  name: myapp-svc-ses-aff
spec:
  sessionAffinity: ClientIP
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: myapp-rs

myapp-svc-named-port.yaml

이 YAML 파일은 명명된 포트를 사용하는 서비스를 정의합니다.

apiVersion: v1
kind: Service
metadata:
  name: myapp-svc-namedport
spec:
  ports:
  - name: myapp-http
    port: 80
    targetPort: myapp-http
  selector:
    app: myapp-rs-namedport

myapp-svc-multiport.yaml

이 YAML 파일은 여러 포트를 가진 서비스를 정의합니다.

apiVersion: v1
kind: Service
metadata:
  name: myapp-svc-multiport
spec:
  ports:
  - name: myapp-http
    port: 80
    targetPort: 8080
  - name: myapp-https
    port: 443
    targetPort: 8443
  selector:
    app: myapp-rs

이러한 YAML 파일들은 쿠버네티스 클러스터 내에서 서비스를 생성하고 관리하는 데 사용됩니다. 이들 각각은 특정 목적을 가지고 있으며, 그 목적은 파드의 배포, 서비스의 라우팅, 세션 친화성의 설정 등 다양합니다. 이러한 설정들은 애플리케이션의 가용성과 확장성을 높이는 데 도움이 됩니다.

profile

이세개발

@print(name)

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!