Dns kubernetes新服务的外部IP不更新

时间:2019-07-26 10:27:19

标签: mongodb docker kubernetes dns eks

我想为kubernetes集群之外的kubernetes创建新的mongo服务。

Mongo部署和服务在群集中工作正常,但是当我创建具有外部IP的新mongo服务时,然后删除所有应用kubectl delete和mongo并再次使用新mongo服务创建kubectl apply

但是DNS kubernetes无法更新:

kubectl exec -it python-guestbook-backend-8544c67965-pxlj5 ping python-guestbook-mongodb
PING python-guestbook-mongodb.default.svc.cluster.local (172.20.74.79) 56(84) bytes of data.

仍然有旧的IP地址。

NAME                                         READY   STATUS    RESTARTS   AGE
python-guestbook-backend-8544c67965-pxlj5    1/1     Running   0          28m
python-guestbook-frontend-55677f6fd7-sjrf5   1/1     Running   0          28m
python-guestbook-mongodb-567654b76f-zxd6t    1/1     Running   0          5h53m

mongo-service.yaml

kind: Service
metadata:
  name: python-guestbook-mongodb
#  name: python-guestbook-mongodb
  labels:
    app: python-guestbook
    tier: db
spec:
  ports:
  - name: python-guestbook
    protocol: TCP
    port: 27017
    targetPort: 27017
  selector:
    app: python-guestbook
    tier: db
  externalIPs:
  - 18.139.115.128

1 个答案:

答案 0 :(得分:0)

实际上,我错过了endpoint这项服务:

apiVersion: v1
metadata:
 name: python-guestbook-mongodb
spec:
 ports:
 - port: 27017
   targetPort: 27017
---
kind: Endpoints
apiVersion: v1
metadata:
 name: python-guestbook-mongodb
subsets:
 - addresses:
     - ip: x.x.x.x
   ports:
     - port: 27017