tencent cloud

Feedback

Basic Features

Last updated: 2024-12-23 11:41:09

Managing a Service in the Console

Creating a service

1. Log in to the TKE console and select Cluster in the left sidebar.
2. On the Cluster page, click the ID of the cluster for which you need to create a Service to go to the cluster management page.
3. Select Services and Routes > Service to go to the Service management page.

4. Click Create to enter the Create Service page. Set the Service parameters as needed. Key parameters are as follows:
Service Name: Customize a name.
Namespace: Select a namespace based on your requirements.
Access Settings: Set it as needed and as instructed in Service Access Methods.
(Optional) Advanced Settings:
External Traffic Policy:
Cluster: Defaults to averagely forward all Pods of the workload.
Local: Retain the client IP, and ensure that traffic is only forwarded within the node if the access mode is public network, VPC private network (LoadBalancer) and node port (NodePort). If you choose Local, the health check for nodes without Pods may fail, raising the risk of unbalanced traffic forwarding
Note
If the Service uses the Local method, there will be a stream interruption when a Pod is scheduled from a TKE node to a super node, or from a super node to a TKE node, because the Service will select only a local service endpoint.
Session Affinity: If you want to ensure that connections from a particular client are passed to the same Pod every time, you can set session affinity based on the client IP address by setting the Service's .spec.sessionAffinity to ClientIP (the default value is None).
Workload binding: Reference an existing workload or customize a label. Then, the Service will select workloads with the label.
Note
To use an existing CLB instance, see Using Existing CLBs.
As a layer-4 CLB instance has only the unique quadruple of CLB VIP, listener protocol, backend RS VIP, and backend RS port and doesn't contain a CLB listener port, scenarios with different CLB listener ports but the same protocol and RS are not supported. In addition, TKE doesn't support opening different ports of the same protocol for the same business.
5. Click Create Service.

Updating a Service

Updating configuration

1. Log in to the TKE console and select Cluster in the left sidebar.
2. On the Cluster Management page, click the target cluster ID to enter the cluster's basic information page.
3. Select Services and Routes > Service. On the Service page, locate the target service and click Update configuration on the right.

4. On the Update access method page, configure the access method as needed.
5. Click Update access method.

Editing YAML

1. Select Services and Routes > Service. On the Service page, locate the target service and click Edit YAML on the right.
2. On the Edit YAML page, edit the YAML and click Done.

Deleting a Service

1. Log in to the TKE console and select Cluster in the left sidebar.
2. On the Cluster Management page, click the target cluster ID to enter the cluster's basic information page.
3. Select Services and Routes > Service. On the Service page, locate the target service and click Delete on the right.


Managing a Service Using kubectl

YAML sample

kind: Service
apiVersion: v1
metadata:
## annotations:
## service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: subnet-xxxxxxxx ## If you are creating a Service for private network access, you need to specify this annotation.
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
type: LoadBalancer
Note:
kind: Service resource type.
metadata: Basic information such as Service name and label.
metadata.annotations: Additional description of the Service. You can set additional enhancements to TKE through this parameter.
spec.selector: The Service will select workloads with the label in the label selector.
spec.type: Mode for accessing the Service.
ClusterIP: The Service is made public in the cluster for internal access.
NodePort: The node port mapped to the backend Service. External access to the cluster can be implemented through IP:NodePort.
LoadBalancer: The Service is made public through the Tencent Cloud CLB instance. A public network CLB instance is created by default, and a private network CLB can be created by specifying annotations.
By default, you can create up to 100 public network or private network CLB instances. If you need more, submit a ticket to increase the quota.
The management and sync of configurations between Service and CLB instances are based on the resource object of the LoadBalancerResource type named the CLB ID. Do not perform any operations on this CRD; otherwise, the Service may fail.
ExternalName: The Service is mapped to DNS, which applies to only kube-dns 1.7 or later.

Creating a service

1. Prepare the Service YAML file as instructed in the YAML sample.
2. Install kubectl and connect to a cluster. For detailed operations, see Connecting to a Cluster.
3. Run the following command to create the Service YAML file.
kubectl create -f Service YAML filename
For example, to create a Service YAML file named my-service.yaml, run the following command:
kubectl create -f my-service.yaml
4. Run the following command to check whether the creation is successful:
kubectl get services
If a message similar to the following is returned, the creation is successful.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 172.16.255.1 <none> 443/TCP 38d

Updating a Service

Method 1

Run the following command to update a Service:
kubectl edit service/[name]

Method 2

1. Manually delete the old Service.
2. Run the following command to create a new Service:
kubectl create/apply

Deleting a Service

Run the following command to delete a Service:
kubectl delete service [NAME]

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support