我正在尝试部署一个使用 postgres 数据库的 spring 引导应用程序。
我使用了本教程:https://github.com/mkjelland/spring-boot-postgres-on-k8s-sample
但是当我做这个通讯时
kubectl expose deployment spring-boot-postgres-sample --type=LoadBalancer --
port=8080
因此,它给出了大约 30 分钟的外部 IP 状态
所以我通过使用
kubectl patch svc <svc-name> -n <namespace> -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.31.71.218"]}}'
因此,当我尝试访问超时 http://172.31.71.218:8080 时。
我想检查幕后发生的事情。
我还尝试使用yaml文件使用群集IP服务
apiVersion: v1
kind: Service
metadata:
labels:
app: spring-boot-postgres-sample
name: spring-boot-postgres-sample
namespace: default
spec:
ports:
- nodePort: 30500
port: 80
protocol: TCP
targetPort: 80
selector:
app: spring-boot-postgres-sample
type: NodePort
使用以下命令:-
kubectl create -f service.yaml
然后尝试访问 http://myhostip:30500/
但仍然超时如何检查日志
这是 kubectl 描述 pod podname 的输出
Name: spring-boot-postgres-sample-7f7c7479d9-fclwb
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: ip-172-31-11-87/172.31.11.87
Start Time: Thu, 30 May 2019 11:50:24 +0000
Labels: app=spring-boot-postgres-sample
pod-template-hash=7f7c7479d9
Annotations: <none>
Status: Running
IP: 192.168.1.28
Controlled By: ReplicaSet/spring-boot-postgres-sample-7f7c7479d9
Containers:
spring-boot-postgres-sample:
Container ID: docker://a1278cc26a66eb3b977cf1946d1490c7c5066e9fe0db8c468fd0e8dc47de5ca2
Image: djtijare/a2i-web:v1
Image ID: docker-pullable://djtijare/a2i-web@sha256:cbeac029eb3b65760b904e93ced0b417eca349280ba5a809de713d5fbb2d608f
Port: <none>
Host Port: <none>
Command:
/bin/bash
-ce
tail -f /dev/null
State: Running
Started: Thu, 30 May 2019 11:50:46 +0000
Ready: True
Restart Count: 0
Environment:
POSTGRES_USER: <set to the key 'postgres_user' of config map 'postgres-config'> Optional: false
POSTGRES_PASSWORD: <set to the key 'postgres_password' of config map 'postgres-config'> Optional: false
POSTGRES_HOST: <set to the key 'postgres_host' of config map 'hostname-config'> Optional: false
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6pksq (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-6pksq:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-6pksq
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
aquilak8suser@ip-172-31-6-149:~/a2i-web$ kubectl describe pod spring-boot-postgres-sample-7f7c7479d9-fclwb
Name: spring-boot-postgres-sample-7f7c7479d9-fclwb
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: ip-172-31-11-87/172.31.11.87
Start Time: Thu, 30 May 2019 11:50:24 +0000
Labels: app=spring-boot-postgres-sample
pod-template-hash=7f7c7479d9
Annotations: <none>
Status: Running
IP: 192.168.1.28
Controlled By: ReplicaSet/spring-boot-postgres-sample-7f7c7479d9
Containers:
spring-boot-postgres-sample:
Container ID: docker://a1278cc26a66eb3b977cf1946d1490c7c5066e9fe0db8c468fd0e8dc47de5ca2
Image: djtijare/a2i-web:v1
Image ID: docker-pullable://djtijare/a2i-web@sha256:cbeac029eb3b65760b904e93ced0b417eca349280ba5a809de713d5fbb2d608f
Port: <none>
Host Port: <none>
Command:
/bin/bash
-ce
tail -f /dev/null
State: Running
Started: Thu, 30 May 2019 11:50:46 +0000
Ready: True
Restart Count: 0
Environment:
POSTGRES_USER: <set to the key 'postgres_user' of config map 'postgres-config'> Optional: false
POSTGRES_PASSWORD: <set to the key 'postgres_password' of config map 'postgres-config'> Optional: false
POSTGRES_HOST: <set to the key 'postgres_host' of config map 'hostname-config'> Optional: false
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6pksq (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-6pksq:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-6pksq
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
可以使用以下命令获取部署日志
kubectl logs -f deployment/spring-boot-postgres-sample
或者,如果您需要特定 Pod 的日志
kubectl logs -f spring-boot-postgres-sample-7f7c7479d9-fclwb