我有 2 个服务(1 -- httpd + php,2 -- go gin)。它们的配置相同。问题是我只能从外部连接到其中一个,而第二个会抛出错误,但如果我从集群内部连接,则一切正常。我通过 helm 部署它们,每个服务使用 1 个基本图表。
IP地址
192.168.49.1 -- abc. 端口:9999 192.168.49.2 -- my-k8s-app. 端口:80
错误
curl: (7) Failed to connect to 192.168.49.1 port 9999 after 0 ms: Couldn't connect to server
值.yaml
abc:
image: regretto/gateway:latest
port: 9999
service:
type: LoadBalancer
externalPort: 9999
my-k8s-app:
image: regretto/myk8sapp:latest
port: 80
service:
type: LoadBalancer
externalPort: 8080
服务.yml
apiVersion: v1
kind: Service
metadata:
name: "{{ .Chart.Name | lower | replace "_" "-"}}"
labels:
proj: "{{ .Release.Name }}"
slave_microservice: "{{ .Chart.Name | lower | replace "_" "-" }}"
spec:
type: {{default "ClusterIP" .Values.service.type}}
ports:
- port: {{ .Values.port }}
NodePort: {{ default .Values.port .Values.service.externalPort }}
protocol: {{default "TCP" .Values.service.protocol}}
selector:
app: {{.Chart.Name | lower | replace "_" "-"}}
部署.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ .Chart.Name | lower | replace "_" "-"}}"
labels:
proj: "{{ .Release.Name | lower}}"
app: {{ .Chart.Name | lower | replace "_" "-" }}
spec:
replicas: {{ .Values.hpa.minReplicas }}
selector:
matchLabels:
proj: "{{ .Release.Name | lower}}"
template:
metadata:
labels:
proj: "{{ .Release.Name | lower }}"
app: "{{ .Chart.Name | lower | replace "_" "-"}}"
spec:
containers:
- name: {{ .Chart.Name | lower | replace "_" "-"}}
image: {{ tpl .Values.image . }}
imagePullPolicy: {{ default "Always" .Values.pull_policy }}
ports:
- containerPort: {{ .Values.port }}
args: {{ toYaml .Values.args | nindent 12}}
答案1
看起来您正在创建 LoadBalancer 类型的服务。在这种情况下,kubectl get services -n <your namespace>
还应该在字段中给您一个值EXTERNAL-IP
。您应该使用它从外部访问您的服务。
kubectl get svc,ep -n <your namespace>
您能提供该命令的结果吗?