What are services in Kubernetes?

The service supports access to a set of network Pods in Kubernetes.

The service selects the Pod based on the label. When making a network request to the service, it will select all Pods that match the service selector, select one of them, and forward the network request to it.

image.gif

Kubernetes Service and Deployment

What is the difference between service and deployment in Kubernetes?

The deployment is responsible for keeping a pod in operation.

The service is responsible for enabling network access to a group of pods.

We can use deployment without services to keep the same Pod running in a cluster in Kubernetes. Development can be extended and expanded, Pod. Each Pod is accessed individually through direct network requests (rather than copying them to the service), but many pods are tracked.

We can also use services that have not been created. We need to create each pod separately (instead of creating a "body" like creation). Then our service can tag the network request tags to these pods by selecting them.

Service and development are different, but they can work well together

Kubernetes service NodePort example YAML

This sample YAML creates a service that can be used for external network requests. We have specified the NodePort to assign the service to that port on the value center node

image.png

Below is some sample YAML code to show you how to use the NodePort service in Kubernetes


Type: Service
api version: v1
Metadata:
  Name: hostname service
Specification:
  # Expose the service on the static port of each node
  # So we can access the service from outside the cluster
  Type: Node port

  # When the node receives a request for a static port (30163)
  # "Select the pods whose label'app' is set to'echo-hostname'"
  # And forward the request to one of them
  Selector:
    Application: Echo hostname

  port:
    # Three ports of a service
    # nodePort-Static port assigned on each node
    # port-port exposed inside the cluster
    # targetPort-The container port to send the request to
    -Node port: 30163
      Port: 8080
      Destination port: 80
``

### What is the English of ClusterIP, NodePort and LoadBalancer?

The attributes in the type service specification determine that the service is exposed to the network. It changes where the service can be accessed from. Possible types are ClusterIP, NodePort and LoadBalancer

-`ClusterIP`: The default value service can only be accessed from inside the Kubernetes cluster-you cannot make requests to your Pod from the outside!
-`NodePort`: This additional service can be accessed on the port of the hub node. The service can handle requests from outside.
-`LoadBalancer`: The service can be accessed from the outside through the cloud's load balancer function. GCP, Azure, Azure, and OpenStack provide this feature. The cloud will create a load balancer, and then it will automatically transfer the request to your Kubernetes service
点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部