一、 通过ingress访问
- 定义ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tiller-deploy
namespace: kube-system
spec:
rules:
- host: tiller.eb.com
http:
paths:
- path: /
backend:
serviceName: tiller-deploy
servicePort: 44134
serviceName要和service中一样。
定义一个host 域名 作为外部流量访问内部的入口, 并在hosts文件中做映射
然后创建这个ingress
ping这个域名,能通表示成功
此时,可以在外部通过这个域名访问内部流量了
二、 通过定义nodePort
在service.yaml文件中定义
打开该yaml文件
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2020-07-29T02:46:55Z"
labels:
app: helm
name: tiller
name: tiller-deploy
namespace: kube-system
resourceVersion: "35004470"
selfLink: /api/v1/namespaces/kube-system/services/tiller-deploy
uid: a74f0711-7b4a-478e-a772-4f85fc720278
spec:
clusterIP: 192.168.194.223
externalTrafficPolicy: Cluster
ports:
- name: tiller
nodePort: 7456 //自定义
port: 44134
protocol: TCP
targetPort: 44134
- name: tiller2
nodePort: 7457 自定义 (两种方式)
port: 44135
protocol: TCP
targetPort: 44135
selector:
app: helm
name: tiller
sessionAffinity: None
type: NodePort // 定义nodePort
status:
loadBalancer: {}
然后创建该service.yaml文件
然后查看该pod 所在的node节点
登录上该节点后,查看端口有没有启动
切换至 root账户登录,查看nodePort,已经启动。
然后外部程序定义如下,可以访问内部pod
host是 node节点的ip, port是nodePort