Publish a service from a Managed Kubernetes cluster to the Internet
1. Check quotas
Make sure that the pool has an allocated quota for at least one public IP address. To do this, view Cloud Platform quota consumption.
2. Connect to the cluster
To connect to the cluster, use the Connect to a Managed Kubernetes cluster instructions.
3. Create a GatewayClass
-
Create a YAML file with a manifest for the GatewayClass object.
Example of a GatewayClass manifest:
---apiVersion: gateway.networking.k8s.io/v1kind: GatewayClassmetadata:name: envoy-gatewayspec:controllerName: gateway.envoyproxy.io/gatewayclass-controller -
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>— the name of the YAML file with the manifest for creating a GatewayClass object. For example,<gatewayclass.yaml>.
4. Create a Gateway
-
Create a YAML file with a manifest for the Gateway object.
Example of a Gateway manifest:
---apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata:name: external-gatewayspec:gatewayClassName: envoy-gatewaylisteners:- name: httpprotocol: HTTPport: 80 -
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>— the name of the YAML file with the manifest for creating a Gateway object. For example,<gateway.yaml>.
The created load balancer will appear in the control panel: in the top menu, click Products and select Cloud Servers → Load Balancers section → Load Balancers.
5. Create an HTTPRoute
-
Create a YAML file with a manifest for the HTTPRoute object.
Example of an HTTPRoute manifest:
---apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata:name: test-routespec:parentRefs:- name: external-gatewayhostnames:- "test.com"rules:- matches:- path:type: Exactvalue: /testpathbackendRefs:- name: my-app-serviceport: 80Where:
external-gateway— name of the Gateway object;my-app-service— name of the service that you are exposing to the internet.
-
Apply the manifest:
kubectl apply -f <file_name>Specify
<file_name>— the name of the YAML file with the manifest for creating an HTTPRoute object. For example,<httproute.yaml>.