Kubernetes_6

최시열·2023년 2월 1일
0

2023.02.01


7장 서비스

Service

ClusterIP

cat > nginx-deployment.yaml

>>>>

apiVersion: apps/v1
kind: Deployment
metadata:
  name: rs-nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      name: nginx-pod
      labels:
        app: webui
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.14
cat > nginx-clusterip.yaml

>>>>

apiVersion: v1
kind: Service
metadata:
  name: clusterip-service
spec:
  type: ClusterIP
  clusterIP: 10.100.100.100
  selector:
    app: webui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

kubectl apply -f nginx-deployment.yaml
kubectl apply -f nginx-clusterip.yaml

kubectl describe service clusterip-service 를 통해 ip 확인

---또는---

cat > nginx-service.yaml

>>>>

apiVersion: v1
kind: Service
metadata:
  name: webui-svc
spec:
  selector:
    app: webui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

이와같이 서비스를 지정하면 ClusterIP가 자동으로 생성된다.

curl 10.100.132.69(생성된 IP)로 접속하면 nginx가 보인다.

NodePort

!! deployment를 먼저 배포하기

cat > nginx-nodeport.yaml

>>>>

apiVersion: v1
kind: Service
metadata:
  name: nodeport-service
spec:
  type: NodePort
  clusterIP: 10.100.100.200
  selector:
    app: webui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30200

kubectl apply -f nginx-nodeport.yaml

nodePort는 따로 정해주지 않으면 알아서 정한다..!

Headless

cat > nginx-headless.yaml

>>>>

apiVersion: v1
kind: Service
metadata:
  name: headless-service
spec:
  type: ClusterIP
  clusterIP: None
  selector:
    app: webui
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

kube-proxy

profile
최시열

0개의 댓글