# Setup domain, user and password first.
$ export USER=user
$ export DOMAIN=ingress.feisky.xyz
$ htpasswd -c auth $USER
New password:
Re-type new password:
Adding password for user user
$ PASSWORD=$(cat auth| awk -F: '{print $2}')
# Deploy with helm.
helm install stable/traefik --name --namespace kube-system --set rbac.enabled=true,acme.enabled=true,dashboard.enabled=true,acme.staging=false,acme.email=admin@$DOMAIN,dashboard.domain=ui.$DOMAIN,ssl.enabled=true,acme.challengeType=http-01,dashboard.auth.basic.$USER=$PASSWORD
稍等一会,traefik Pod 就会运行起来:
$ kubectl -n kube-system get pod -l app=traefik
NAME READY STATUS RESTARTS AGE
traefik-65d8dc4489-k97cg 1/1 Running 0 5m
$ kubectl -n kube-system get ingress
NAME HOSTS ADDRESS PORTS AGE
traefik-dashboard ui.ingress.feisky.xyz 80 25m
$ kubectl -n kube-system get svc traefik
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
traefik LoadBalancer 10.0.206.26 172.20.0.115 80:31662/TCP,443:32618/TCP 24m
根据你自己环境中部署的 service 名称和端口自行修改,有新 service 增加时,修改该文件后可以使用kubectl replace -f traefik.yaml来更新。
测试
在集群的任意一个节点上执行。假如现在我要访问nginx的"/"路径。
$ curl -H Host:traefik.nginx.io http://172.20.0.115/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>