Service를 활용한 애플리케이션 노출
애플리케이션에 접근할 수 있도록 ClusterIP, NodePort, LoadBalancer 등 다양한 Kubernetes Service 유형을 알아봅니다.
Service를 활용한 애플리케이션 노출은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
What are K8s Services?
When you deploy applications in Kubernetes, your Pods can come and go. They get new IPs, they scale up or down, and they might even crash and restart.
This creates a challenge: how do other parts of your application, or external users, consistently find and communicate with these ever-changing Pods?
Services: Stable Access Point
Kubernetes Services solve this problem by providing a stable network abstraction over a set of Pods. Think of a Service as a single, unchanging IP address and DNS name for your application.
- Services act as load balancers, distributing traffic to healthy Pods.
- They ensure your application remains reachable even if individual Pods change or fail.
How Services Find Pods
Services don't directly manage Pods. Instead, they use labels and selectors to find the Pods they should route traffic to. When a Pod matches a Service's selector, it becomes an endpoint for that Service.
- Labels: Key-value pairs attached to objects (like Pods) for identification.
- Selectors: Rules defined in a Service to match Pod labels.
ClusterIP: Internal Only
The ClusterIP Service type is the default. It exposes the Service on an internal IP address within the cluster. This means the Service is only reachable from inside the cluster.
It's perfect for internal communication between different services in your application, like a frontend talking to a backend database.
ClusterIP Service Example
Here's a YAML definition for a ClusterIP Service. It targets Pods with the label app: my-app and exposes port 80, routing traffic to container port 8080.
Apply it with kubectl apply -f service.yaml.
apiVersion: v1
kind: Service
metadata:
name: my-app-clusterip
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIPNodePort: External via Node IP
A NodePort Service opens a specific port on all worker nodes in your cluster. External traffic can reach your Service by contacting any node's IP address on that specific port (e.g., NodeIP:NodePort).
This is useful for exposing services to the outside world, especially in small setups or for development, without needing a cloud load balancer.
NodePort Service Example
This NodePort Service will expose port 80 of your application on a high port (typically 30000-32767) on every node. You can specify a nodePort or let Kubernetes assign one.
After applying, find the assigned port with kubectl get svc.
apiVersion: v1
kind: Service
metadata:
name: my-app-nodeport
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 30007 # Optional: K8s assigns if omitted
type: NodePortLoadBalancer: Cloud Integration
A LoadBalancer Service is primarily used when running Kubernetes on a cloud provider (like AWS, GCP, Azure). It automatically provisions an external cloud load balancer.
This provides a dedicated, stable external IP address and often integrates with cloud-specific features like SSL termination and advanced routing.
LoadBalancer Service Example
When deployed on a cloud provider, this Service will automatically create and configure an external load balancer, assigning it an external IP address.
The external IP will be visible via kubectl get svc once provisioned.
apiVersion: v1
kind: Service
metadata:
name: my-app-loadbalancer
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancerService Type Overview
Let's quickly compare the primary Service types:
- ClusterIP: Internal access only, within the cluster.
- NodePort: External access via a specific port on each node.
- LoadBalancer: External access via a cloud provider's load balancer, stable external IP.
Choosing the right type depends on whether your application needs to be accessible internally or externally, and your deployment environment.
Service Type Quiz
Which Kubernetes Service types provide a direct mechanism for external traffic to reach applications running inside the cluster?
Recap: Exposing Apps
Great job! You've learned how Kubernetes Services abstract network access to your Pods and make your applications reachable. We explored three main types:
- ClusterIP: For internal-only communication within the cluster.
- NodePort: Exposes services on a static port across all nodes for external access.
- LoadBalancer: Integrates with cloud providers to provision an external load balancer, providing a stable external IP.
Understanding these Service types is fundamental for designing accessible and robust applications in Kubernetes.
자주 묻는 질문
“Service를 활용한 애플리케이션 노출” 강의는 무료인가요?
네 — “Service를 활용한 애플리케이션 노출” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
“Service를 활용한 애플리케이션 노출”에서 뭘 배우나요?
애플리케이션에 접근할 수 있도록 ClusterIP, NodePort, LoadBalancer 등 다양한 Kubernetes Service 유형을 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“Service를 활용한 애플리케이션 노출” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Kubernetes Deployment 이해
- Service를 활용한 애플리케이션 노출
- 애플리케이션 확장 및 자동 복구
- 롤링 업데이트 및 롤백