ASK: Alibaba Cloud Serverless Kuberneteshtml
不一樣於阿里雲ACK集羣默認經過nginx-ingress-controller提供ingress能力,在ASK(Serverless Kubernetes)集羣中默認基於SLB七層轉發提供ingress能力(請參考文檔https://help.aliyun.com/document_detail/86398.html)。這樣的優點是Serverless集羣開箱即用,用戶無需部署任何controller便可建立本身的Ingress資源,更符合Serverless環境的用法。nginx
然而基於SLB七層轉發的ingress與nginx-ingress-controller相比,缺乏了一些高級Ingress功能,沒法知足某些客戶場景的需求,好比支持域名path的正則匹配等。git
因此ASK集羣也提供了與ACK集羣一樣的nginx-ingress-controller,供用戶使用nginx提供的ingress轉發能力。用戶能夠根據本身的需求決定選擇二者之一。下面咱們一塊兒來嘗試在ASK集羣中使用nginx-ingress。github
在ASK集羣中部署yaml文件:
https://github.com/AliyunContainerService/serverless-k8s-examples/blob/master/ingress-nginx/nginx-ingress-controller.yaml後端
#kubectl apply -f https://raw.githubusercontent.com/AliyunContainerService/serverless-k8s-examples/master/ingress-nginx/nginx-ingress-controller.yaml service/nginx-ingress-lb created configmap/nginx-configuration created configmap/tcp-services created configmap/udp-services created serviceaccount/nginx-ingress-controller created clusterrole.rbac.authorization.k8s.io/nginx-ingress-controller created clusterrolebinding.rbac.authorization.k8s.io/nginx-ingress-controller created deployment.apps/nginx-ingress-controller created # kubectl -n kube-system get pod NAME READY STATUS RESTARTS AGE nginx-ingress-controller-c9d8697f6-n4bzs 0/1 Running 0 52s nginx-ingress-controller-c9d8697f6-p8p6j 0/1 Running 0 52s # kubectl -n kube-system get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE metrics-server ClusterIP 172.19.4.171 <none> 443/TCP 72d nginx-ingress-lb LoadBalancer 172.19.6.118 47.93.131.72 80:32676/TCP,443:30256/TCP 116s
能夠看到一個公網slb已經被建立出來(後端是兩個nginx-ingress-controller pod),這是集羣中全部ingress的入口IP地址。app
咱們一樣提供了簡單的Coffee和Tea Ingress示例:https://github.com/AliyunContainerService/serverless-k8s-examples/blob/master/ingress-nginx/ingress-cafe-demo.yamlless
須要注意的是Ingress中須要指定以下Annotation,才能保證ingress被nginx-ingress-controller正確處理。
kubernetes.io/ingress.class:nginxcurl
# kubectl apply -f https://raw.githubusercontent.com/AliyunContainerService/serverless-k8s-examples/master/ingress-nginx/ingress-cafe-demo.yamldeployment.extensions/coffee created service/coffee-svc created deployment.extensions/tea created service/tea-svc created ingress.extensions/cafe-ingress created # kubectl get pod NAME READY STATUS RESTARTS AGE coffee-56668d6f78-g7g6p 1/1 Running 0 88s coffee-56668d6f78-x9ktc 1/1 Running 0 88s tea-85f8bf86fd-477d2 1/1 Running 0 88s tea-85f8bf86fd-jlq6b 1/1 Running 0 88s tea-85f8bf86fd-p4ng4 1/1 Running 0 88s # kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE coffee-svc ClusterIP None <none> 80/TCP 102s kubernetes ClusterIP 172.19.0.1 <none> 443/TCP 72d tea-svc ClusterIP None <none> 80/TCP 102s # kubectl get ing NAME HOSTS ADDRESS PORTS AGE cafe-ingress cafe.example.com 47.93.131.72 80 2m1s
pod和ingress都已建立成功,下面咱們嘗試訪問Ingress:tcp
# curl -H "Host:cafe.example.com" 47.93.131.72/tea Server address: 192.168.55.159:80 Server name: default-tea-85f8bf86fd-p4ng4 Date: 14/Nov/2019:09:01:46 +0000 URI: /tea Request ID: 2c3a87eb89130d62664b640fcbabc74b # curl -H "Host:cafe.example.com" 47.93.131.72/coffee Server address: 192.168.55.156:80 Server name: default-coffee-56668d6f78-x9ktc Date: 14/Nov/2019:09:01:49 +0000 URI: /coffee Request ID: a4f1d84bb5288a260ecfc5d21ecccff6
Ingress鏈路訪問成功,能夠看到上述域名轉發由nginx ingress controller完成。阿里雲
當運行上述示例成功後,記得清理集羣中的ingress:
kubectl delete -f https://raw.githubusercontent.com/AliyunContainerService/serverless-k8s-examples/master/ingress-nginx/ingress-cafe-demo.yaml
更多ASK集羣示例請參考:https://github.com/AliyunContainerService/serverless-k8s-examples
本文爲雲棲社區原創內容,未經容許不得轉載。