knative的實踐(一)
參考的是人家的github項目,因為這個項目里的安裝模板用的是國內可訪問的容器鏡像安裝源,直接用knative官方的大概率是會遇到下載不成功的情況的,
下載項目,
git clone https://github.com/seanly/knative-demo.git,
cd knative-demo,
安裝knative需要的組件,
kubectl apply -f serving-crds.yaml,
kubectl apply -f serving-core.yaml,
kubectl apply -f net-kourier.yaml,
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}',
創建無服務應用,這個地方我自己改了一下,把命名空間的創建直接放到了創建無服務應用的模板里,這樣比較方便,
vim helloworld-go-app.yaml,
apiVersion: v1
kind: Namespace
metadata:
name: knative-demo
---
apiVersion: serving.knative.dev/v1 # Current version of Knative
kind: Service
metadata:
name: helloworld-go # The name of the app
namespace: knative-demo
spec:
template:
spec:
containers:
- image: jmalloc/echo-server # The URL to the image of the app
env:
- name: TARGET # The environment variable printed out by the sample app
value: "Go Sample v1"
kubectl apply -f helloworld-go-app.yaml,
查看knative服務,獲取服務域名,
kubectl get ksvc -n knative-demo,
查看ingress發布的端口,
kubectl get service -n kourier-system,

訪問無服務,首次訪問需要等待一會兒,
curl -H "Host: helloworld-go.knative-demo.knative.k8ops.cn" http://10.90.11.166:30787,

查看按需啟動的無服務應用,一段時間內無業務請求,自動釋放,
