您可以部署配置为使用主机网络和端口 80/443 的 Ingress。
-
您的集群的 DO 防火墙默认没有打开 80/443 入站。
如果您编辑自动创建的防火墙规则will eventually reset themselves。解决方案是创建一个单独的防火墙,也指向相同的 Kubernetes 工作节点:
$ doctl compute firewall create \
--inbound-rules="protocol:tcp,ports:80,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:443,address:0.0.0.0/0,address:::/0" \
--tag-names=k8s:CLUSTER_UUID \
--name=k8s-extra-mycluster
(从仪表板获取CLUSTER_UUID 值或从doctl kubernetes cluster list 获取ID 列)
- 使用主机网络创建nginx ingress。我在下面包含了helm chart 配置,但您也可以通过直接安装过程来完成。
编辑:上面链接中的 Helm 图表已被弃用,因此安装图表的正确方法是(as per the new docs):
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
添加和更新此 repo 后
# For Helm 2
$ helm install stable/nginx-ingress --name=myingress -f myingress.values.yml
# For Helm 3
$ helm install myingress stable/nginx-ingress -f myingress.values.yml
#EDIT: The New way to install in helm 3
helm install myingress ingress-nginx/ingress-nginx -f myingress.values.yaml
myingress.values.yml 用于图表:
---
controller:
kind: DaemonSet
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
daemonset:
useHostPort: true
service:
type: ClusterIP
rbac:
create: true
-
您应该能够通过任何工作程序节点 IP 访问 :80 和 :443 上的集群,它将流量路由到您的入口。
-
由于节点 IP 可以并且确实可以更改,因此请考虑部署 external-dns 来管理 DNS 条目以指向您的工作节点。同样,使用掌舵图并假设您的 DNS 域由 DigitalOcean 托管(尽管任何受支持的 DNS 提供商都可以使用):
# For Helm 2
$ helm install --name=mydns -f mydns.values.yml stable/external-dns
# For Helm 3
$ helm install mydns stable/external-dns -f mydns.values.yml
mydns.values.yml 用于图表:
---
provider: digitalocean
digitalocean:
# create the API token at https://cloud.digitalocean.com/account/api/tokens
# needs read + write
apiToken: "DIGITALOCEAN_API_TOKEN"
domainFilters:
# domains you want external-dns to be able to edit
- example.com
rbac:
create: true
- 创建一个 Kubernetes Ingress resource 将请求路由到现有的 Kubernetes 服务:
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: testing123-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: testing123.example.com # the domain you want associated
http:
paths:
- path: /
backend:
serviceName: testing123-service # existing service
servicePort: 8000 # existing service port
- 大约一分钟后,您应该会看到 DNS 记录出现并且可以解析:
$ dig testing123.example.com # should return worker IP address
$ curl -v http://testing123.example.com # should send the request through the Ingress to your backend service
(编辑:编辑自动创建的防火墙规则最终会中断,改为添加单独的防火墙)。