我正在运行一个 kubernetes 集群,并且有一个在 TestPort(实际上是 3000)上运行的 TestApplication。我设法启动并运行了 Traefik v3.2.1,并使用 http 质询启动并运行了 CertManager 1.16.1 以进行 letsencrypt。我想保护 TestApplication,让人们通过 TraefiK 端口 443 并进入 TestApplication:TestPort。如何为我的应用程序创建适当的 Ingress 资源?到目前为止,我做到了:
#001-app-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f compose.yml
kompose.version: 1.34.0 (HEAD)
labels:
io.kompose.service: app-frontend
name: app-frontend
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: app-frontend
template:
metadata:
annotations:
kompose.cmd: kompose convert -f compose.yml
kompose.version: 1.34.0 (HEAD)
labels:
io.kompose.service: app-frontend
spec:
containers:
- env:
- name: API_GATEWAY_BASE_URL
value: http://edge-thinghy:9000
image: my-image-I-test
name: app-frontend
ports:
- name: app-frontend
containerPort: 3000
protocol: TCP
imagePullSecrets:
- name: ghcr-secret
restartPolicy: Always
#010-app-service.yml
apiVersion: v1
kind: Service
metadata:
name: app-frontend
spec:
ports:
- name: app-frontend
port: 80
targetPort: 3000
selector:
app: app-frontend
#011-app-ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-frontend
port:
name: app-frontend
#012-challenge.yml
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: app-challenge
namespace: default
spec:
acme:
email: [email protected]
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: app-issuer-account-key
solvers:
- http01:
ingress:
class: traefik
#013-ingress-rule.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ssl-ingress
namespace: default
annotations:
cert-manager.io/issuer: "app-challenge"
spec:
tls:
- hosts:
- app.domain.example
secretName: tls-app-ingress-http
rules:
- host: app.domain.example
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-frontend
port:
name: app-frontend
由于证书已颁发,我原本希望 Traefik 能够自动工作,但当我转到https://app.domain.example时却超时了。我想我做错了什么。如果我打开 traefik pod 日志,我可以看到:
ERR Skipping service: no endpoints found ingress=app-ingress namespace=default providerName=kubernetes serviceName=app-frontend servicePort=&ServiceBackendPort{Name:app-frontend,Number:0,}
ERR Skipping service: no endpoints found ingress=app-ssl-ingress namespace=default providerName=kubernetes serviceName=app-frontend servicePort=&ServiceBackendPort{Name:app-frontend,Number:0,}
尽管我可以访问http://app.domain.example,但不能访问 https,如果我这样做
kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS
app-ingress traefik * 80
app-ssl-ingress traefik app.domain.example 80, 443
看起来你忘记了部署清单
这里是例子: