Table of Contents
외부 IP 주소로 애플리케이션에 접속하기
아래에 외부 아이피를 이용해 접속하는 방법과, 로드 밸런싱 기능을 포함하여 애플리케이션을 이중화 하는 방법을 설명합니다.
애플리케이션 적용
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: load-balancer-example
name: hello-world
spec:
replicas: 5
selector:
matchLabels:
app.kubernetes.io/name: load-balancer-example
template:
metadata:
labels:
app.kubernetes.io/name: load-balancer-example
spec:
containers:
- image: gcr.io/google-samples/node-hello:1.0
name: hello-world
ports:
- containerPort: 8080
kubernetes 에서 제공하는 샘플 애플리케이션입니다.
wget https://k8s.io/examples/service/load-balancer-example.yaml
vi load-balancer-example.yaml
kubectl apply -f load-balancer-example.yaml
아래의 명령으로 배포상태를 확인할 수 있습니다.
kubectl get deployments hello-world
kubectl describe deployments hello-world
아래의 명령으로 복제셋의 상태를 확인할 수 있습니다.
kubectl get replicasets
kubectl describe replicasets
애플리케이션 노출
아래의 명령으로 위 애플리케이션이 외부에 노출되게 됩니다.
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
서비스의 상태를 확인할 수 있습니다.
kubectl get services my-service
kubectl describe services my-service
Name: my-service
Namespace: default
Labels: app.kubernetes.io/name=load-balancer-example
Annotations: <none>
Selector: app.kubernetes.io/name=load-balancer-example
Type: LoadBalancer
IP: 100.66.64.212
LoadBalancer Ingress: aa3e69fb02caa4d7f8f43c0e529d2e3d-1253346531.ap-northeast-2.elb.amazonaws.com
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 31649/TCP
Endpoints: 100.96.1.10:8080,100.96.1.11:8080,100.96.1.7:8080 + 2 more...
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 8m17s service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 8m15s service-controller Ensured load balancer
LoadBalancer Ingres
가 도메인이 되고, Port
가 접속 포트가 됩니다.
LoadBalancer Ingres
가 아마존 도메인인 경우, 5분정도의 DNS 반영시간이 지나야 접속이 가능합니다.
아래 명령으로 포드의 상태를 확인할 수 있습니다.
kubectl get pods --output=wide
확인하기
브라우저를 이용해 http://<external-ip>:<port>
에 접속하면 아래 문구가 표시되는 것을 확인할 수 있습니다.
Hello Kubernetes!
삭제하기
아래의 명령으로 서비스를 삭제합니다.
kubectl delete services my-service
아래 명령으로 배포를 삭제할 수 있습니다.
kubectl delete deployment hello-world