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/v1kind: Deploymentmetadata:name: grpc-serverlabels:app: grpc-serverspec:replicas: 3selector:matchLabels:app: grpc-servertemplate:metadata:labels:app: grpc-serverspec:containers:- name: grpc-serverimage: techdozo/grpc-lb-server:1.0.0
Service şöyle
apiVersion: v1kind: 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/v1kind: Deploymentmetadata:name: grpc-clientlabels:app: grpc-clientspec:replicas: 1selector:matchLabels:app: grpc-clienttemplate:metadata:labels:app: grpc-clientspec:containers:- name: grpc-clientimage: techdozo/grpc-lb-client:1.0.0env:- name: SERVER_HOSTvalue: 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/v1beta1kind: Deploymentmetadata:name: queuespec:replicas: 1template:metadata:labels:app: queuespec:containers:- name: webimage: webcenter/activemq:5.14.3imagePullPolicy: IfNotPresentports:- containerPort: 61616resources:limits:memory: 512Mi
apiVersion: v1kind: Servicemetadata:name: queuespec:ports:- port: 61616targetPort: 61616selector: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