# 0. 准备curl -Lfs -o istio.yaml https://github.com/knative/net-istio/releases/download/knative-v1.7.0/istio.yaml
# 根据版本不同,一些 API 不兼容,升级下配置文件的版本即可,kubectl api-resources |grep PodDisruptionBudgetsed 's#policy/v1beta1#policy/v1#g' -i istio.yaml
sed 's#maxReplicas: 10#maxReplicas: 2#g' -i istio.yaml
sed 's#minReplicas: 3#minReplicas: 1#g' -i istio.yaml
# 1. 安装 CRDskubectl apply -l knative.dev/crd-install=true -f istio.yaml
# 2. 安装 Istio 插件kubectl apply -f istio.yaml
# 3. 安装 Knative Istio controllercurl -LfS -o net-istio.yaml https://github.com/knative/net-istio/releases/download/knative-v1.7.0/net-istio.yaml
sed 's#gcr.io/knative-releases/knative.dev/net-istio/cmd/controller#gcrioknative/net-istio-controller#g' -i *.yaml
sed 's#gcr.io/knative-releases/knative.dev/net-istio/cmd/webhook#gcrioknative/net-istio-webhook#g' -i *.yaml
# 替换镜像版本sed "s#@sha256:.*#:v1.7.0#g" -i net-istio.yaml
kubectl apply -f net-istio.yaml
# 4. 查看 istio ingressgateway svc 信息root@k8s-master:~/knative# kubectl --namespace istio-system get service istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway NodePort 10.96.242.187 <none> 15021:30455/TCP,80:30999/TCP,443:32324/TCP 36h
安装 istio-net 日志
knative-istio-net-install↕
bash
root@k8s-master:~/knative# kubectl apply -l knative.dev/crd-install=true -f istio.yaml
customresourcedefinition.apiextensions.k8s.io/authorizationpolicies.security.istio.io created
customresourcedefinition.apiextensions.k8s.io/destinationrules.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/envoyfilters.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/gateways.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/istiooperators.install.istio.io created
customresourcedefinition.apiextensions.k8s.io/peerauthentications.security.istio.io created
customresourcedefinition.apiextensions.k8s.io/proxyconfigs.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/requestauthentications.security.istio.io created
customresourcedefinition.apiextensions.k8s.io/serviceentries.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/sidecars.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/telemetries.telemetry.istio.io created
customresourcedefinition.apiextensions.k8s.io/virtualservices.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/wasmplugins.extensions.istio.io created
customresourcedefinition.apiextensions.k8s.io/workloadentries.networking.istio.io created
customresourcedefinition.apiextensions.k8s.io/workloadgroups.networking.istio.io created
root@k8s-master:~/knative# kubectl apply -f istio.yaml
namespace/istio-system unchanged
serviceaccount/istio-ingressgateway-service-account unchanged
serviceaccount/istio-reader-service-account unchanged
serviceaccount/istiod unchanged
serviceaccount/istiod-service-account unchanged
clusterrole.rbac.authorization.k8s.io/istio-reader-clusterrole-istio-system unchanged
clusterrole.rbac.authorization.k8s.io/istio-reader-istio-system unchanged
clusterrole.rbac.authorization.k8s.io/istiod-clusterrole-istio-system unchanged
clusterrole.rbac.authorization.k8s.io/istiod-gateway-controller-istio-system unchanged
clusterrole.rbac.authorization.k8s.io/istiod-istio-system unchanged
clusterrolebinding.rbac.authorization.k8s.io/istio-reader-clusterrole-istio-system unchanged
clusterrolebinding.rbac.authorization.k8s.io/istio-reader-istio-system unchanged
clusterrolebinding.rbac.authorization.k8s.io/istiod-clusterrole-istio-system unchanged
clusterrolebinding.rbac.authorization.k8s.io/istiod-gateway-controller-istio-system unchanged
clusterrolebinding.rbac.authorization.k8s.io/istiod-istio-system unchanged
role.rbac.authorization.k8s.io/istio-ingressgateway-sds unchanged
role.rbac.authorization.k8s.io/istiod unchanged
role.rbac.authorization.k8s.io/istiod-istio-system unchanged
rolebinding.rbac.authorization.k8s.io/istio-ingressgateway-sds unchanged
rolebinding.rbac.authorization.k8s.io/istiod unchanged
rolebinding.rbac.authorization.k8s.io/istiod-istio-system unchanged
customresourcedefinition.apiextensions.k8s.io/authorizationpolicies.security.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/destinationrules.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/envoyfilters.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/gateways.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/istiooperators.install.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/peerauthentications.security.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/proxyconfigs.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/requestauthentications.security.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/serviceentries.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/sidecars.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/telemetries.telemetry.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/virtualservices.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/wasmplugins.extensions.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/workloadentries.networking.istio.io unchanged
customresourcedefinition.apiextensions.k8s.io/workloadgroups.networking.istio.io unchanged
configmap/istio unchanged
configmap/istio-sidecar-injector unchanged
deployment.apps/istio-ingressgateway configured
deployment.apps/istiod configured
service/istio-ingressgateway unchanged
service/istiod unchanged
Warning: autoscaling/v2beta2 HorizontalPodAutoscaler is deprecated in v1.23+, unavailable in v1.26+; use autoscaling/v2 HorizontalPodAutoscaler
horizontalpodautoscaler.autoscaling/istiod unchanged
poddisruptionbudget.policy/istio-ingressgateway configured
poddisruptionbudget.policy/istiod configured
mutatingwebhookconfiguration.admissionregistration.k8s.io/istio-sidecar-injector configured
validatingwebhookconfiguration.admissionregistration.k8s.io/istio-validator-istio-system configured
envoyfilter.networking.istio.io/stats-filter-1.11 created
envoyfilter.networking.istio.io/stats-filter-1.12 created
envoyfilter.networking.istio.io/stats-filter-1.13 created
envoyfilter.networking.istio.io/stats-filter-1.14 created
envoyfilter.networking.istio.io/stats-filter-1.15 created
envoyfilter.networking.istio.io/tcp-stats-filter-1.11 created
envoyfilter.networking.istio.io/tcp-stats-filter-1.12 created
envoyfilter.networking.istio.io/tcp-stats-filter-1.13 created
envoyfilter.networking.istio.io/tcp-stats-filter-1.14 created
envoyfilter.networking.istio.io/tcp-stats-filter-1.15 created
root@k8s-master:~/knative# kubectl apply -f net-istio.yaml
clusterrole.rbac.authorization.k8s.io/knative-serving-istio created
gateway.networking.istio.io/knative-ingress-gateway created
gateway.networking.istio.io/knative-local-gateway created
service/knative-local-gateway created
configmap/config-istio created
peerauthentication.security.istio.io/webhook created
peerauthentication.security.istio.io/domainmapping-webhook created
peerauthentication.security.istio.io/net-istio-webhook created
deployment.apps/net-istio-controller created
deployment.apps/net-istio-webhook created
secret/net-istio-webhook-certs created
service/net-istio-webhook created
mutatingwebhookconfiguration.admissionregistration.k8s.io/webhook.istio.networking.internal.knative.dev created
validatingwebhookconfiguration.admissionregistration.k8s.io/config.webhook.istio.networking.internal.knative.dev created
操作后,检查资源情况如下:
text
^Croot@k8s-master:~/knative# kubectl -n knative-serving get pod
NAME READY STATUS RESTARTS AGE
activator-84cbcd7bd-njnpt 1/1 Running 0 51m
autoscaler-75965477fd-vd5rf 1/1 Running 0 51m
controller-76dd96d457-mw6rz 1/1 Running 0 51m
domain-mapping-ccdcfcd89-d6v9v 1/1 Running 0 51m
domainmapping-webhook-79f6f4f9d6-xgxzq 1/1 Running 0 51m
net-istio-controller-6899897874-nkfss 1/1 Running 0 5m11s
net-istio-webhook-7679886d7-97dbh 1/1 Running 0 5m11s
webhook-5448865f65-km9ps 1/1 Running 0 40m
root@k8s-master:~/knative# kubectl -n istio-system get pod
NAME READY STATUS RESTARTS AGE
istio-egressgateway-579dc4df64-dtwms 1/1 Running 0 36h
istio-ingressgateway-6849fc894d-759lj 1/1 Running 0 28m
istio-ingressgateway-6849fc894d-c95np 1/1 Running 0 28m
istio-ingressgateway-6849fc894d-rfpzx 1/1 Running 0 28m
istiod-9c5b49645-2jp49 1/1 Running 0 28m
istiod-9c5b49645-vjghz 0/1 Pending 0 27m
模拟向网关发送请求
bash
# header 参考 https://github.com/knative/serving/blob/v0.46.5/pkg/activator/activator.go#L30# kubectl -n kourier-system get pod -o wide 获取 ipcurl -H "Knative-Serving-Revision: xxx-00001" -H "Knative-Serving-Namespace: xxx" ip:8012
apiVersion:v1kind:ConfigMapmetadata:name:config-deploymentnamespace:knative-servinglabels:serving.knative.dev/release:develannotations:knative.dev/example-checksum:"fa67b403"data:# This is the Go import path for the binary that is containerized# and substituted here.queue-sidecar-image:ko://knative.dev/serving/cmd/queue# List of repositories for which tag to digest resolving should be skippedregistries-skipping-tag-resolving:"kind.local,ko.local,dev.local"# digest-resolution-timeout is the maximum time allowed for an image's# digests to be resolved.digest-resolution-timeout:"10s"# progress-deadline is the duration we wait for the deployment to# be ready before considering it failed.progress-deadline:"600s"# queue-sidecar-cpu-request is the requests.cpu to set for the queue proxy sidecar container.# If omitted, a default value (currently "25m"), is used.queue-sidecar-cpu-request:"25m"# queue-sidecar-cpu-limit is the limits.cpu to set for the queue proxy sidecar container.# If omitted, no value is specified and the system default is used.queue-sidecar-cpu-limit:"1000m"# queue-sidecar-memory-request is the requests.memory to set for the queue proxy container.# If omitted, no value is specified and the system default is used.queue-sidecar-memory-request:"400Mi"# queue-sidecar-memory-limit is the limits.memory to set for the queue proxy container.# If omitted, no value is specified and the system default is used.queue-sidecar-memory-limit:"800Mi"# queue-sidecar-ephemeral-storage-request is the requests.ephemeral-storage to# set for the queue proxy sidecar container.# If omitted, no value is specified and the system default is used.queue-sidecar-ephemeral-storage-request:"512Mi"# queue-sidecar-ephemeral-storage-limit is the limits.ephemeral-storage to set# for the queue proxy sidecar container.# If omitted, no value is specified and the system default is used.queue-sidecar-ephemeral-storage-limit:"1024Mi"
Knative may default this to secure in a future release
错误日志
text
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
解决这个警告的最佳方式是显式地在你的 Knative Service YAML 中设置这些 securityContext 字段,使其符合更安全的实践。