- Knative 安装
- 安装 Istio
- 验证 Istio 安装
- 安装 Knative
- 验证 Knative 安装
- 参考
- 安装 Istio
Knative 安装
我们在已有的 Kubernetes 集群上安装 Knative,因为 Knative 依赖 Istio,首先我们需要先安装 Istio。
安装 Istio
我们安装的 Istio 的基本情况:
- Kubernetes 1.15
- Istio v1.1.7
- 启动 Sidecar 自动注入
- 使用 Helm 安装
- 不启用 SDS
[info] 提示
截止本文发稿时 Istio 已发布 v1.3,但是为了保持兼容性,本文中仍使用 Istio v1.1.7,以保持与 Knative 官方要求的版本统一。
运行以下命令安装 Istio。
# Knative v0.9 在 Istio v1.1.7 验证过export ISTIO_VERSION=1.1.7curl -L https://git.io/getLatestIstio | sh -cd istio-${ISTIO_VERSION}# 安装 Istio CRDfor i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done# 创建 istio-system namespacecat <<EOF | kubectl apply -f -apiVersion: v1kind: Namespacemetadata:name: istio-systemlabels:istio-injection: disabledEOF# 启用 sidecar 注入的模板helm template --namespace=istio-system \--set sidecarInjectorWebhook.enabled=true \--set sidecarInjectorWebhook.enableNamespacesByDefault=true \--set global.proxy.autoInject=disabled \--set global.disablePolicyChecks=true \--set prometheus.enabled=false \`# 禁用 mixer prometheus adapter,删除 istio 默认的 metrics` \--set mixer.adapters.prometheus.enabled=false \`# 禁用 mixer policy check,我们的模板里不使用 policy` \--set global.disablePolicyChecks=true \`# 将 gateway pod 设置为 1 以规避最终一致性/readiness 问题` \--set gateways.istio-ingressgateway.autoscaleMin=1 \--set gateways.istio-ingressgateway.autoscaleMax=1 \--set gateways.istio-ingressgateway.resources.requests.cpu=500m \--set gateways.istio-ingressgateway.resources.requests.memory=256Mi \`# 多个 pilot replica 便于伸缩` \--set pilot.autoscaleMin=2 \`# 将 pilot 追踪采样设置为 100%` \--set pilot.traceSampling=100 \install/kubernetes/helm/istio \> ./istio.yaml# 部署 istiokubectl apply -f istio.yaml
使用 Helm 渲染完成的 istio.yaml 文件已保存在 manifests/istio/v1.17/istio.yaml 文件中,以后每次可以直接使用该文件执行安装和卸载 Istio。
验证 Istio 安装
执行下面的命令验证 Istio 的安装是否正确。
首先检查 Istio 的 pod 是否完全启动。
$ kubectl get pods --namespace istio-systemNAME READY STATUS RESTARTS AGEistio-citadel-8559955d59-j5xx9 1/1 Running 0 40mistio-cleanup-secrets-1.1.7-rb9hp 0/1 Completed 0 40mistio-galley-fd84c8888-8kljq 1/1 Running 0 40mistio-ingressgateway-8486b5db4f-hhqfg 1/1 Running 0 40mistio-pilot-7846986bf5-5ql82 2/2 Running 0 40mistio-pilot-7846986bf5-xgqhk 2/2 Running 0 40mistio-policy-f7f8c578b-7rz2j 2/2 Running 2 40mistio-security-post-install-1.1.7-nqm9z 0/1 Completed 0 40mistio-sidecar-injector-c645cf64-8hfzg 1/1 Running 0 40mistio-telemetry-575c8d8d66-pb27q 2/2 Running 3 40m
部署 bookinfo 示例应用确认 Istio 所有组件可以正常工作。
kubectl -n default apply -f manifests/istio/bookinfo-sample
参考 Bookinfo Application 确认可以正常访问 productpage 页面。
安装 Knative
我们安装的 Istio 的基本情况:
- Knative v0.9.0
运行下面的命令直接安装 Knative。
# 安装 Knative CRDkubectl apply --selector knative.dev/crd-install=true \--filename https://github.com/knative/serving/releases/download/v0.9.0/serving.yaml \--filename https://github.com/knative/eventing/releases/download/v0.9.0/release.yaml \--filename https://github.com/knative/serving/releases/download/v0.9.0/monitoring.yaml# 再运行一遍 kubectl applykubectl apply --filename https://github.com/knative/serving/releases/download/v0.9.0/serving.yaml \--filename https://github.com/knative/eventing/releases/download/v0.9.0/release.yaml \--filename https://github.com/knative/serving/releases/download/v0.9.0/monitoring.yaml
或者使用本书中提供的 YAML 直接安装。
kubectl apply --selector knative.dev/crd-install=true -f manifests/knative/0.9kubectl apply -f manifests/knative/v0.9.0
[info] 提示
因为
quay.io、gcr.io、k8s.gcr.io、docker.elastic.co等镜像仓库在中国大陆无法访问,位于中国大陆的用户可以使用本书仓库中的manifests/knative/0.9目录下的 YAML 文件安装,其中以上镜像已替换为 DockerHub 镜像源。
验证 Knative 安装
运行下面的命令验证 Knative 所有 pod 是否可以正常启动。
$ kubectl get pods --namespace knative-serving$ kubectl get pods --namespace knative-eventing$ kubectl get pods --namespace knative-monitoringNAME READY STATUS RESTARTS AGEactivator-76f486c78-9k7l7 2/2 Running 3 34mautoscaler-7495bcbc4b-j58n5 2/2 Running 2 34mautoscaler-hpa-66b55c9688-w2x58 1/1 Running 0 34mcontroller-859b7dbb8f-pdwfp 1/1 Running 0 34mnetworking-istio-dc5f9b9f8-8qxfh 1/1 Running 0 34mwebhook-8dcd46846-kz78d 1/1 Running 0 34mNAME READY STATUS RESTARTS AGEeventing-controller-8466765fbf-djs8v 1/1 Running 0 34meventing-webhook-684467d8f5-klb7s 1/1 Running 0 34mimc-controller-66dfdb6878-8mppw 1/1 Running 0 34mimc-dispatcher-7db65bf44b-kwwhs 1/1 Running 0 34msources-controller-75c57459cc-xttxr 1/1 Running 0 34mNAME READY STATUS RESTARTS AGEelasticsearch-logging-0 1/1 Running 0 12melasticsearch-logging-1 1/1 Running 0 11mgrafana-85c86fb7b9-8b95g 1/1 Running 0 34mkibana-logging-85569f954d-fc65f 1/1 Running 0 35mkube-state-metrics-6fd74d89bf-7kmk6 4/4 Running 0 30mnode-exporter-6z6nk 2/2 Running 0 34mnode-exporter-hm2gr 2/2 Running 0 34mnode-exporter-rhc7r 2/2 Running 0 34mprometheus-system-0 1/1 Running 0 34mprometheus-system-1 1/1 Running 0 34m
参考 Getting Started with App Deployment 部署 helloworld-go 示例验证 Knative 是否正常运行。
kubectl -n default apply -f manifests/knative/samples/helloworld-go/service.yaml
参考
- Installing Istio for Knative - knative.dev
- Installing Knative - knative.dev
- Performing a Custom Knative Installation - knative.dev
- Bookinfo Application - istio.io
