我是traefik和k3s的新手,我想象它很成熟所以我可以轻松安装它没有问题。但我很挣扎。我用 traefik 安装了 k3s,从我到目前为止阅读/谷歌搜索的内容来看,在添加服务+部署+入口之后,它应该可以正常工作。但它不会:皱眉: 我一定是遗漏了一些基本的东西,希望你能指出我的问题或链接一些我遗漏的教程/文档。
所以用traefik(默认)安装k3s后,有这个部署版本:
rancher/mirrored-library-traefik:2.9.4
.
我有一个 django 应用程序,其服务如下所示:
apiVersion: v1
kind: Service
metadata:
name: web-sandbox-service
spec:
type: ClusterIP
selector:
name: web-sandbox
ports:
- protocol: TCP
port: 8000
targetPort: 80
name: HTTP
部署看起来像这样:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-sandbox
labels:
app: web-sandbox
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0%
progressDeadlineSeconds: 120
selector:
matchLabels:
app: web-sandbox
template:
metadata:
labels:
app: web-sandbox
spec:
containers:
- image: registry.gitlab.com/lucas03/digrin-sandbox:commit
name: web-sandbox
envFrom:
- secretRef:
name: digrin-sandbox-secret
command: ['/bin/sh', 'extras/docker-entrypoint.sh']
ports:
- containerPort: 8000
name: gunicorn
livenessProbe:
httpGet:
path: /robots.txt
port: 8000
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 9
readinessProbe:
httpGet:
path: /robots.txt
port: 8000
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 2
failureThreshold: 5
timeoutSeconds: 2
imagePullSecrets:
- name: registry-credentials
我相信 web-sandbox 正在运行,因为我没有看到错误,而且我看到带有 robots.txt 路径的日志被 healthcheck 命中。 我以为我只需要像这样添加一个入口对象,将我的子域指向服务器的 IP 后,它就会起作用:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web-sandbox-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/limit-rps: "5"
nginx.ingress.kubernetes.io/limit-rpm: "100"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
traefik.ingress.kubernetes.io/router.tls: "false"
kubernetes.io/ingress.class: "traefik"
spec:
ingressClassName: "traefik"
rules:
- host: sandbox.mydomain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-sandbox-service
port:
number: 80
当我点击 sandbox.mydomain.com 时,它会以
404 page not found
响应。我想用 curl 图像以某种方式调试它。但是,如果我想通过 pod IP/名称来访问,例如curl HTTPcurl http://10.43.108.170:8000/robots.txt
或 curl http://web-sandbox:8000/robots.txt
它只是回应:Couldn't connect to server