0

我的环境是:Ruby on Rails、Vue.js、Webpacker 和 Kubernetes。

我在我的 K8s 部署中添加了用于运行状况检查的 readinessProbe,但是 pod 无法准备好启动,因此我使用以下命令检查了日志:

kubectl describe po <pod_name> -n <name_space>

然后我能够收到一条消息

Readiness probe failed: Get http://10.44.1.252:3000/health: dial tcp 10.44.1.252:3000: connect: connection refused.

但是,当我在本地主机中检查此路由时,没有错误并且 HTTP 状态为 200

curl http://localhost:3000/health 

在 K8s 吊舱中。

我进行了 readinessProbe 健康检查,因为我在入口中获得了不健康状态。

这是我的 YAML 文件:

mysql.yaml:

apiVersion: v1
kind: Service
metadata:
  namespace: line-manager
  name: mysql
  labels:
    app: mysql
spec:
  selector:
    app: mysql
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 3306
---
kind: PersistentVolume
apiVersion: v1
metadata:
  namespace: line-manager
  name: mysql-pv
  labels:
    app: mysql
spec:
  capacity:
    storage: 20Gi
  accessModes:
  - ReadWriteOnce
  storageClassName: standard
  hostPath:
    path: "/tmp/mysql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: line-manager
  name: mysql-pvc
  labels:
    app: mysql
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: standard
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: line-manager
  name: mysql
  labels:
    app: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7.17
        env:
        - name: MYSQL_DATABASE
          value: lineManage_db
        - name: MYSQL_USER
          value: root
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-pv
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-pv
        persistentVolumeClaim:
          claimName: mysql-pvc

webpacker.yaml

apiVersion: v1
kind: Service
metadata:
  namespace: line-manager
  name: webpacker
  labels:
    app: webpacker
spec:
  selector:
    app: webpacker
  type: ClusterIP
  clusterIP: None
  ports:
  - port: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: line-manager
  name: webpacker
spec:
  selector:
    matchLabels:
      app: webpacker
  template:
    metadata:
      labels:
        app: webpacker
    spec:
      containers:
      - name: webpacker
        image: khjoo19/fullout-line:v1
        imagePullPolicy: Always
        command: ["bundle", "exec", "bin/webpack-dev-server"]
        ports:
        - containerPort: 8080

rails.yaml:

apiVersion: v1
kind: Service
metadata:
  namespace: line-manager
  name: web
  labels:
    app: web
spec:
  selector:
    app: web
  type: NodePort
  ports:
  - port: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: line-manager
  name: web
spec:
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: khjoo19/fullout-line:v1
        imagePullPolicy: Always
        command: ["bundle", "exec", "rails", "s"]
        env:
        - name: MYSQL_DATABASE
          value: lineManage_db
        - name: MYSQL_USER
          value: root
        - name: MYSQL_HOST
          value: mysql
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3000
        readinessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 60
          periodSeconds: 30
          timeoutSeconds: 60
        volumeMounts:
        - name: mysql-pv
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-pv
        persistentVolumeClaim:
          claimName: mysql-pvc

kubectl describe po <pod_name> -n <namespace>

Name:               web-6d*****7d-khljl
Namespace:          line-manager
Priority:           0
PriorityClassName:  <none>
Node:               gke-core-pool-2-5*****26-v5wp/10.138.0.31
Start Time:         Fri, 17 Jan 2020 11:03:41 +0900
Labels:             app=web
                    pod-template-hash=6*****7d
Annotations:        <none>
Status:             Running
IP:                 10.44.1.252
Controlled By:      ReplicaSet/web-6*****d
Containers:
  web:
    Container ID:  docker://9eb5146d686856a*********************8465b358a04
    Image:         khjoo19/fullout-line:v1
    Image ID:      docker-pullable://khjoo19/fullout-line@sha256:ee6147ac************************8ab675ce3571
    Port:          3000/TCP
    Host Port:     0/TCP
    Command:
      bundle
      exec
      rails
      s
    State:          Running
      Started:      Fri, 17 Jan 2020 11:04:19 +0900
    Ready:          False
    Restart Count:  0
    Readiness:      http-get http://:3000/health delay=60s timeout=60s period=30s #success=1 #failure=3
    Environment:
      MYSQL_DATABASE:       lineManage_db
      MYSQL_USER:           root
      MYSQL_HOST:           mysql
      MYSQL_PASSWORD:       <set to the key 'password' in secret 'mysql-pass'>  Optional: false
      MYSQL_ROOT_PASSWORD:  <set to the key 'password' in secret 'mysql-pass'>  Optional: false
    Mounts:
      /var/lib/mysql from mysql-pv (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lzccw (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  mysql-pv:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pvc
    ReadOnly:   false
  default-token-lzccw:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-l****
    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:
  Type     Reason     Age                  From                                    Message
  ----     ------     ----                 ----                                    -------
  Normal   Scheduled  6m19s                default-scheduler                       Successfully assigned line-manager/web-6dfd6dcc7d-khljl to gke-core-pool-2-5e0c4e26-v5wp
  Normal   Pulling    6m17s                kubelet, gke-core-pool-2-5e0c4e26-v5wp  pulling image "khjoo19/fullout-line:v1"
  Normal   Pulled     5m43s                kubelet, gke-core-pool-2-5e0c4e26-v5wp  Successfully pulled image "khjoo19/fullout-line:v1"
  Normal   Created    5m41s                kubelet, gke-core-pool-2-5e0c4e26-v5wp  Created container
  Normal   Started    5m41s                kubelet, gke-core-pool-2-5e0c4e26-v5wp  Started container
  Warning  Unhealthy  24s (x9 over 4m24s)  kubelet, gke-core-pool-2-5e0c4e26-v5wp  Readiness probe failed: Get http://10.44.1.252:3000/health: dial tcp 10.44.1.252:3000: connect: connection refused
4

1 回答 1

2

您的 Webpacker 容器可能只监听localhost接口。将其更改为0.0.0.0.

于 2020-01-17T05:07:43.080 回答