Alibaba Cloud Serverless Kubernetes supports service discovery for intranet services, Headless services, and ClusterIP services.
- You need to activate Alibaba Cloud DNS PrivateZone in the Alibaba Cloud DNS console first.
- A Serverless Kubernetes cluster is created. For more information, see Create a serverless Kubernetes cluster.
- You have connected to the Kubernetes clusters. For more information, see Connect to a Kubernetes cluster by using kubectl.
PrivateZone is an Alibaba Cloud private domain name resolution and management service based on VPC. You can map a private domain name to an IP address in one or more custom VPCs. Your private domain names are not accessible in other network environments.
- Deploy a Deployment and create a Service.
The sample template is as follows. Copy the following yaml code to the yaml file. Then run the
kubectl create -f nginx-service.yamlcommand to create a service.
apiVersion: v1 kind: Service metadata: name: nginx-headless-service spec: ports: - port: 80 protocol: TCP selector: app: nginx clusterIP: None --- apiVersion: v1 kind: Service metadata: name: nginx-clusterip-service spec: ports: - port: 80 protocol: TCP selector: app: nginx type: ClusterIP --- apiVersion: v1 kind: Service metadata: name: nginx-intranet-service annotations: service.beta.kubernetes.io/alicloud-loadbalancer-address-type: intranet spec: ports: - port: 80 protocol: TCP selector: app: nginx type: LoadBalancer --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine ports: - containerPort: 80
- Run the following command to view the operating status of the application:
kubectl get svc,pod,deployment
- In the left-side navigation pane, click
. A record is automatically generated in the zone list.
- Click Configure. The Resolution Settings page appears.
Note The format of the host machine record is
$svc.$ns, and the record corresponds to an IP resolution. Resolution rules are as follows:
You can access the service by using the private domain name in the VPC. The private domain name can be a long domain name or a short domain name.
- LoadBalancer service: corresponds to only one resolution record in PrivateZone, which is the SLB IP.
- ClusterIP service: corresponds to multiple resolution records in PrivateZone, which are the IPs of the backend pods.
- Headless service: corresponds to multiple resolution records in PrivateZone, which are the IPs of the backend pods.
- A long domain name: You can use
$svc.$ns.svc.cluster.local.$clusterIdto connect to services in other clusters that are synchronized to PrivateZone.
- A short domain name: You can use
$svcto connect to the service under this namespace and use
$svc.$nsto connect to services in other namespaces.
For more information, see serverless-k8s-examples.