无法通过NodePort访问Kubernetes公开的服务-请求达到超时-我做错了什么



我知道这方面有很多问题。。。但直到现在我都找不到任何答案。我尝试了两个图像(Apache Solr和Neo4J(。尝试了不同的命名空间、clusterIP、edit/etc/hosts、ingress、tunnel、minikube-ip,但我的所有请求都没有得到响应。

我在Docker中单独尝试了这些图像,它们的答案很正确。。。使用localhost、127.0.0.1和我的以太网IP-在192.168.0.15的情况下。我猜这可能是一个内部配置(来自Sol、Neo4J(,只允许来自localhost的请求。。。但当他们从IP地址通过我在/etc/hosts中设置的自定义域回复呼叫时,我转向了kubernetes配置。

以下是以下步骤和环境:

1) MacOS 10.15 Catalina
2) minikube version: v1.24.0 - commit: 76b94fb3c4e8ac5062daf70d60cf03ddcc0a741b
3) Kubectl:
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:33:37Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:35:25Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
4) Docker:
Client:
Cloud integration: v1.0.22
Version:           20.10.11
API version:       1.41
Go version:        go1.16.10
Git commit:        dea9396
Built:             Thu Nov 18 00:36:09 2021
OS/Arch:           darwin/amd64
Context:           default
Experimental:      true
Server: Docker Engine - Community
Engine:
Version:          20.10.11
API version:      1.41 (minimum version 1.12)
Go version:       go1.16.9
Git commit:       847da18
Built:            Thu Nov 18 00:35:39 2021
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          1.4.12
GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version:          1.0.2
GitCommit:        v1.0.2-0-g52b36a2
docker-init:
Version:          0.19.0
GitCommit:        de40ad0
minikube start --mount --mount-string="/my/local/path:/analytics" --driver='docker'
kubectl apply -f neo4j-configmap.yaml
kubectl apply -f neo4j-secret.yaml
kubectl apply -f neo4j-volume.yaml
kubectl apply -f neo4j-volume-claim.yaml
kubectl apply -f neo4j.yaml
kubectl apply -f neo4j-service.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: neo4j-configmap
data:
neo4j-url: neo4j-service
---
apiVersion: v1
kind: Secret
metadata:
name: neo4j-secret
type: Opaque
data:
neo4j-user: bmVvNGoK
neo4j-password: bmVvNGoK
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: neo4j-volume
spec:
storageClassName: hostpath
capacity:
storage: 101Mi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/analytics/neo4j"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: neo4j-volume-claim
labels:
app: neo4j
spec:
storageClassName: hostpath
volumeMode: Filesystem
volumeName: neo4j-volume
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 101Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: neo4j-application
labels:
app: neo4j
spec:
replicas: 1
selector:
matchLabels:
app: neo4j
template:
metadata:
labels:
app: neo4j
spec:
volumes:
- name: neo4j-storage
persistentVolumeClaim:
claimName: neo4j-volume-claim
containers:
- name: neo4j
image: neo4j:4.1.4
ports:
- containerPort: 7474
name: neo4j-7474
- containerPort: 7687
name: neo4j-7687
volumeMounts:
- name: neo4j-storage
mountPath: "/data"
---
apiVersion: v1
kind: Service
metadata:
name: neo4j-service
spec:
type: NodePort
selector:
app: neo4j
ports:
- protocol: TCP
port: 7474
targetPort: neo4j-7474
nodePort: 30001
name: neo4j-port-7474
- protocol: TCP
port: 7687
targetPort: neo4j-7687
nodePort: 30002
name: neo4j-port-7687

bash步骤按该顺序执行。我把每个yaml配置都放在一个单独的文件中。我在这里加入他们只是为了揭露真相。

我缺少设置过程或配置过程的哪些部分?

以下是仅使用neo4j的kubectl describe all。我尝试了http,https请求从所有可能的IP。。。连接到每个吊舱并在吊舱内进行卷曲。。。并获得成功回复。

Name:         neo4j-application-7757948b98-2pxr2
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Sun, 09 Jan 2022 14:19:32 -0300
Labels:       app=neo4j
pod-template-hash=7757948b98
Annotations:  <none>
Status:       Running
IP:           172.17.0.4
IPs:
IP:           172.17.0.4
Controlled By:  ReplicaSet/neo4j-application-7757948b98
Containers:
neo4j:
Container ID:   docker://2deda46b3bb15712ff6dde5d2f3493c07b616c2eef3433dec6fe6f0cd6439c5f
Image:          neo4j:4.1.4
Image ID:       docker-pullable://neo4j@sha256:b1bc8a5c5136f4797dc553c114c0269537c85d3580e610a8e711faacb48eb774
Ports:          7474/TCP, 7687/TCP
Host Ports:     0/TCP, 0/TCP
State:          Running
Started:      Sun, 09 Jan 2022 14:19:43 -0300
Ready:          True
Restart Count:  0
Environment:    <none>
Mounts:
/data from neo4j-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-z5hq9 (ro)
Conditions:
Type              Status
Initialized       True 
Ready             True 
ContainersReady   True 
PodScheduled      True 
Volumes:
neo4j-storage:
Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName:  neo4j-volume-claim
ReadOnly:   false
kube-api-access-z5hq9:
Type:                    Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds:  3607
ConfigMapName:           kube-root-ca.crt
ConfigMapOptional:       <nil>
DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type     Reason            Age   From               Message
----     ------            ----  ----               -------
Warning  FailedScheduling  35m   default-scheduler  0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.
Normal   Scheduled         35m   default-scheduler  Successfully assigned default/neo4j-application-7757948b98-2pxr2 to minikube
Normal   Pulling           35m   kubelet            Pulling image "neo4j:4.1.4"
Normal   Pulled            35m   kubelet            Successfully pulled image "neo4j:4.1.4" in 3.087215911s
Normal   Created           34m   kubelet            Created container neo4j
Normal   Started           34m   kubelet            Started container neo4j

Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.96.0.1
IPs:               10.96.0.1
Port:              https  443/TCP
TargetPort:        8443/TCP
Endpoints:         192.168.49.2:8443
Session Affinity:  None
Events:            <none>

Name:                     neo4j-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=neo4j
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.98.131.77
IPs:                      10.98.131.77
Port:                     neo4j-port-7474  7474/TCP
TargetPort:               neo4j-7474/TCP
NodePort:                 neo4j-port-7474  30001/TCP
Endpoints:                172.17.0.4:7474
Port:                     neo4j-port-7687  7687/TCP
TargetPort:               neo4j-7687/TCP
NodePort:                 neo4j-port-7687  30002/TCP
Endpoints:                172.17.0.4:7687
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

Name:                   neo4j-application
Namespace:              default
CreationTimestamp:      Sun, 09 Jan 2022 14:19:27 -0300
Labels:                 app=neo4j
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=neo4j
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
Labels:  app=neo4j
Containers:
neo4j:
Image:        neo4j:4.1.4
Ports:        7474/TCP, 7687/TCP
Host Ports:   0/TCP, 0/TCP
Environment:  <none>
Mounts:
/data from neo4j-storage (rw)
Volumes:
neo4j-storage:
Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName:  neo4j-volume-claim
ReadOnly:   false
Conditions:
Type           Status  Reason
----           ------  ------
Available      True    MinimumReplicasAvailable
Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   neo4j-application-7757948b98 (1/1 replicas created)
Events:
Type    Reason             Age   From                   Message
----    ------             ----  ----                   -------
Normal  ScalingReplicaSet  35m   deployment-controller  Scaled up replica set neo4j-application-7757948b98 to 1

Name:           neo4j-application-7757948b98
Namespace:      default
Selector:       app=neo4j,pod-template-hash=7757948b98
Labels:         app=neo4j
pod-template-hash=7757948b98
Annotations:    deployment.kubernetes.io/desired-replicas: 1
deployment.kubernetes.io/max-replicas: 2
deployment.kubernetes.io/revision: 1
Controlled By:  Deployment/neo4j-application
Replicas:       1 current / 1 desired
Pods Status:    1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels:  app=neo4j
pod-template-hash=7757948b98
Containers:
neo4j:
Image:        neo4j:4.1.4
Ports:        7474/TCP, 7687/TCP
Host Ports:   0/TCP, 0/TCP
Environment:  <none>
Mounts:
/data from neo4j-storage (rw)
Volumes:
neo4j-storage:
Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName:  neo4j-volume-claim
ReadOnly:   false
Events:
Type    Reason            Age   From                   Message
----    ------            ----  ----                   -------
Normal  SuccessfulCreate  35m   replicaset-controller  Created pod: neo4j-application-7757948b98-2pxr2

正如评论和本文中所提到的,通过NodePort公开在minikube中运行的应用程序的方式是我运行命令:

minikube service <SERVICE_NAME> --url

它打印出你可以粘贴到浏览器中的url。您还提到:

有了minikube服务的url,我可以到达终点!🏃 Starting tunnel for service neo4j-service. http://127.0.0.1:49523 and http://127.0.0.1:49524.,但考虑到应用领域。。。我应该如何处理NodePort 30001?配置kubernetes节点的正确方法是什么?

粘贴的输出是正确的,您得到了成功的响应。至于NodePort-minikube将这个端口映射到您在运行前面提到的命令时获得的url。阅读更多关于访问minikube中运行的应用程序的信息

相关内容

  • 没有找到相关文章

最新更新