Knative services
Knative Serving runs your containers as services that scale with requests. An idle service scales to zero pods. The next request starts it again. Multicloud installs and runs Knative for you in a Kubernetes pool. This page shows how to turn Knative on, deploy a service and publish it on a public hostname.
Contents
- Before you start
- Turn Knative on
- Deploy a Knative service
- Publish a service on a public hostname
- Turn Knative off
- Limits
1. Before you start
- You have a Kubernetes pool. The Multicloud Kubernetes Engine guide shows how to create one.
- You are an organization owner, or you use an API key with Write access.
- You can connect to the pool with
kubectl.
2. Turn Knative on
Knative adds 6 platform pods to the pool. Their requests are 0.09 vCPU and 0.44 GiB in total. These pods never keep a node alive on their own.
Console: open the pool, go to the Settings tab, and set Knative to On. The state shows Installing, then On.
mctl:
mctl pool knative <pool> --on
mctl pool knative <pool>
The second command shows the state. Wait for ready.
If the state is blocked with reason CUSTOMER_KNATIVE, the pool already runs its own Knative.
Remove your own Knative, or keep the add-on off.
3. Deploy a Knative service
Apply a Knative Service in a namespace of your own. Example, in namespace demo:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: hello
namespace: demo
spec:
template:
spec:
containers:
- image: ghcr.io/knative/helloworld-go
env:
- name: TARGET
value: World
kubectl create namespace demo
kubectl apply -f hello.yaml
kubectl -n demo get ksvc hello
Inside the pool, the service answers on http://hello.demo.svc.cluster.local.
Knative services are not public until you publish them (section 4).
4. Publish a service on a public hostname
You publish a Knative service like any other Kubernetes Service: with an Ingress on a pool hostname.
Knative creates a Service with the same name as your Knative service. Use that name and port 80.
Console:
- Open the pool and go to the Ingress tab.
- Click Expose a Service.
- Enter the namespace (
demo), the Service name (hello) and port80. - Choose the hostname and the path.
- Click Create apply line, and run the apply line on your cluster.
The hostname serves HTTPS when its Ingress is applied. The certificate is automatic.
The apply line creates an Ingress like this one. <pool-label> is the first part of the pool hostname that the Ingress tab shows.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: multicloud-edge-<pool-label>-app
namespace: demo
annotations:
multicloud.io/edge: "true"
spec:
ingressClassName: multicloud
rules:
- host: app.<pool-label>.edge.multicloud.ing
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello
port:
number: 80
A request to a service with zero pods waits while Knative starts a pod. The first request after an idle time is slower.
If the pool has no Ingress tab, public ingress is not on for your organization. Contact support.
5. Turn Knative off
Delete your Knative services first, in every namespace. Knative does not turn off while services exist in the pool.
kubectl get ksvc -A
kubectl delete ksvc --all -n demo
mctl pool knative <pool> --off
--off asks first. Add -y to skip the question, for example in a script.
In the Console, set Knative to Off on the Settings tab. If services remain, the state shows Delete your Knative services first with the number left.
6. Limits
- Knative is for Kubernetes pools only. CI and Extend pools do not have it.
- A pool has one pool hostname and at most 5 extra hostnames: 6 public hostnames per pool.
- One hostname serves one namespace. Use paths to put more services of that namespace on one hostname. So at most 6 namespaces per pool have public Knative services.
- Knative's own automatic URLs (
<name>-<namespace>.<domain>) are not public. You pick which service gets which hostname. - Your own domain (a CNAME to the pool hostname) is not in the Console yet.