您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
如何暴露您Kubernetes集群内部 "应用服务" 并向外(互联网)提供访问服务!!!
Internet ---------> Service
Internet ------> Ingress ------> Service
Ingress 它能做什么
Ingress 控制器
多个Ingress控制器并存的示例
多个控制器切换使用,修改红色字体即可
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- secretName: tls-secret
backend:
serviceName: echoheaders-https
servicePort: 80
haproxy-ingress参考 haproxy-ingress in github
在使用kubeadm工具部署的集群下部署Ingress-nginx
https://github.com/kubernetes/ingress-nginx
https://github.com/kubernetes/ingress-nginx/blob/master/docs/deploy/index.md
https://kubernetes.github.io/ingress-nginx/
https://kubernetes.github.io/ingress-nginx/deploy/
[root@node1 ~]# kubectl explain ingress.spec
[root@node1 ~]# kubectl explain ingress.spec.rules
[root@node1 ingress]# wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.27.1/deploy/static/mandatory.yaml
[root@node1 ingress]# kubectl apply -f mandatory.yaml
[root@node1 ingress]# kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-948ffd8cc-9nd4c 1/1 Running 0 10m
[root@node1 ingress]#
[root@node1 ingress]# kubectl describe pods -n ingress-nginx
[root@node1 ingress]# wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.27.1/deploy/static/provider/baremetal/service-nodeport.yaml
[root@node1 ingress]# kubectl apply -f service-nodeport.yaml
service/ingress-nginx created
[root@node1 ingress]#
[root@node1 ingress]# kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx NodePort 10.99.146.223 <none> 80:32116/TCP,443:30771/TCP 17s
[root@node1 ingress]#
[root@node1 ingress]# curl 172.12.0.10:32116
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h2>404 Not Found</h2></center>
<hr><center>nginx/1.17.7</center>
</body>
</html>
[root@node1 ingress]#
Nginx调度器本身调度已经可以正常工作了!!!
Nginx调度器本身调度已经可以正常工作了!!!
Nginx调度器本身调度已经可以正常工作了!!!
接下来就可以手动部署个应用,并通过nginx的调度器发布出去
手动部署tomcat应用服务,通过nginx调度器发布出去
[root@node1 pod]# cat tomcat-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: tomcat
namespace: default
spec:
selector:
app: tomcat
release: canary
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 30080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-demo
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: tomcat
release: canary
template:
metadata:
labels:
app: tomcat
release: canary
spec:
containers:
- name: tomcat
image: tomcat
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
- name: ajp
containerPort: 8009
[root@node1 pod]#
直接使用集群内部任意IP地址加30080端口进行访问即可。
[root@node1 pod]# cat deploy-svc-tomcat.yaml
apiVersion: v1
kind: Service
metadata:
name: tomcat
spec:
selector:
app: tomcat
release: canary
ports:
- name: http
targetPort: 8080
port: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-demo
spec:
replicas: 2
selector:
matchLabels:
app: tomcat
release: canary
template:
metadata:
labels:
app: tomcat
release: canary
spec:
containers:
- name: tomcat8
image: tomcat
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
[root@node1 pod]#
创建完成后,接下来就可以为刚刚部署的tomcat制作一个ingress服务了
[root@node1 pod]# cat tomcat-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-tomcat
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: tomcat.siyou.com
http:
paths:
- path:
backend:
serviceName: tomcat
servicePort: 8080
[root@node1 pod]#
测试吧。配置好"tomcat.siyou.com"的解析,访问的时候通过ingress调度器映射出去的端口访问即可
# 获取默认空间下的pods资源详情
[root@node1 pod]# kubectl get pods -o wide
# 描述默认空间下某个pods资源
[root@node1 pod]# kubectl describe pods tomcat-demo-655c78c49-ctd66
# 查看某个tomcat的日志,实时查看
[root@node1 pod]# kubectl logs tomcat-demo-655c78c49-ctd66 -f
# 查看默认空间下tomcat应用端口监听状态
[root@node1 pod]# kubectl exec tomcat-demo-655c78c49-ctd66 -- ss -tnl
# 进入到一个tomcat内部
[root@node1 pod]# kubectl exec -it tomcat-demo-655c78c49-ctd66 -- /bin/sh
# 查看默认名称空间下的service详情
[root@node1 pod]# kubectl get svc -o wide
# 获取名称空间为ingress-nginx下的pod资源情况
[root@node1 pod]# kubectl get pods -n ingress-nginx
# 查看ingress-nginx空间下pod详情
[root@node1 pod]# kubectl describe pods -n ingress-nginx nginx-ingress-controller-948ffd8cc-9nd4c
# 查看默认名称空间下的ingress
[root@node1 pod]# kubectl get ingress
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。