您好,登錄后才能下訂單哦!
如何暴露您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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。