写点什么

跟 GPT 学 k8s-Kubernetes-native load balancer options

作者:jupiter
  • 2023-03-28
    广东
  • 本文字数:2228 字

    阅读完需:约 7 分钟

What is ClusterIP

ClusterIP is a type of Kubernetes service that exposes a set of pods within a cluster to other objects within the same cluster. It provides a stable IP address and DNS name that can be used by other services and pods within the same Kubernetes cluster to access the set of pods it represents.

The ClusterIP service type is the default service type for Kubernetes. It sets up a virtual IP address for the service and automatically load balances traffic across the pods that are part of the service. The virtual IP address is only accessible from within the cluster, and not from outside the cluster.

ClusterIP is useful for creating microservices that communicate with each other within a cluster. It allows you to decouple the service consumers from the service providers, so that you can scale and update them independently without breaking the overall system.

ClusterIP can be defined in a Kubernetes manifest file using YAML syntax. Here’s an example of a ClusterIP service definition that exposes a deployment named “my-deployment” on port 80:

apiVersion: v1kind: Servicemetadata:  name: my-servicespec:  selector:    app: my-app  ports:    - name: http      port: 80      targetPort: 80  type: ClusterIP
复制代码

In this example, the service is named “my-service” and it selects pods with the label “app: my-app” as its target. It exposes port 80 and routes traffic to the pods’ port 80.

What is NodePort?

NodePort is a type of Kubernetes service that exposes a set of pods to the outside world by creating a static port on each node in the cluster. It allows external traffic to be directed to the service by accessing any of the nodes’ IP address at the specified static port.

NodePort is typically used for development or testing purposes, or when deploying a service that needs to be accessible from outside the cluster without a load balancer. However, it’s not recommended for production use because it can create a security risk and has scalability limitations.

When you create a NodePort service, Kubernetes automatically assigns a port in the range of 30000-32767 as the static port for the service. The assigned port can be specified explicitly in the service definition if you prefer a specific port number.

Here’s an example of a NodePort service definition that exposes a deployment named “my-deployment” on port 80:

apiVersion: v1kind: Servicemetadata:  name: my-servicespec:  selector:    app: my-app  ports:    - name: http      port: 80      targetPort: 80      nodePort: 30080  type: NodePort
复制代码

In this example, the service is named “my-service” and it selects pods with the label “app: my-app” as its target. It exposes port 80 and routes traffic to the pods’ port 80. It also specifies a static node port of 30080, which allows the service to be accessed from any of the nodes in the cluster at the node’s IP address and the specified static port.

What's ExternalName services

ExternalName services is a type of Kubernetes service that allows you to create a DNS entry for an external service or resource. It does not create any load balancing or proxying for the external resource, but instead acts as a mapping service so that clients within the cluster can refer to it by a DNS name rather than an IP address.

ExternalName services are typically used to reference non-Kubernetes services or resources that are external to the Kubernetes cluster, such as a database or a third-party API. It allows those resources to be accessed by other Kubernetes services within the cluster using a uniform DNS name with the same syntax as other Kubernetes services.

Here’s an example of an ExternalName service definition that maps a service named “my-service” to an external DNS name of “example.com”:

apiVersion: v1kind: Servicemetadata:  name: my-servicespec:  type: ExternalName  externalName: example.com
复制代码

In this example, the service is named “my-service” and has a type of “ExternalName”. It maps the DNS name “my-service” to the external name “example.com”. Whenever a pod or service within the Kubernetes cluster refers to “my-service”, Kubernetes will look up the external DNS name and return the IP address(es) associated with it.

Note that the external resource must be resolvable by the DNS server(s) used by the Kubernetes cluster. Additionally, ExternalName services only support TCP and UDP protocols for their ports, and only allow a single port to be defined per service.

用户头像

jupiter

关注

还未添加个人签名 2022-01-14 加入

还未添加个人简介

评论

发布
暂无评论
跟GPT学k8s-Kubernetes-native load balancer options_jupiter_InfoQ写作社区