0
点赞
收藏
分享

微信扫一扫

knative安装与实践

1、介绍

knative 是谷歌开源的 serverless 架构方案,旨在提供一套简单易用的 serverless 方案,把 serverless 标准化。knative 建立在 kubernetes 和 istio 平台之上,使用 kubernetes 提供的容器管理能力(deployment、replicaset、和 pods等),以及 istio 提供的网络管理功能(ingress、LB、dynamic route等)。

为了实现 serverless 应用的管理,knative 把整个系统分成了三个部分:

(一)Build:构建系统,把用户定义的函数和应用 build 成容器镜像

(二)Serving:服务系统,用来配置应用的路由、升级策略、自动扩缩容等功能

(三)Eventing:事件系统,用来自动完成事件的绑定和触发

2、安装

(1) 环境

操作系统:CentOS Linux release 7.9.2009 (Core)

K8s版本:minikube version: v1.24.0

Knative版本:v1.2.0

(2) Knative Serving
# 安装自定义资源 
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.2.0/serving-crds.yaml
# 安装核心组件
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.2.0/serving-core.yaml

# 安装Istio网络层组件
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.2.0/istio.yaml
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.2.0/net-istio.yaml
# 查看配置
kubectl --namespace istio-system get service istio-ingressgateway

# 验证安装结果
kubectl get pods -n knative-serving
NAME READY STATUS RESTARTS AGE
activator-5875d8cdd4-pnhgp 1/1 Running 3 (8h ago) 2d7h
autoscaler-67648d87fd-vtfw2 1/1 Running 2 2d7h
controller-698ff694df-f4rjv 1/1 Running 2 (8h ago) 2d7h
domain-mapping-86c95f49c9-bgjws 1/1 Running 2 2d7h
domainmapping-webhook-54c898d568-r78v4 1/1 Running 3 (8h ago) 2d7h
net-certmanager-controller-85db6558fc-btlw6 1/1 Running 2 (8h ago) 2d3h
net-certmanager-webhook-85dccf4596-rf6wn 1/1 Running 2 (8h ago) 2d3h
net-istio-controller-6b959c5db4-bpwp8 1/1 Running 2 (8h ago) 2d3h
net-istio-webhook-84854fd59-cfsp4 1/1 Running 2 (8h ago) 2d3h
webhook-649f9fbfb5-fp928 1/1 Running 4 (8h ago) 2d7h

# 安装TLS证书管理器
kubectl apply -f https://github.com/knative/net-certmanager/releases/download/knative-v1.2.0/release.yaml
(3) Knative Eventing
# 安装自定义资源(CRD)
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.2.0/eventing-crds.yaml
# 安装核心组件
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.2.0/eventing-core.yaml

# 查看安装结果
kubectl get pods -n knative-eventing
NAME READY STATUS RESTARTS AGE
eventing-controller-74958c68dc-spc5j 1/1 Running 3 (8h ago) 2d2h
eventing-webhook-7d975685f5-jhqn9 1/1 Running 4 (8h ago) 2d2h

3、实践

部署helloworld

配置helloworld-go.yaml

参考:​​https://github.com/knative/docs/tree/main/code-samples/serving/hello-world/helloworld-go​​

部署helloworld
# kubectl apply -f helloworld-go.yaml

[root@localhost knative]# kubectl -n istio-system get svc istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.98.3.238 <pending> 15021:31093/TCP,80:32398/TCP,443:30961/TCP 24d
[root@localhost knative]# kubectl get ksvc/helloworld-go
NAME URL LATESTCREATED LATESTREADY READY REASON
helloworld-go http://helloworld-go.default.example.comhelloworld-go-v1 helloworld-go-v1 True
[root@localhost knative]# curl -H "Host: helloworld-go.default.example.com" http://10.98.3.238
Hello Knative!
注意:可能遇到queue镜像下载出错,记得挂代理

2、修改默认域名
在Knative Serving Route路由中使用example.com作为默认域名,Route完全定义的域名格式默认为:{route}.{namespace}.{default-domain}

导出配置
# kubectl get cm config-domain --namespace knative-serving -o yaml >config-domain.yaml
编辑config-domain.yaml并配置域名信息
apiVersion: v1
data:
01314.cn: ""
kind: ConfigMap

重新应用配置
# kubectl apply -f config-domain.yaml

# 查看并请求
[root@localhost knative]# kubectl get ksvc/helloworld-go
NAME URL LATESTCREATED LATESTREADY READY REASON
helloworld-go http://helloworld-go.default.01314.cn helloworld-go-v1 helloworld-go-v1 True
[root@localhost knative]# curl -H "Host: helloworld-go.default.01314.cn" http://10.98.3.238
Hello Knative!

4、补充

(1) 参考文档:

官方安装教程:​​https://knative.dev/docs/install/​​

官方文档:​​https://github.com/knative/docs​​

官方案例:​​https://github.com/knative/docs/tree/main/code-samples​​

阿里云容器服务:​​https://partners-intl.aliyun.com/help/zh/doc-detail/121508.html​​

(2) Docker拉取gcr.io域名镜像异常处理:

1、配置代理:

# vim /etc/systemd/system/docker.service.d/http-proxy.conf 新增内容
[Service]
Environment="HTTP_PROXY=192.168.xxx.xxx:8118"
Environment="HTTPS_PROXY=192.168.xxx.xxx:8118"
# systemctl daemon-reload
# systemctl restart docker
# docker info 查看是否已包含HTTP Proxy

2、阿里云镜像服务

1、编排Dockerfile文件,提交github,通过阿里云镜像拉取github来构建自己镜像版本

2、下载阿里云镜像到本地,通过修改yaml来修改gcr.io的地址

具体操作参考:​​https://zhuanlan.zhihu.com/p/429685829​​



举报

相关推荐

0 条评论