由于我想学习使用 kubernetes 部署软件,所以我安装了一个单节点 k3s 集群(ip:192.168.178.10)curl -sfL https://get.k3s.io | sh -
。现在我按照本教程建立了两个服务并将它们暴露给外部。但是当我尝试curl 192.168.178.10/apple
响应时,Bad Gateway
我认为它与 k3s traefik ingeress 有关,但我无法找到问题所在。
服务
kind: Pod
apiVersion: v1
metadata:
name: banana-app
labels:
app: banana
spec:
containers:
- name: banana-app
image: hashicorp/http-echo
args:
- "-text=banana"
---
kind: Service
apiVersion: v1
metadata:
name: banana-service
spec:
selector:
app: banana
ports:
- port: 5678 # Default port for image
kind: Pod
apiVersion: v1
metadata:
name: apple-app
labels:
app: apple
spec:
containers:
- name: apple-app
image: hashicorp/http-echo
args:
- "-text=apple"
---
kind: Service
apiVersion: v1
metadata:
name: apple-service
spec:
selector:
app: apple
ports:
- port: 5678 # Default port for image
入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /apple
backend:
serviceName: apple-service
servicePort: 5678
- path: /banana
backend:
serviceName: banana-service
servicePort: 5678
编辑:
kubectl describe ingress example-ingress
显示以下规则:
Rules:
Host Path Backends
---- ---- --------
*
/apple apple-service:5678 (10.42.0.68:5678)
/banana banana-service:5678 (10.42.0.67:5678)
而这些是苹果和香蕉的服务:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
apple-service ClusterIP 10.43.61.250 <none> 5678/TCP 101m
banana-service ClusterIP 10.43.67.205 <none> 5678/TCP 100m
ip不匹配对我来说似乎是个问题。
输出kubectl describe svc
:
Name: kubernetes
Namespace: default
Labels: component=apiserver
provider=kubernetes
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP: 10.43.0.1
Port: https 443/TCP
TargetPort: 6443/TCP
Endpoints: 192.168.178.10:6443
Session Affinity: None
Events: <none>
Name: banana-service
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"banana-service","namespace":"default"},"spec":{"ports":[{"port":5...
Selector: app=banana
Type: ClusterIP
IP: 10.43.124.19
Port: <unset> 5678/TCP
TargetPort: 5678/TCP
Endpoints: 10.42.0.76:5678
Session Affinity: None
Events: <none>
Name: apple-service
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"apple-service","namespace":"default"},"spec":{"ports":[{"port":56...
Selector: app=apple
Type: ClusterIP
IP: 10.43.9.134
Port: <unset> 5678/TCP
TargetPort: 5678/TCP
Endpoints: 10.42.0.77:5678
Session Affinity: None
Events: <none>