Как подключиться к GKE Postgresql SVC в GCP? - PullRequest
0 голосов
/ 03 апреля 2019

Я пытаюсь подключиться к службе postgresql (pod) в моем развертывании kubernetes, но у меня GCP не дает порт (поэтому я не могу использовать что-то вроде: $ psql -h localhost -U postgresadmin1 --password -p 31070 postgresdb для подключения к Postgresql и просмотра моей базы данных).

Я использую LoadBalancer в моем сервисе:


@cloudshell:~ (academic-veld-230622)$ psql -h 35.239.52.68 -U jhipsterpress --password -p 30728 jhipsterpress-postgresql
Password for user jhipsterpress:
psql: could not connect to server: Connection timed out
        Is the server running on host "35.239.52.68" and accepting
        TCP/IP connections on port 30728?

apiVersion: v1
kind: Service
metadata:
  name: jhipsterpress
  namespace: default
  labels:
    app: jhipsterpress
spec:
  selector:
    app: jhipsterpress
  type: LoadBalancer
  ports:
  - name: http
    port: 8080



NAME                                            READY     STATUS    RESTARTS   AGE
pod/jhipsterpress-84886f5cdf-mpwgb              1/1       Running   0          31m
pod/jhipsterpress-postgresql-5956df9557-fg8cn   1/1       Running   0          31m

NAME                               TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)          AGE
service/jhipsterpress              LoadBalancer   10.11.243.22   35.184.135.134   8080:32670/TCP   31m
service/jhipsterpress-postgresql   LoadBalancer   10.11.255.64   35.239.52.68     5432:30728/TCP   31m
service/kubernetes                 ClusterIP      10.11.240.1    <none>           443/TCP          35m

NAME                                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/jhipsterpress              1         1         1            1           31m
deployment.apps/jhipsterpress-postgresql   1         1         1            1           31m

NAME                                                  DESIRED   CURRENT   READY     AGE
replicaset.apps/jhipsterpress-84886f5cdf              1         1         1         31m
replicaset.apps/jhipsterpress-postgresql-5956df9557   1         1         1         31m


@cloudshell:~ (academic-veld-230622)$ kubectl describe pod jhipsterpress-postgresql
Name:               jhipsterpress-postgresql-5956df9557-fg8cn
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               gke-standard-cluster-1-default-pool-bf9f446d-9hsq/10.128.0.58
Start Time:         Sat, 06 Apr 2019 13:39:08 +0200
Labels:             app=jhipsterpress-postgresql
                    pod-template-hash=1512895113
Annotations:        kubernetes.io/limit-ranger=LimitRanger plugin set: cpu request for container postgres
Status:             Running
IP:                 10.8.0.14
Controlled By:      ReplicaSet/jhipsterpress-postgresql-5956df9557
Containers:
  postgres:
    Container ID:   docker://55475d369c63da4d9bdc208e9d43c457f74845846fb4914c88c286ff96d0e45a
    Image:          postgres:10.4
    Image ID:       docker-pullable://postgres@sha256:9625c2fb34986a49cbf2f5aa225d8eb07346f89f7312f7c0ea19d82c3829fdaa
    Port:           5432/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 06 Apr 2019 13:39:29 +0200
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:  100m
    Environment:
      POSTGRES_USER:      jhipsterpress
      POSTGRES_PASSWORD:  <set to the key 'postgres-password' in secret 'jhipsterpress-postgresql'>  Optional: false
    Mounts:
      /var/lib/pgsql/data from data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mlmm5 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  spingular-bucket
    ReadOnly:   false
  default-token-mlmm5:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mlmm5
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason                  Age                From                                                        Message
  ----     ------                  ----               ----                                                        -------
  Warning  FailedScheduling        33m (x3 over 33m)  default-scheduler                                           persistentvolumeclaim "spingular-bucket" not found
  Warning  FailedScheduling        33m (x3 over 33m)  default-scheduler                                           pod has unbound immediate PersistentVolumeClaims
  Normal   Scheduled               33m                default-scheduler                                           Successfully assigned default/jhipsterpress-postgresql-5956df9557-fg8cn to gke-standard-cluster-1-default-pool-bf9f446d-9hsq
  Normal   SuccessfulAttachVolume  33m                attachdetach-controller                                     AttachVolume.Attach succeeded for volume "pvc-95ba1737-5860-11e9-ae59-42010a8000a8"
  Normal   Pulling                 33m                kubelet, gke-standard-cluster-1-default-pool-bf9f446d-9hsq  pulling image "postgres:10.4"
  Normal   Pulled                  32m                kubelet, gke-standard-cluster-1-default-pool-bf9f446d-9hsq  Successfully pulled image "postgres:10.4"
  Normal   Created                 32m                kubelet, gke-standard-cluster-1-default-pool-bf9f446d-9hsq  Created container
  Normal   Started                 32m                kubelet, gke-standard-cluster-1-default-pool-bf9f446d-9hsq  Started container

С открытым брандмауэром: posgresql-jhipster вход Применить ко всем
Диапазоны IP: 0.0.0.0/0 TCP: 30728 Разрешать 999 по умолчанию

Спасибо за вашу помощь. Любая документация действительно ценится.

1 Ответ

0 голосов
/ 04 апреля 2019

Ваш сервис в настоящее время является кластером типа IP.Это не раскрывает службу или модули за пределами кластера.Вы не можете подключиться к модулю из облачной оболочки, как это, поскольку облачная оболочка отсутствует на вашем VPC, а модули не отображаются.

Обновите службу, используя kubectl edit svc jhipsterpress-postgresql Измените спецификацию.введите в поле «LoadBalancer»

После этого у вас будет внешний IP-адрес, к которому можно подключиться

...