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,
查看按需启动的无服务应用,一段时间内无业务请求,自动释放,
