大网数据广告活动
服务器运维问答

Access service on subdomain in Kubernetes

· 52CE 我爱测

I have following setup: Private OpenStack Cloud - o̲n̲l̲y̲ Web UI (Horizon) is accessible (API is restricted but maybe I could get access) I have used CoreOS with a setup of one master and three nodes Resources are standardized (…

问题原文

原帖链接 · x4k3p · CC BY-SA 3.0

I have following setup:

  • Private OpenStack Cloud - o̲n̲l̲y̲ Web UI (Horizon) is accessible
    (API is restricted but maybe I could get access)
  • I have used CoreOS with a setup of one master and three nodes
  • Resources are standardized (as default of OpenStack)
  • I followed the getting-started guide for CoreOS (i.e. I'm using the default YAMLs for cloud-config provided) on GitHub

As I read extensions such like Web UI (kube-ui) can be added as Add-On - which I have added (only kube-ui).

Now if I run a test such like simple-nginx I get following output:

creating pods:

$ kubectl run my-nginx --image=nginx --replicas=2 --port=80

creating service:

$ kubectl expose rc my-nginx --port=80 --type=LoadBalancer          
NAME       LABELS         SELECTOR       IP(S)     PORT(S)
my-nginx   run=my-nginx   run=my-nginx             80/TCP

get service info:

$ kubectl describe service my-nginx                                                                                                
Name:           my-nginx
Namespace:      default
Labels:         run=my-nginx
Selector:       run=my-nginx
Type:           LoadBalancer
IP:             10.100.161.90
Port:           <unnamed>   80/TCP
NodePort:       <unnamed>   31170/TCP
Endpoints:      10.244.19.2:80,10.244.44.3:80
Session Affinity:   None
No events.

I can access my service from every(!) external IP of the nodes.

My question now is as follows:

How can access any started service ether with a subdomain and therefore how can I set this configuration (for example I have domain.com as example) or could it be printed out on which node-IP I have to access my service (although I have only two replicas(?!))?

To describe my thoughts more understandable I mean following:

  • given domain: domain.com (pointing to master)
  • start service simple-nginx
  • service can be accessed with simple-nginx.domain.com

已采纳解答

原帖链接 · Matt · CC BY-SA 4.0

Here is the answer to all these people that see it after 5 years since the question got asked.

Tech got better and now we have ingress in k8s :D.

To make use of subdomains, deploy ingress controller e.g. nginx ingress controller

and create an ingress object:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: "simple-nginx.domain.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: simple-nginx
            port:
              number: 80

Now all that is left to do, is to create a dns record for *.domain.com and point it to the ingress IP seen in ADDRESS column.

$ kubectl get ingress
NAME          CLASS    HOSTS                      ADDRESS           PORTS   AGE
ingress       <none>   simple-nginx.domain.com    xxx.yyy.zzz.kkk   80      2d20h

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。