安装knative-serving-1.18.0
knative-serving 官网
https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/#install-the-knative-serving-component
安装所需的定制资源
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.18.0/serving-crds.yaml
查看新创建的资源
kubectl api-resources --api-group=serving.knative.dev
NAME SHORTNAMES APIVERSION NAMESPACED KIND
configurations config,cfg serving.knative.dev/v1 true Configuration
domainmappings dm serving.knative.dev/v1beta1 true DomainMapping
revisions rev serving.knative.dev/v1 true Revision
routes rt serving.knative.dev/v1 true Route
services kservice,ksvc serving.knative.dev/v1 true Service
安装 knative-serving 核心组件
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.18.0/serving-core.yaml
kubectl get deployment -n knative-serving
NAME READY UP-TO-DATE AVAILABLE AGE
activator 1/1 1 1 2m26s
autoscaler 1/1 1 1 2m25s
controller 1/1 1 1 2m25s
webhook 1/1 1 1 2m25s
kubectl get pods -n knative-serving
NAME READY STATUS RESTARTS AGE
activator-cbf5b6b55-sh672 1/1 Running 0 2m47s
autoscaler-c5d454c88-hjbdb 1/1 Running 0 2m46s
controller-84f96b7676-8hj5q 1/1 Running 0 2m46s
webhook-75d4fb6db5-xm4rj 1/1 Running 0 2m46s
安装网络层我用的 istio
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.18.0/istio.yaml
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.18.0/net-istio.yaml
把 yzy.com设置为默认域名
kubectl patch configmap config-domain \
-n knative-serving \
--type merge \
--patch '{"data":{"yzy.com":""}}'
编辑 istio-ingressgateway添加一个入口 IP,在 externalTrafficPolicy: Cluster下面添加
kubectl edit svc istio-ingressgateway -n istio-system
externalTrafficPolicy: Cluster
externalIPs:
- 10.211.55.74
查看添加是否成功
kubectl --namespace istio-system get service istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.111.190.24 10.211.55.74 15021:31810/TCP,80:30408/TCP,443:32244/TCP 16m
安装扩展组件 hpa
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.18.0/serving-hpa.yaml
下载二进制 kn
wget https://storage.googleapis.com/knative-nightly/client/latest/kn-linux-amd64
cp kn-linux-amd64 kn-linux-amd64
chmod +x kn-linux-amd64
测试一个案例
# kn service create demoapp --image=ikubernetes/demoapp:v1.0
Warning: Kubernetes default value is insecure, Knative may default this to secure in a future release: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation, spec.template.spec.containers[0].securityContext.capabilities, spec.template.spec.containers[0].securityContext.runAsNonRoot, spec.template.spec.containers[0].securityContext.seccompProfile
Creating service 'demoapp' in namespace 'default':
0.076s The Route is still working to reflect the latest desired specification.
0.116s Configuration "demoapp" is waiting for a Revision to become ready.
0.129s ...
9.163s ...
9.248s Ingress has not yet been reconciled.
9.349s Waiting for load balancer to be ready
9.525s Ready to serve.
Service 'demoapp' created to latest revision 'demoapp-00001' is available at URL:
访问测试
# curl -H "Host: demoapp.default.yzy.com" http://10.211.55.74
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.1, ServerName: demoapp-00001-deployment-9974c8b68-c647j, ServerIP: 10.244.169.168!
# curl -H "Host: demoapp.default.yzy.com" http://10.211.55.74
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.1, ServerName: demoapp-00001-deployment-9974c8b68-c647j, ServerIP: 10.244.169.168!
不妨问的时候 pod 会缩容到 0,当访问的时候会立即启用 pod
root@k8s-master:~# kubectl get pods -w
NAME READY STATUS RESTARTS AGE
bookinfo-gateway-istio-746f559795-q7jdz 1/1 Running 3 (55m ago) 43h
demoapp-00001-deployment-9974c8b68-mh7nv 2/3 Terminating 0 18m
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 Pending 0 0s
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 Init:0/1 0 0s
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 Init:0/1 0 0s
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 PodInitializing 0 0s
demoapp-00001-deployment-9974c8b68-ct4zg 1/3 Running 0 1s
demoapp-00001-deployment-9974c8b68-ct4zg 2/3 Running 0 1s
demoapp-00001-deployment-9974c8b68-ct4zg 2/3 Running 0 2s
demoapp-00001-deployment-9974c8b68-ct4zg 3/3 Running 0 2s
demoapp-00001-deployment-9974c8b68-ct4zg 3/3 Terminating 0 67s
demoapp-00001-deployment-9974c8b68-ct4zg 2/3 Terminating 0 91s
demoapp-00001-deployment-9974c8b68-ct4zg 1/3 Terminating 0 2m2s
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 Completed 0 6m8s
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 Completed 0 6m8s
demoapp-00001-deployment-9974c8b68-ct4zg 0/3 Completed 0 6m8s
root@k8s-master:~# kubectl get configuration
NAME LATESTCREATED LATESTREADY READY REASON
demoapp demoapp-00001 demoapp-00001 True
root@k8s-master:~# kubectl get revision
NAME CONFIG NAME GENERATION READY REASON ACTUAL REPLICAS DESIRED REPLICAS
demoapp-00001 demoapp 1 True 0 0
root@k8s-master:~# kubectl get route
NAME URL READY REASON
demoapp http://demoapp.default.yzy.com True
root@k8s-master:~# kubectl get vs
NAME GATEWAYS HOSTS AGE
demoapp-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["demoapp.default","demoapp.default.svc","demoapp.default.svc.cluster.local","demoapp.default.yzy.com"] 27m
demoapp-mesh ["mesh"] ["demoapp.default","demoapp.default.svc","demoapp.default.svc.cluster.local"] 27m

浙公网安备 33010602011771号