简体   繁体   中英

Cannot access service at external ip Kubernetes

I have a problem that I cannot access service with curl althought I have external IP.I meet a timeout request. Here is my services

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE crawler-manager-1 NodePort 10.103.18.210 192.168.0.10 3001:30029/TCP 2h redis NodePort 10.100.67.138 192.168.0.11 6379:30877/TCP 5h and here my yaml service file:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
      convert -f docker-compose.yml
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: crawler-manager-1
  name: crawler-manager-1
  namespace: cbpo-example
spec:
  type: NodePort
  externalIPs:
    - 192.168.0.10
  ports:
  - name: "3001"
    port: 3001
    targetPort: 3001
  selector:
    io.kompose.service: crawler-manager-1
    run: redis
status:
  loadBalancer: {}

Here my deployment yml file

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
      convert -f docker-compose.yml
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: crawler-manager-1
  name: crawler-manager-1
  namespace: cbpo-example
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: crawler-manager-1
    spec:
      hostNetwork: true
      containers:
      - args:
        - npm
        - start
        env:
        - name: DB_HOST
          value: mysql
        - name: DB_NAME
        - name: DB_PASSWORD
        - name: DB_USER
        - name: REDIS_URL
          value: redis://cbpo-redis
        image: localhost:5000/manager
        name: crawler-manager-1
        ports:
        - containerPort: 3001
        resources: {}
      restartPolicy: Always
status: {}

Anyone have a problem like me when work with kube.netes? I need to access to check if 2 service in my namespace can connect each other, Thanks so much.

Instead of communication through ip addresses for your services you can communicate with their DNS names.

“Normal” (not headless) Services are assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local. This resolves to the cluster IP of the Service.

“Headless” (without a cluster IP) Services are also assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local. Unlike normal Services, this resolves to the set of IPs of the pods selected by the Service. Clients are expected to consume the set or else use standard round-robin selection from the set.

For more info, please check Kubernetes DNS for Services

Make sure you see end points for the app. One reason this can happen is becuase of pod name mismatch.. if i remember, it's selector.name

 kubectl get endpoints
 NAME         ENDPOINTS            AGE
 kubernetes   192.168.63.13:8080   1d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM