[英]Unable to access kubernates pods
I follow below steps to deploy my custom jar我按照以下步骤部署我的自定义 jar
1)- I created on docker image through the below docker file 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)- Deploy on kubernetes with the below deployment file 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)- Exposed as service with the below command 3)- 使用以下命令公开为服务
minikube tunnel
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service --port=8000 --target-port=8000
4)- Output of the kubectl describe svc my-service 4)- kubectl describe svc my-service 的 Output
<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 is in running state POD 正在运行 state
I m trying to access the pod using "10.96.142.93" as given in the http://10.96.142.93:8090 my loginservice is started on 8090 PORT, BUT i am unable to access pod plz help我正在尝试使用http://10.96.142.93:8090中给出的“10.96.142.93”访问 pod,我的登录服务在 8090 端口上启动,但我无法访问 pod 请帮助
Try to access on nodeport localhost:31284
and please use service type as NodePort
instead of LoadBalancer
because loadbalancer service type mostly used on cloud level.尝试在 nodeport
localhost:31284
上访问,请使用服务类型作为NodePort
而不是LoadBalancer
,因为负载均衡器服务类型主要用于云级别。
and Use Target-Port as same port you configured on pod definition yaml file.并将 Target-Port 用作您在 pod 定义 yaml 文件中配置的相同端口。
so your url should be http://10.96.142.93:8000
所以你的 url 应该是
http://10.96.142.93:8000
or another way you can be by using port-forward或者您可以使用端口转发的另一种方式
kubectl port-forward pod_name 80:8000
this will map pod port to localhost port kubectl port-forward pod_name 80:8000
这将 map pod 端口到 localhost 端口
Then access it on http://localhost:80
然后在
http://localhost:80
上访问它
The Kubernetes loadbalancer type service is provided only in places such as aws and gcp. Kubernetes负载均衡器类型服务只在aws、gcp等地方提供。 Use metallb for use in an on-premises environment.
使用 metallb 在本地环境中使用。
If not, try modifying the service type to Nodeport and accessing http://localhost:31284
如果没有,尝试修改服务类型为Nodeport并访问
http://localhost:31284
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.