环境要求
安装步骤
以YAML文件进行Serving部署
参考官方文档:https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/
部署serving的crd:
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-crds.yaml
部署serving核心组件
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-core.yaml
安装 a networking layer(这里以istio为例)
kubectl apply -l knative.dev/crd-install=true -f https://github.com/knative/net-istio/releases/download/knative-v1.12.0/istio.yaml
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.12.0/istio.yaml
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.12.0/net-istio.yaml
kubectl --namespace istio-system get service istio-ingressgateway
配置DNS,因为我们是测试环境,所以选择"no dns",来配置,可以从集群外部访问的域名
kubectl patch configmap/config-domain \
--namespace knative-serving \
--type merge \
--patch '{"data":{"example.com":""}}'
安装HPA控制器
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.12.0/serving-hpa.yaml
安装kn
wget https://github.com/knative/client/releases/download/knative-v1.11.2/kn-linux-amd64
cp kn-linux-amd64 /usr/local/bin/kn
chmod +x /usr/local/bin/kn
确认下载成功
root@k-master01:~# kubectl get pods -n knative-serving
NAME READY STATUS RESTARTS AGE
activator-58b9474547-7nnh6 1/1 Running 0 18m
autoscaler-c88f8c8dc-zfvjv 1/1 Running 0 18m
autoscaler-hpa-5877fb58d6-84m5j 1/1 Running 0 64s
controller-84cd85bcc-wg9q8 1/1 Running 0 18m
net-istio-controller-79f97565f4-dc6m8 1/1 Running 0 2m34s
net-istio-webhook-f7c89b4fd-jwcqs 1/1 Running 0 2m34s
webhook-6bbbc5867c-dw7vs 1/1 Running 0 18m
root@k-master01:~# kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
istio-ingressgateway-584c594ff8-2f8mg 1/1 Running 0 5m2s
istio-ingressgateway-584c594ff8-7clr9 1/1 Running 0 5m2s
istio-ingressgateway-584c594ff8-w7tq5 1/1 Running 0 5m2s
istiod-78c4f7f756-kv4mh 1/1 Running 0 5m2s
istiod-78c4f7f756-kxbjw 1/1 Running 0 4m47s
istiod-78c4f7f756-pldrm 1/1 Running 0 4m47s
暴露istio-ingressgateway
给node01上邦一个ip地址:
ip addr add 192.168.58.100/24 dev ens33
kubectl edit svc istio-ingressgateway -n istio-system
运行一个demo的service
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: hello
spec:
template:
metadata:
# This is the name of our new "Revision," it must follow the convention {service-name}-{revision-name}
name: hello-world
spec:
containers:
#- image: gcr.io/knative-samples/helloworld-go
- image: ikubernetes/helloworld-go
ports:
- containerPort: 8080
env:
- name: TARGET
value: "World"
测试请求
kubectl get ksvc
本机测试:
curl -H "Host: hello.default.example.com" 192.168.58.100
Hello World!