본문 바로가기

⭐ Kubernetes & EKS/네트워크 (Network)

# 쿠버네티스 네트워크 - CoreDNS 서비스 및 서비스 DNS 연습문제

# CoreDNS 서비스

- 쿠버네티스에서는 서비스 이름이 도메인 이름이 된다.

# 서비스 DNS 연습문제

# blue라는 네임스페이스 생성

kubectl create ns blue --dry-run=client -o yaml

kubectl create ns blue --dry-run=client -o yaml > blue-jenkins-svc-deploy.yaml

kubectl create ns blue

# 디플로이먼트 생성하기

kubectl create deploy pod-jenkins --image=jenkins --port=8080 --dry-run=client -o yaml -n blue >> blue-jenkins-svc-deploy.yaml

# 서비스 생성하기

kubectl expose deploy pod-jenkins --name srv-jenkins --dry-run=client -o yaml -n blue >> blue-jenkins-svc-deploy.yaml

- Error from server (NotFound): namespaces "blue" not found 가 발생하는 경우

- 위의 캡쳐 화면처럼 deployment 쪽에 namespace를 지정해 주면 된다.

vim blue-jenkins-svc-deploy.yaml

kubectl create -f blue-jenkins-svc-deploy.yaml

# 서비스 다시 생성하기

kubectl expose deploy pod-jenkins --name srv-jenkins --dry-run=client -o yaml -n blue >> blue-jenkins-svc-deploy.yaml

# 확인하기

vim blue-jenkins-svc-deploy.yaml

apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: null
  name: blue
spec: {}
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: pod-jenkins
  name: pod-jenkins
  namespace: blue
spec:
  replicas: 1
  selector:
    matchLabels:
      run: pod-jenkins
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: pod-jenkins
    spec:
      containers:
      - image: jenkins
        name: pod-jenkins
        ports:
        - containerPort: 8080
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: pod-jenkins
  name: srv-jenkins
  namespace: blue
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    run: pod-jenkins
status:
  loadBalancer: {}

- 내용을 확인하자 namespace가 잘 부여가 되었는지, 그리고 포트 및 labels등이 정상적으로 부여되어 있는지 확인

# 최종 실행하기

kubectl create -f blue-jenkins-svc-deploy.yaml

# 이미지를 생성하기

kubectl run http-go --image=gasbugs/http-go

kubectl get pod

# 서비스 실행하기

kubectl exec http-go -- curl srv-jenkins.blue:8080