【发布时间】:2021-12-06 06:10:33
【问题描述】:
我已经成功部署了一个 kubernetes 服务。最重要的是,我创建了一个 k8s 入口控制器,它映射到端口 80 上已部署的服务,并且路径只是带有前斜杠( / )。例如ingress 的主机名是 kubernetes-app.local,url 是 http://kubernetes-app.local:80 或 http://kubernetes-app.local。但是,两天后突然我无法获得相同网址的成功响应。入口和服务没有任何变化,而且我可以看到入口和服务正在成功运行。 不知道发生了什么,突然我开始收到错误,因为“没有与这些值匹配的路由”。我重新部署了应用程序,但仍然面临同样的问题。问题。 任何线索都会有所帮助。
以下是供您参考的信息
$ kubectl 版本
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"SOME_STRING", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.5+k3s2", GitCommit:"SOME_STRING", GitTreeState:"clean", BuildDate:"2021-10-05T19:59:14Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
service.yaml
apiVersion: v1
kind: Service # Specify the type of manifest this is. In this case a service, which is used to allow network access to pods.
metadata:
labels:
app: kubernetes-app-service
name: kubernetes-app-service
namespace: my-app-plus # Specify the name of the namespace to run this object under.
spec:
type: ClusterIP # Type of Service. Options are ClusterIP or NodePort
clusterIP: None # Specify an IP for the service. None means K8S will auto assign an IP.
selector:
app: kubernetes-app-pod # Traffic to this service will be routed to pod(s) with this label.
sessionAffinity: None
ports:
- name: default
port: 80 # Port the service will be listening on
protocol: TCP
targetPort: 80 # Port that pod(s) will be listening on
deployment.yaml
apiVersion: apps/v1
kind: Deployment # Specify the type of manifest this is. In this case a deployment, which is used to get and keep pods running.
metadata:
labels:
app: kubernetes-app
name: kubernetes-app
namespace: my-app-plus # Specify the name of the namespace to run this object under.
spec:
replicas: 1 # Specify how many copies of the pods we want running.
selector:
matchLabels:
app: kubernetes-app-pod # Pods matching this label are part of this deployment
strategy: # Specify the rules for updating or replacing pods.
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
template: # Here is where we will define the pods that the deployment will use.
metadata:
labels:
app: kubernetes-app-pod # Set the label of the pod. This is what the deployment selector up above is referencing. Services will also reference this.
annotations:
dapr.io/enabled: "true"
dapr.io/app-id: "kubernetes-app"
dapr.io/app-port: "80"
dapr.io/config: "tracing"
spec:
containers: # Specify how the container(s) in this pod are created.
- name: kubernetes-app
image: ghcr.io/myuseridORorgName/app:1.1.0 # Docker image to create the container from.
imagePullPolicy: Always
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "1000Mi"
cpu: "1000m"
volumeMounts:
- name: kubernetes-app-git-volume
mountPath: /root/.gitconfig # Creating the .gitconfig from the configmap we created earlier
subPath: .gitconfig
env:
- name: dev
value: "true"
envFrom:
- configMapRef:
name: kubernetes-app-configmap
- secretRef:
name: kubernetes-app-secret
imagePullSecrets:
- name: mysecrethub
volumes:
- name: kubernetes-app-git-volume
configMap:
name: gitconfig
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-app-ingress
namespace: my-app-plus # Specify the name of the namespace to run this object under.
spec:
rules:
- host: kubernetes-app.local # Traffic arriving at the load balancer to this Domain Name will get routed according to this ingress spec.
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: kubernetes-app-service # Traffic will be sent to a service with this label.
port:
number: 80 # Port on the service to route traffic to.
【问题讨论】:
-
请更新您的问题并提供更多详细信息:您是如何安装 kubernetes 的?使用什么? (例如启用了 k8s 或 microk8s 的 minikube 或 docker desktop 等)。来自集群的日志/事件?你到底在哪里看到这个错误?入口清单和
kubectl describe输出。因此,应该提供更多详细信息,以便社区可以尝试帮助您。 -
@moonkotte 更新了问题
-
Manifests 看起来不错 + 他们以前工作过。因此,潜在的问题。你是如何安装你的 Kubernetes 集群的?请提供更多详细信息,以便重现环境。你到底在哪里看到这个错误?您也可以尝试使用
NodePort或LoadBalancer类型公开您的服务,以查看该应用是否真正有效。