Kubernetes 为什么吊舱主机名不';无法解决?

Kubernetes 为什么吊舱主机名不';无法解决?,kubernetes,service,hostname,Kubernetes,Service,Hostname,我对kubernetes的豆荚有问题。 我有一个带有init容器的apppod(invoice),它检查mysql pod(invoicemysql)是否正在运行 invoice mysql正在运行并准备就绪,但invoice pod中的init容器没有看到它 以下是init容器的日志 DB is not yet reachable;sleep for 10s before retry DB is not yet reachable;sleep for 10s before retry nc:

我对kubernetes的豆荚有问题。 我有一个带有init容器的apppod(invoice),它检查mysql pod(invoicemysql)是否正在运行 invoice mysql正在运行并准备就绪,但invoice pod中的init容器没有看到它

以下是init容器的日志

DB is not yet reachable;sleep for 10s before retry
DB is not yet reachable;sleep for 10s before retry
nc: bad address 'invoice-mysql'
nc: bad address 'invoice-mysql'
DB is not yet reachable;sleep for 10s before retry
nc: bad address 'invoice-mysql'
DB is not yet reachable;sleep for 10s before retry
nc: bad address 'invoice-mysql'
这是发票号码

apiVersion: apps/v1
kind: Deployment
metadata:
  name: invoice
  namespace: jhipster
spec:
  replicas: 1
  selector:
    matchLabels:
      app: invoice
      version: 'v1'
  template:
    metadata:
      labels:
        app: invoice
        version: 'v1'
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - invoice
                topologyKey: kubernetes.io/hostname
              weight: 100
      initContainers:
        - name: init-ds
          image: busybox:latest
          command:
            - '/bin/sh'
            - '-c'
            - |
              while true
              do
                rt=$(nc -z -w 1 invoice-mysql 3306)
                if [ $? -eq 0 ]; then
                  echo "DB is UP"
                  break
                fi
                echo "DB is not yet reachable;sleep for 10s before retry"
                sleep 10
              done
      containers:
        - name: invoice-app
          image: docker.pkg.github.com/morsi84/kubernetes/invoice
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: prod
            - name: SPRING_CLOUD_CONFIG_URI
              value: http://admin:${jhipster.registry.password}@jhipster-registry.Jhipster.svc.cluster.local:8761/config
            - name: JHIPSTER_REGISTRY_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: registry-secret
                  key: registry-admin-password
            - name: EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE
              value: http://admin:${jhipster.registry.password}@jhipster-registry.Jhipster.svc.cluster.local:8761/eureka/
            - name: SPRING_DATASOURCE_URL
              value: jdbc:mysql://invoice-mysql.Jhipster.svc.cluster.local:3306/invoice?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true
            - name: SPRING_SLEUTH_PROPAGATION_KEYS
              value: 'x-request-id,x-ot-span-context'
            - name: JAVA_OPTS
              value: ' -Xmx256m -Xms256m'
          resources:
            requests:
              memory: '512Mi'
              cpu: '500m'
            limits:
              memory: '1Gi'
              cpu: '1'
          ports:
            - name: http
              containerPort: 8081
          readinessProbe:
            httpGet:
              path: /management/health
              port: http
            initialDelaySeconds: 20
            periodSeconds: 15
            failureThreshold: 6
          livenessProbe:
            httpGet:
              path: /management/health
              port: http
            initialDelaySeconds: 120
      imagePullSecrets:
          - name: regcred
这是发票mysql的yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: invoice-mysql
  namespace: jhipster
spec:
  replicas: 1
  selector:
    matchLabels:
      app: invoice-mysql
  template:
    metadata:
      labels:
        app: invoice-mysql
    spec:
      volumes:
        - name: data
          emptyDir: {}
      containers:
        - name: mysql
          image: mysql:8.0.20
          env:
            - name: MYSQL_USER
              value: root
            - name: MYSQL_ALLOW_EMPTY_PASSWORD
              value: 'yes'
            - name: MYSQL_DATABASE
              value: invoice
          args:
            - --lower_case_table_names=1
            - --skip-ssl
            - --character_set_server=utf8mb4
            - --explicit_defaults_for_timestamp
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: data
              mountPath: /var/lib/mysql/
          resources:
            requests:
              memory: '512Mi'
              cpu: '500m'
            limits:
              memory: '1Gi'
              cpu: '1'
---
apiVersion: v1
kind: Service
metadata:
  name: invoice-mysql
  namespace: jhipster
spec:
  selector:
    app: invoice-mysql
  ports:
    - port: 3306
下面是对invoice mysql服务的描述

Name:              invoice-mysql
Namespace:         jhipster
Labels:            <none>
Annotations:       <none>
Selector:          app=invoice-mysql
Type:              ClusterIP
IP:                10.98.220.110
Port:              <unset>  3306/TCP
TargetPort:        3306/TCP
Endpoints:         10.244.1.66:3306
Session Affinity:  None
Events:            <none>
名称:发票mysql
名称空间:jhipster
标签:
注释:
选择器:app=invoice-mysql
类型:集群
IP:10.98.220.110
端口:3306/TCP
目标端口:3306/TCP
终点:10.244.1.66:3306
会话关联:无
活动:
工作环境:

故障环境:


你能帮我一下吗

我认为你应该使用全服务域,而不是
mysql
。你能试着用发票mysql.Jhipster.svc.cluster.local来代替吗?

问题实际上是由于centos主机上的防火墙,我禁用了防火墙,名称开始解析。

你好,Syam,这个名称也无法解析,我在问题中附上了屏幕截图,显示了故障环境中的nslookup和工作环境中的结果我在dns日志中发现了此错误我执行了此命令:kubectl logs--namespace=kube system-l k8s app=kube dns,我得到了以下输出::53[INFO]插件/重新加载:运行配置MD5=db32ca3650231d74073ff4cf814959a7 CoreDNS-1.7.0 linux/amd64,go1.14.4,f59c03d[错误]插件/错误:2 6473717310687983585.33066931313241093183。HINFO:read udp 10.244.0.3:39609->10.66.15.254:53:read:no route to host[错误]插件/错误:2 6473717310687983585.330669313132410931183。HINFO:read udp 10.244.0.3:55906->10.66.15.254:53:read:no route to hosts这是一个新构建的集群吗?是否有其他服务的DNS解析可以在同一集群上正常工作?如果它是一个新建的环境,最好从下到上与工作环境进行比较。