简体   繁体   English

如何将 IP 分配给 Kube.netes 集群?

[英]How to assign an IP to Kubernetes cluster?

I have installed a K8S cluster via Rancher and it is up and running.我已经通过 Rancher 安装了一个 K8S 集群,它已经启动并正在运行。 For testing purpose, I've deployed a helloworld nginx pod:出于测试目的,我部署了一个 helloworld nginx pod:

在此处输入图像描述

To call the service, I have to call the NodePort IP address, for example:要调用该服务,我必须调用 NodePort IP 地址,例如:

http://111.111.111.111:30359/

But I would like to call it by a name, for example:但我想用一个名字来称呼它,例如:

https://helloworld.co.example.org

The ingress controller Nginx is installed:安装入口controller Nginx:

NAMESPACE       NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE
default         kubernetes             ClusterIP   10.43.0.1       <none>        443/TCP                  162m
dev             helloworld             ClusterIP   10.43.187.230   <none>        80/TCP                   17m
dev             helloworld-nodeport    NodePort    10.43.9.147     <none>        80:30359/TCP             17m
ingress-nginx   default-http-backend   ClusterIP   10.43.86.105    <none>        80/TCP                   161m
kube-system     kube-dns               ClusterIP   10.43.0.10      <none>        53/UDP,53/TCP,9153/TCP   161m
kube-system     metrics-server         ClusterIP   10.43.220.198   <none>        443/TCP                  161m

But it does not have EXTERNAL-IP .但它没有EXTERNAL-IP The question is, how to get it.问题是,如何得到它。

A ClusterIP type service will never create an EXTERNAL IP because it's cluster-internal IP. Follow this guide on how to use nginx ingress on digital ocean to expose hello world app via a hostname. ClusterIP类型的服务永远不会创建 EXTERNAL IP,因为它是集群内部的 IP。请按照本指南了解如何使用数字海洋上的 nginx 入口通过主机名公开 hello world 应用程序。

Following the guide after you install the nginx ingress controller it will be exposed by a LoadBalancer provided by digital ocean.按照指南安装 nginx 入口 controller 后,它将由 digital ocean 提供的 LoadBalancer 公开。

As you can see in the guide you will use your domain in the ingress rules.You'll need to ensure that your domain is pointed to the Load Balancer via A records.正如您在指南中看到的,您将在入口规则中使用您的域。您需要确保您的域通过 A 记录指向负载均衡器。 This is done through your DNS provider.这是通过您的 DNS 提供商完成的。

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: helloworld.co.example.org
    http:
      paths:
      - backend:
          serviceName: hello-kubernetes
          servicePort: 80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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