如何在kubernates上使用静态IP作为外部IP?

时间:2019-06-20 11:39:38

标签: docker kubernetes yaml

我想将external-Ip设置为静态。我成功将ClusterIP设置为静态,但在任何地方都找不到external_IP的任何解决方案。

我使用以下部署yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: null
  generation: 1
  labels:
    run: x-master
  name: x-deployment-master
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: x-master
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: x-master
    spec:
      containers:
      - image: gitlab:4567/ecoservers/x-docker:x
        imagePullPolicy: IfNotPresent
        name: x-master
        volumeMounts:
        - name: task-pv-storage
          mountPath: /opt/y/x/home/configutil
        ports:
        - containerPort: 8009
          protocol: TCP
        - containerPort: 8443
          protocol: TCP
        - containerPort: 8445
          protocol: TCP
        - containerPort: 9000
          protocol: TCP
        - containerPort: 7600
          protocol: UDP
        - containerPort: 12001
          protocol: TCP
      volumes:
      - name: task-pv-storage
        hostPath:
          path: /root/configs/configutil_master
          type: Directory
      hostAliases:
      - ip: 10.233.0.13
        hostnames:
        - gessmsatf1
      - ip: 10.233.0.13
        hostnames:
        - gessmsatf2
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: x-master
  name: x-service-master
  selfLink: /api/v1/namespaces/default/services/x-service-master
spec:
  externalTrafficPolicy: Cluster
  ports:
  - name: "gui-port"
    protocol: TCP
    port: 8443
    targetPort: 8443
  - name: "service-port"
    protocol: TCP
    port: 8445
    targetPort: 8445
  - name: "cu-port"
    protocol: TCP
    port: 9000
    targetPort: 9000
  - name: "ajp-port"
    protocol: TCP
    port: 8009
    targetPort: 8009
  - name: "cluster-7600"
    protocol: TCP
    port: 7600
    targetPort: 7600
  - name: "cluster-12001"
    protocol: TCP
    port: 12001
    targetPort: 12001
clusterIP: 10.233.0.13
  loadBalancerIP: 10.233.0.13
  selector:
    run: x-master
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 10.233.0.13

实际结果如下:

名称类型集群IP外部IP端口的年龄

x-service-master  LoadBalancer  10.233.0.13   <pending>    8443:30013/TCP   175m

预期结果应为: 名称集群IP外部IP端口的年龄

helloweb           10.31.254.176   203.0.113.32     80:30690/TCP     54s

2 个答案:

答案 0 :(得分:0)

Kubernetes本身不提供负载平衡

Load Balancing on Kubernetes

当您指定服务定义时,您将设置一种类型的负载均衡器,该负载均衡器实际上是由云提供程序功能提供的(大多数情况下是由VPS提供程序处理的。AWS使用弹性负载均衡器,Azure使用其TCP负载均衡器等) )。在这种情况下,您几乎也不会指定IP地址

如果您在已经提供服务的云提供商上推出了自己的Kubernetes,则最好只使用该服务。如果您在私有数据中心中,则需要部署metallb,然后将服务降低到它。

使用NodePort作为类型是否可以完全解决您的问题?

答案 1 :(得分:0)

Kubernetes不提供任何IP作为静态IP或外部IP。如果您使用的是AWS,GCP作为服务,则可以创建服务类型LoadBalancer,以便它将为您提供一个可用作外部IP地址的外部IP。

您还可以在kubernetes中搜索入口。这还将有助于将来在一个kubernetes集群中为您的应用程序和多个网站设置SSL证书。

https://kubernetes.io/docs/concepts/services-networking/ingress/