创建 ns
# kubectl create ns knative-demo
namespace/knative-demo created
创建应用
hello-world.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
namespace: knative-demo
spec:
template:
spec:
containers:
- image: ghcr.dockerproxy.com/knative/helloworld-go:latest
env:
- name: TARGET
value: "Go Sample v1"
创建资源
# kubectl apply -f hello-word.yaml
service.serving.knative.dev/hello created
查看资源
查看 Pod
# kubectl get svc,deployment,pods -n knative-demo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/helloworld-go ExternalName <none> knative-local-gateway.istio-system.svc.wgs.local 80/TCP 46s
service/helloworld-go-00001 ClusterIP 10.100.172.219 <none> 80/TCP,443/TCP 47s
service/helloworld-go-00001-private ClusterIP 10.100.7.170 <none> 80/TCP,443/TCP,9090/TCP,9091/TCP,8022/TCP,8012/TCP 48s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/helloworld-go-00001-deployment 1/1 1 1 48s
NAME READY STATUS RESTARTS AGE
pod/helloworld-go-00001-deployment-5c44fdc68-njv7n 2/2 Running 0 48s
查看 configuration
# kubectl get configurations -n knative-demo
NAME LATESTCREATED LATESTREADY READY REASON
helloworld-go helloworld-go-00001 helloworld-go-00001 True
查看 revision
# kubectl get revisions -n knative-demo
NAME CONFIG NAME K8S SERVICE NAME GENERATION READY REASON ACTUAL REPLICAS DESIRED REPLICAS
helloworld-go-00001 helloworld-go 1 True 0 0
查看 kpa
# kubectl get kpa -n knative-demo
NAME DESIREDSCALE ACTUALSCALE READY REASON
helloworld-go-00001 0 0 False NoTraffic
查看 route
# kubectl get rt -n knative-demo
NAME URL READY REASON
helloworld-go http://helloworld-go.knative-demo.svc.wgs.local True
查看 ingress 地址
# kubectl --namespace istio-system get service istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.100.132.184 192.168.174.249 15021:31063/TCP,80:56051/TCP,443:33148/TCP 40m
查看 istio ingress 路由信息
# istioctl proxy-config all istio-ingressgateway-568ffb9976-lk455 -n istio-system |grep helloworld-go
helloworld-go-00001-private.knative-demo.svc.wgs.local 80 - outbound EDS
helloworld-go-00001-private.knative-demo.svc.wgs.local 443 - outbound EDS
helloworld-go-00001-private.knative-demo.svc.wgs.local 8012 - outbound EDS
helloworld-go-00001-private.knative-demo.svc.wgs.local 8022 - outbound EDS
helloworld-go-00001-private.knative-demo.svc.wgs.local 9090 - outbound EDS
helloworld-go-00001-private.knative-demo.svc.wgs.local 9091 - outbound EDS
helloworld-go-00001.knative-demo.svc.wgs.local 80 - outbound EDS
helloworld-go-00001.knative-demo.svc.wgs.local 443 - outbound EDS
helloworld-go.knative-demo.svc.wgs.local 80 - outbound STRICT_DNS
http.8081 helloworld-go.knative-demo.svc.wgs.local:8081 helloworld-go.knative-demo.svc.wgs.local, helloworld-go.knative-demo.wgs.com + 1 more... /* helloworld-go-ingress.knative-demo
http.8081 helloworld-go.knative-demo.svc.wgs.local:8081 helloworld-go.knative-demo.svc.wgs.local, helloworld-go.knative-demo.wgs.com + 1 more... /* helloworld-go-ingress.knative-demo
http.8080 helloworld-go.knative-demo.svc.wgs.local:80 helloworld-go.knative-demo.svc.wgs.local, helloworld-go.knative-demo.wgs.com + 1 more... /* helloworld-go-ingress.knative-demo
http.8080 helloworld-go.knative-demo.svc.wgs.local:80 helloworld-go.knative-demo.svc.wgs.local, helloworld-go.knative-demo.wgs.com + 1 more... /* helloworld-go-ingress.knative-demo
集群内部访问应用
创建测试 pod
# kubectl run client --image=ikubernetes/admin-box -it --rm --restart=Never --command -n default -- /bin/bash
If you don't see a command prompt, try pressing enter.
root@client /#
内部访问应用
# curl http://helloworld-go.knative-demo.svc.wgs.local
Hello Go Sample v1!
集群外部访问应用
设置 DNS
# kubectl patch configmap/config-domain --namespace knative-serving --type merge --patch '{"data":{"wgs.com":""}}'
查看 rt
# kubectl get rt -n knative-demo
NAME URL READY REASON
helloworld-go http://helloworld-go.knative-demo.wgs.com True
外部访问应用
# curl -H "Host: helloworld-go.knative-demo.wgs.com" http://192.168.174.249
Hello Go Sample v1!
标签:Serving,demo,helloworld,Knative,wgs,go,local,knative
From: https://www.cnblogs.com/wangguishe/p/17705328.html