Serverless- Knative的使用例子

文档说明:自建K8S,只记录关键地方;
k8s 版本 > 1.24.7
CRI 使用 containerd
实验环境: linux debian 11

目标:serverless 使用实践

knative 应用例子: chromium 扩展开发文档展示

pod 有效期1个小时,1小时候以后没有访问流量,容器自动停止运行

获取某个容器的最新tag


chrome_docs_latest_tag=$(curl -L -s 'https://hub.docker.com/v2/repositories/wenba100xie/developer.chrome.com/tags/?page_size=1&page=1&ordering=last_updated'|jq '."results"[]["name"]'| sed 's/\"//g')
echo "export chrome_docs_latest_tag='$chrome_docs_latest_tag'" >> latest_tag_conf.sh

echo $chrome_docs_latest_tag


运行knative service pod


apiVersion: serving.knative.dev/v1
kind: Service
metadata:
    name: developer-chrome-com
    namespace: kn
    annotations:
        serving.knative.dev/rolloutDuration: "380s"
spec:
    template:
        metadata:
            labels:
                app: developer-chrome-com
            annotations:
                #                autoscaling.knative.dev/class: "kpa.autoscaling.knative.dev"
                autoscaling.knative.dev/class: "kpa.autoscaling.knative.dev"
                autoscaling.knative.dev/maxScale: "1"
                autoscaling.knative.dev/minScale: "0"
                autoscaling.knative.dev/scaleToZeroPodRetentionPeriod: "1h0m0s"
        spec:
            containers:
                - image: wenba100xie/developer.chrome.com:20220901
                  ports:
                      -   containerPort: 80 #containerPort 字段就是容器提供服务的唯一端口。业务端口可以设置 1-65535 这个范围中除了 8012、8013、8022、8091 和 8092 以外的任意端口
                          name: http1
    traffic:
        - latestRevision: true
          percent: 100


查看knative pod 状态


kubectl get pods -n knative-serving
kubectl get pod -n kn
kubectl get ksvc -n kn 
kubectl get pods --namespace istio-system
kubectl get pod -n kn   -l serving.knative.dev/service=developer-chrome-com -w

kubectl get svc -n istio-system

kubectl get namespace knative-serving -o 'go-template={{index .metadata.labels "serving.knative.dev/release"}}'


浏览器访问

https://developer-chrome-com.knative.xiaoshuogeng.com

参考文档

上一篇 Serverless- Knative的初始化

下一篇

posted @ 2022-10-28 18:32  jingjingxyk  阅读(72)  评论(0编辑  收藏  举报