How to assign a static IP to a pod using Kubernetes on deployment

浪尽此生 提交于 2019-12-06 08:13:13

问题


I am trying to assign a static IP address to a pod on deployment.

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: aws-test-mysql
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: aws-test-mysql
    spec:
      containers:
      - name: aws-test-mysql
        image: 461677341235123.dkr.ecr.us-east-1.amazonaws.com/aws-test-mysql
        securityContext:
          privileged: true
        ports:
        - containerPort: 3306
          hostIP: 172.20.32.50
          hostPort: 3306
        resources:
          requests:
            cpu: 100m
      imagePullSecrets:
        - name: ecrkey

As you can see when I described my pod it is created with another IP.

test-mbp1:aws test$ kubectl describe pods | grep IP
IP:     100.96.1.3

I'm trying to deploy a pod with a static IP on "kind: Deployment" and not as a service.

Is this posible ?


回答1:


A static IP cannot be assigned to a Pod because of the dynamic nature of kubernetes' IP layer.

Since you don't want to attach a Service (which is the best way imho), a close alternative is to convert the Deployment to a StatefulSet. This will give the Pod a static hostname which more-or-less fulfils your requirement.

The first replica of the StatefulSet will be called aws-test-mysql-0.<kubernetes.cluster.tld>.



来源:https://stackoverflow.com/questions/45465228/how-to-assign-a-static-ip-to-a-pod-using-kubernetes-on-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!