apiVersion: apps/v1 kind: Deployment # Deployment 기본 정보 metadata: name: nginx-deployment # Deployment 이름 # Deployment 세부 정보 spec: replicas: 3 selector: matchLabels: app: nginx # 아래에서 정의한 Pod 중 'app: nginx'이라는 값을 가진 파드를 선택 # 배포할 Pod 정의 template: metadata: labels: # 레이블 (= 카테고리) app: nginx spec: containers: - name: nginx-container # 컨테이너 이름 image: nginx # 컨테이너를 생성할 때 사용할 이미지 ports: - containerPort: 80 # 컨테이너에서 사용하는 포트를 명시적으로 표현
apiVersion: v1 kind: Service # Service 기본 정보 metadata: name: nginx-service # Service 이름 # Service 세부 정보 spec: type: NodePort # Service의 종류 selector: app: nginx # 실행되고 있는 파드 중 'app: nginx'이라는 값을 가진 파드와 서비스를 연결 ports: - protocol: TCP # 서비스에 접속하기 위한 프로토콜 port: 80 # 쿠버네티스 내부에서 Service에 접속하기 위한 포트 번호 targetPort: 80 # 매핑하기 위한 파드의 포트 번호 nodePort: 30000 # 외부에서 사용자들이 접근하게 될 포트 번호
$ kubectl apply -f deployment.yaml $ kubectl apply -f service.yaml
$ kubectl get pods $ kubectl get deployment $ kubectl get service

$ kubectl delete all --all