Açıklaması şöyle. Böylece load-balancer'a uğramadan direkt DNS kaydı ile bir POD'a erişilebilir.
A headless service in Kubernetes can be a useful tool for creating distributed applications. It allows you to directly access the individual pods in a service.
Örnek
Şöyle yaparız
apiVersion: v1kind: Servicemetadata:name: my-servicespec:clusterIP: Noneselector:app: my-appports:- protocol: TCPport: 80targetPort: 9376
Açıklaması şöyle
To create a headless service in Kubernetes, we need to define a service with the clusterIP field set to "None".In this example, we’ve defined a headless service named “my-service”. We’ve set the clusterIP field to "None" to indicate that we want a headless service. We've also specified a selector to associate pods with the service. The ports field specifies the ports that the service will forward traffic to.Once you’ve created a headless service, you can access each pod associated with the service through DNS. The DNS record for each pod will be in the format <pod-name>.<headless-service-name>.<namespace>.svc.cluster.local.
Örnek - StatefulSet
Elimizde şöyle bir headless service olsun
apiVersion: v1 kind: Service metadata: name: my-db-service spec: clusterIP: None selector: app: my-db ports: - protocol: TCP port: 3306 targetPort: 3306
Şöyle yaparız
apiVersion: apps/v1 kind: StatefulSet metadata: name: my-db-statefulset spec: serviceName: my-db-service replicas: 3 selector: matchLabels: app: my-db template: metadata: labels: app: my-db spec: containers: - name: my-container image: my-db-image env: - name: MYSQL_ROOT_PASSWORD value: my-password volumeClaimTemplates: - metadata: name: my-pvc spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 10Gi
Örnek - StatefulSet
Şöyle yaparız.
apiVersion: apps/v1kind: StatefulSetmetadata:name: kafkaspec:selector:matchLabels:app: kafkaserviceName: kafkareplicas: 3updateStrategy:type: RollingUpdatetemplate:metadata:labels:app: kafkaspec:hostname: kafkacontainers:- name: kafkaimage: <kafka-image>env:- name: KAFKA_ZOOKEEPER_CONNECTvalue: <zookeeper-endpoints>- name: KAFKA_ADVERTISED_LISTENERSvalue: PLAINTEXT://$(hostname -f):9092ports:- containerPort: 9092name: kafkavolumeMounts:- name: datamountPath: /var/lib/kafka/datavolumes:- name: datapersistentVolumeClaim:claimName: kafka-datavolumeClaimTemplates:- metadata:name: kafka-dataspec:accessModes:- ReadWriteOnceresources:requests:storage: 10Gi---apiVersion: v1kind: Servicemetadata:name: kafkaspec:clusterIP: Noneports:- name: kafkaport: 9092targetPort: 9092selector:app: kafka
Örnek - Deployment
Şöyle yaparız
apiVersion: v1 kind: Service metadata: name: my-service-a spec: clusterIP: None selector: app: my-service-a ports: - protocol: TCP port: 80 targetPort: 8080 --- apiVersion: apps/v1 kind: Deployment metadata: name: my-service-a-deployment spec: replicas: 3 selector: matchLabels: app: my-service-a template: metadata: labels: app: my-service-a spec: containers: - name: my-container image: my-service-a-image ports: - containerPort: 8080
Hiç yorum yok:
Yorum Gönder