如何在部署时使用Kubernetes将静态IP分配给Pod [英] How to assign a static IP to a pod using Kubernetes on deployment

查看:1316
本文介绍了如何在部署时使用Kubernetes将静态IP分配给Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为部署时的Pod分配一个静态IP地址.

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

如您所见,当我描述我的广告连播时,它是用另一个IP创建的.

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

我正在尝试在种类:部署"而不是服务上部署具有静态IP的Pod.

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

这可能吗?

推荐答案

由于kubernetes IP层的动态特性,无法将静态IP分配给Pod.

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

由于您不希望附加服务(这是恕我直言的最佳方式),因此一种替代方案是将Deployment转换为StatefulSet.这将为Pod提供一个静态主机名,该主机名或多或少可以满足您的要求.

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.

StatefulSet的第一个副本将称为aws-test-mysql-0.<kubernetes.cluster.tld>.

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

这篇关于如何在部署时使用Kubernetes将静态IP分配给Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆