8 Şubat 2021 Pazartesi

Kubernetes ClusterIP Service - Servise Sadece Cluster İçindeki Pod/Servisler Erişebilir

Giriş
Diğer Servisler arasındaki fark şöyle. Yani NodePort ve LoadBalancer servisi cluster dışına açar, ancak ClusterIP açmaz.
ClusterIP: Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. This is the default ServiceType

NodePort: Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting <NodeIP>:<NodePort>.

LoadBalancer: Exposes the service externally using a cloud provider’s load balancer. NodePort and ClusterIP services, to which the external load balancer will route, are automatically created.
servisleri görmek için kubectl get services kullanılır. Sorgularsak çıktı olarak şuna benzer bir şey alırız
NAME                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes          ClusterIP   10.96.0.1        <none>        443/TCP          58d
mongodb             ClusterIP   10.105.147.168   <none>        27017/TCP        6s
springbootmongodb   NodePort    10.108.143.94    <none>        8080:31636/TCP   16m
kind : Service 
type: ClusterIP
şeklinde kullanılır. type: ClusterIP yazmak zorunlu değildir, çünkü varsayılan servis tipi budur

Örnek - ClusterIP
Şeklen şöyle

Deployment şöyle
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grpc-server
  labels:
    app: grpc-server
spec:
  replicas: 3
  selector:
    matchLabels:
      app: grpc-server
  template:
    metadata:
      labels:
        app: grpc-server
    spec:
      containers:
        - name: grpc-server
          image: techdozo/grpc-lb-server:1.0.0
Service şöyle
apiVersion: v1
kind: Service metadata: name: grpc-server-service spec: type: ClusterIP selector: app: grpc-server ports: - port: 80 targetPort: 8001
Bu servise erişmek isteyen bir başka kod şöyle yapar
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grpc-client
  labels:
    app: grpc-client
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grpc-client
  template:
    metadata:
      labels:
        app: grpc-client
    spec:
      containers:
        - name: grpc-client
          image: techdozo/grpc-lb-client:1.0.0
          env:
            - name: SERVER_HOST
              value: grpc-server-service:80
Açıklaması şöyle
The SERVER_HOST environment variable point to the DNS of the service grpc-server-service.

Örnek ClusterIP
Deployment için şöyle yaparız. Burada  webcenter/activemq isimli registry'den activemq eğer zaten indirilmemişse, indiriliyor.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: queue
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: queue
    spec:
      containers:
      - name: web
        image: webcenter/activemq:5.14.3
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 61616
        resources:
          limits:
            memory: 512Mi
Önüne bir servis için şöyle yaparız
apiVersion: v1
kind: Service
metadata:
  name: queue
spec:
  ports:
  - port: 61616 
    targetPort: 61616
  selector:
    app: queue
Açıklaması şöyle
- you created a load balancer that exposes port 61616
- the incoming traffic is distributed to all Pods (see deployment above) that has a label of type app: queue
- the targetPort is the port exposed by the Pods

Hiç yorum yok:

Yorum Gönder