部署knative
部署方法
https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/#prerequisites
部署serving核心组件
[root@master ~]# kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.7.2/serving-crds.yaml
[root@master ~]# kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.7.2/serving-core.yaml
[root@master ~]# kubectl get pods -n knative-serving
NAME READY STATUS RESTARTS AGE
activator-76cc45fff8-kl646 1/1 Running 0 145m
autoscaler-78f677f7fb-rpz5p 1/1 Running 0 134m
controller-6c498f87-j457v 1/1 Running 0 134m
domain-mapping-76dbd88d69-lw7rl 1/1 Running 0 134m
domainmapping-webhook-bcbc6464-pct45 1/1 Running 0 134m
webhook-5ff7fc4687-drkhr 1/1 Running 0 145m
[root@master ~]# kubectl get deployment -n knative-serving
NAME READY UP-TO-DATE AVAILABLE AGE
activator 1/1 1 1 4h53m
autoscaler 1/1 1 1 4h53m
controller 1/1 1 1 4h53m
domain-mapping 1/1 1 1 4h53m
domainmapping-webhook 1/1 1 1 4h53m
webhook 1/1 1 1 4h53m
部署网络组件
curl -LO https://github.com/knative/net-istio/releases/download/knative-v1.7.0/istio.yaml
vim istio.yaml # 将policy/v1beta1修改为policy/v1
kubectl apply -l knative.dev/crd-install=true -f istio.yaml
kubectl apply -f istio.yaml
[root@master ~]# kubectl get ns
NAME STATUS AGE
default Active 14d
istio-system Active 4m12s
knative-serving Active 34h
kube-node-lease Active 14d
kube-public Active 14d
kube-system Active 14d
[root@master ~]# kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
istio-ingressgateway-6849fc894d-4slzl 1/1 Running 0 4m17s
istio-ingressgateway-6849fc894d-mvv5z 1/1 Running 0 4m17s
istio-ingressgateway-6849fc894d-n2g8t 1/1 Running 0 4m17s
istiod-9c5b49645-fj67w 1/1 Running 0 4m7s
istiod-9c5b49645-jbtsc 1/1 Running 0 4m17s
istiod-9c5b49645-slkc6 1/1 Running 0 4m7s
Install a networking layer
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.7.0/net-istio.yaml
[root@master ~]# kubectl get pods -n knative-serving
NAME READY STATUS RESTARTS AGE
activator-76cc45fff8-kl646 1/1 Running 0 32h
autoscaler-78f677f7fb-rpz5p 1/1 Running 0 32h
controller-6c498f87-j457v 1/1 Running 0 32h
domain-mapping-76dbd88d69-lw7rl 1/1 Running 0 32h
domainmapping-webhook-bcbc6464-2bj9t 1/1 Running 0 32h
net-istio-controller-56cc84bf8f-vq9fr 1/1 Running 0 76s
net-istio-webhook-5d9864f688-slffd 1/1 Running 0 76s
webhook-5ff7fc4687-drkhr 1/1 Running 0 32h
给ingressgateway添加一个外部地址
kubectl edit service istio-ingressgateway -n istio-system
[root@master ~]# kubectl --namespace istio-system get service istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.100.247.178 10.211.55.30 15021:30446/TCP,80:31623/TCP,443:31154/TCP 57m
安装 Knative CLI
wget https://storage.googleapis.com/knative-nightly/client/latest/kn-linux-amd64
cp kn-linux-amd64 /usr/local/bin/kn
chmod +x /usr/local/bin/kn
kn --help
我运行demoapp的时候报错了,因为下载镜像失败了
[root@master ~]# kn service create demoapp --image=ikubernetes/demoapp:v1.0
Creating service 'demoapp' in namespace 'default':
0.051s The Route is still working to reflect the latest desired specification.
0.125s ...
0.141s Configuration "demoapp" is waiting for a Revision to become ready.
Error: timeout: service 'demoapp' not ready after 600 seconds
Run 'kn --help' for usage
我有代理让docker走代理服务器,然后下载镜像测试
vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.3.77:9999"
Environment="HTTPS_PROXY=socks5://192.168.3.77:10000"
下载镜像
docker pull gcr.io/knative-releases/knative.dev/serving/cmd/queue@sha256:9b8dad0630029dfcab124e6b4fa7c8e39b453249f0b31282c48e008bfc16faa3
再次创建demoapp
[root@master ~]# kn service delete demoapp
[root@master ~]# kn service create demoapp --image=ikubernetes/demoapp:v1.0
Creating service 'demoapp' in namespace 'default':
0.051s The Route is still working to reflect the latest desired specification.
0.077s Configuration "demoapp" is waiting for a Revision to become ready.
75.879s ...
75.963s Ingress has not yet been reconciled.
76.090s Ready to serve.
Service 'demoapp' created to latest revision 'demoapp-00001' is available at URL:
http://demoapp.default.example.com
查看下pod然后curl访问
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
demoapp-00001-deployment-b75d96697-lwzht 3/3 Running 0 59s
[root@master ~]# curl -H "Host: demoapp.default.example.com" 10.211.55.30
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.1, ServerName: demoapp-00001-deployment-b75d96697-lwzht, ServerIP: 10.244.166.145!
如果一直不访问,pod会处于Terminating状态
如果有访问流量,当请求的那一刻会临时创建一个pod响应请求
如果并发访问量变大会自动扩容增加pod
[root@master ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
demoapp-00001-deployment 0/0 0 0 11m
[root@master ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demoapp ExternalName <none> knative-local-gateway.istio-system.svc.cluster.local 80/TCP 11m
demoapp-00001 ClusterIP 10.111.131.8 <none> 80/TCP,443/TCP 11m
demoapp-00001-private ClusterIP 10.98.248.135 <none> 80/TCP,443/TCP,9090/TCP,9091/TCP,8022/TCP,8012/TCP 11m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21d
[root@master ~]# kubectl get configuration
NAME LATESTCREATED LATESTREADY READY REASON
demoapp demoapp-00001 demoapp-00001 True
[root@master ~]# kubectl get revision
NAME CONFIG NAME K8S SERVICE NAME GENERATION READY REASON ACTUAL REPLICAS DESIRED REPLICAS
demoapp-00001 demoapp
[root@master ~]# kubectl get route
NAME URL READY REASON
demoapp http://demoapp.default.example.com True
[root@master ~]# kubectl get vs
NAME GATEWAYS HOSTS AGE
demoapp-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["demoapp.default","demoapp.default.example.com","demoapp.default.svc","demoapp.default.svc.cluster.local"] 13m
demoapp-mesh ["mesh"] ["demoapp.default","demoapp.default.svc","demoapp.default.svc.cluster.local"] 13m