參考: https://knative.dev/docs/install/any-kubernetes-cluster/
kubectl apply --filename https://github.com/knative/net-kourier/releases/download/v0.20.0/kourier.yaml
namespace/kourier-system created
serviceaccount/3scale-kourier created
clusterrole.rbac.authorization.k8s.io/3scale-kourier created
clusterrolebinding.rbac.authorization.k8s.io/3scale-kourier created
deployment.apps/3scale-kourier-control created
service/kourier-control created
deployment.apps/3scale-kourier-gateway created
service/kourier created
service/kourier-internal created
configmap/kourier-bootstrap created
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'
configmap/config-network patched
kubectl --namespace kourier-system get service kourier
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kourier LoadBalancer 10.102.77.91 <pending> 80:30794/TCP,443:31790/TCP 22s
參考: https://knative.dev/docs/serving/getting-started-knative-app/
service.yaml
apiVersion: serving.knative.dev/v1 # Current version of Knative
kind: Service
metadata:
name: helloworld-go # The name of the app
namespace: default # The namespace the app will use
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go # Reference to the image of the app
env:
- name: TARGET # The environment variable printed out by the sample app
value: "Go Sample v1"
kubectl apply --filename service.yaml
可以看到
service.serving.knative.dev/helloworld-go created
查看服務是否成功部屬
kubectl get ksvc helloworld-go
NAME URL LATESTCREATED LATESTREADY READY REASON
helloworld-go http://helloworld-go.default.example.com helloworld-go-00001 helloworld-go-00001 True
Magic DNS 僅在集群 LoadBalancer 服務公開了 IPv4 地址的情況下才有效,因此不適用於 IPv6 集群,AWS 或 Minikube之類的本地設置。
生產環境的話,應該考慮使用Real DNS。
If you are using curl to access the sample applications, or your own Knative app, and are unable to use the “Magic DNS (xip.io)” or “Real DNS” methods, there is a temporary approach. This is useful for those who wish to evaluate Knative without altering their DNS configuration, as per the “Real DNS” method, or cannot use the “Magic DNS” method due to using, for example, minikube locally or IPv6 clusters.
取得部屬服務的 URL
kubectl get ksvc
NAME URL LATESTCREATED LATESTREADY READY REASON
helloworld-go http://helloworld-go.default.example.com helloworld-go-00001 helloworld-go-00001 True
Instruct curl to connect to the External IP or CNAME defined by the networking layer in section 3 above, and use the -H "Host:" command-line option to specify the Knative application’s host name. For example, if the networking layer defines your External IP and port to be http://192.168.39.228:32198 and you wish to access the above helloworld-go application, use:
curl -H "Host: helloworld-go.default.example.com" http://10.20.1.142:30794
Hello Go Sample v1!
參考: https://knative.dev/docs/serving/using-a-custom-domain/
先確認目前服務 route
kubectl get route helloworld-go
NAME URL READY REASON
helloworld-go http://helloworld-go.default.example.com True
By default, Knative Serving routes use example.com as the default domain. The fully qualified domain name for a route by default is {route}.{namespace}.{default-domain}.
To change the {default-domain} value there are a few steps involved:
config-domain.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: config-domain
namespace: knative-serving
data:
# These are example settings of domain.
# example.org will be used for routes having app=prod.
example.org: |
selector:
app: prod
# Default value for domain, for routes that does not have app=prod labels.
# Although it will match all routes, it is the least-specific rule so it
# will only be used if no other domain matches.
mydomain.com: ""
更新 Domain Configuration
kubectl apply --filename config-domain.yaml
查看服務的 Domain
kubectl get route helloworld-go
NAME URL READY REASON
helloworld-go http://helloworld-go.default.mydomain.com True
重新拜訪更新過 Domain 的服務
curl -H "Host: helloworld-go.default.mydomain.com" http://10.20.1.142:30794
Hello Go Sample v1!