无法访问 kubernates pods

Unable to access kubernates pods

我按照以下步骤部署我的自定义 jar

1)- 我通过下面的 docker 文件

在 docker 图像上创建了
FROM openjdk:8-jre-alpine3.9
LABEL MAINTAINER DINESH
LABEL version="1.0"
LABEL description="First image with Dockerfile & DINESH."
RUN mkdir  /app
COPY LoginService-0.0.1-SNAPSHOT.jar /app
WORKDIR /app
CMD ["java", "-jar", "LoginService-0.0.1-SNAPSHOT.jar"]

2)- 使用以下部署文件在 kubernetes 上部署

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: load-balancer-example
  name: hello-world
spec:
  replicas: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: load-balancer-example
  template:
    metadata:
      labels:
        app.kubernetes.io/name: load-balancer-example
    spec:
      containers:
      - image: localhost:5000/my-image:latest
        name: hello-world
        ports:
        - containerPort: 8000

3)- 使用以下命令公开为服务

minikube tunnel
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service --port=8000 --target-port=8000 

4)- kubectl 的输出描述 svc my-service

<strong>
Name:                     my-service<br> 
Namespace:                default<br> 
Labels:                   app.kubernetes.io/name=load-balancer-example<br> 
Annotations:              <none><br> 
Selector:                 app.kubernetes.io/name=load-balancer-example<br> 
Type:                     LoadBalancer<br> 
IP:                       10.96.142.93<br> 
LoadBalancer Ingress:     10.96.142.93<br> 
Port:                     <unset>  8000/TCP<br> 
TargetPort:               8000/TCP<br> 
NodePort:                 <unset>  31284/TCP<br> 
Endpoints:                172.18.0.7:8000,172.18.0.8:8000<br> 
Session Affinity:         None<br> 
External Traffic Policy:  Cluster<br> 
Events:                   <none><br> </strong>


POD 处于 运行 状态

我正在尝试使用 http://10.96.142.93:8090 中给出的“10.96.142.93”访问 pod 我的登录服务是在 8090 端口上启动的,但是我无法访问 pod 请求助

尝试在节点端口 localhost:31284 上访问,请使用 NodePort 而不是 LoadBalancer 的服务类型,因为负载均衡器服务类型主要用于云级别。

并使用 Target-Port 作为您在 pod 定义 yaml 文件中配置的相同端口。

所以你的 url 应该是 http://10.96.142.93:8000

或者您可以使用 port-forward

的另一种方式

kubectl port-forward pod_name 80:8000 这会将 pod 端口映射到本地主机端口

然后在 http://localhost:80

上访问它

Kubernetes loadbalancer类型的服务只在aws、gcp等地方提供。在 on-premises 环境中使用 metallb。

如果不行,尝试修改服务类型为Nodeport并接入http://localhost:31284