日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ingress controller 和ingress使用实例

發布時間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ingress controller 和ingress使用实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ingress controller安裝

官方文檔:

https://kubernetes.github.io/ingress-nginx/

創建基礎配置

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

 Using?NodePort:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml

以上執行完成后,查看ingress-controller已經運行起來了

[root@k8s-master ~]# kubectl get pods -n ingress-nginx NAME READY STATUS RESTARTS AGE nginx-ingress-controller-689498bc7c-tvhv5 1/1 Running 3 16d [root@k8s-master ~]#

查看service信息,nodeport端口31380,31390

[root@k8s-master ~]# kubectl get svc -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx NodePort 10.108.101.78 <none> 80:31380/TCP,443:31390/TCP 14d [root@k8s-master ~]#

 至此ingress-controller安裝完成

What is Ingress?

internet|[ Ingress ]--|-----|--[ Services ]

  

ingress使用

本次通過安裝kubernetes的dashboard來演示ingress的使用

dashboard的安裝

[root@k8s-master jtdeploy]# cat kubernetes-dashboard.yaml # Copyright 2017 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.# ------------------- Dashboard Secret ------------------- #apiVersion: v1 kind: Secret metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-certsnamespace: kube-system type: Opaque--- # ------------------- Dashboard Service Account ------------------- #apiVersion: v1 kind: ServiceAccount metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kube-system--- # ------------------- Dashboard Role & Role Binding ------------------- #kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata:name: kubernetes-dashboard-minimalnamespace: kube-system rules:# Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret. - apiGroups: [""]resources: ["secrets"]verbs: ["create"]# Allow Dashboard to create 'kubernetes-dashboard-settings' config map. - apiGroups: [""]resources: ["configmaps"]verbs: ["create"]# Allow Dashboard to get, update and delete Dashboard exclusive secrets. - apiGroups: [""]resources: ["secrets"]resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]verbs: ["get", "update", "delete"]# Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map. - apiGroups: [""]resources: ["configmaps"]resourceNames: ["kubernetes-dashboard-settings"]verbs: ["get", "update"]# Allow Dashboard to get metrics from heapster. - apiGroups: [""]resources: ["services"]resourceNames: ["heapster"]verbs: ["proxy"] - apiGroups: [""]resources: ["services/proxy"]resourceNames: ["heapster", "http:heapster:", "https:heapster:"]verbs: ["get"]--- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata:name: kubernetes-dashboard-minimalnamespace: kube-system roleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: kubernetes-dashboard-minimal subjects: - kind: ServiceAccountname: kubernetes-dashboardnamespace: kube-system--- # ------------------- Dashboard Deployment ------------------- #kind: Deployment apiVersion: apps/v1 metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kube-system spec:replicas: 1revisionHistoryLimit: 10selector:matchLabels:k8s-app: kubernetes-dashboardtemplate:metadata:labels:k8s-app: kubernetes-dashboardspec:containers:- name: kubernetes-dashboardimage: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1ports:- containerPort: 9090protocol: TCPargs:- --enable-skip-login# Uncomment the following line to manually specify Kubernetes API server Host# If not specified, Dashboard will attempt to auto discover the API server and connect# to it. Uncomment only if the default does not work.# - --apiserver-host=http://my-address:portvolumeMounts:- name: kubernetes-dashboard-certsmountPath: /certs# Create on-disk volume to store exec logs- mountPath: /tmpname: tmp-volumelivenessProbe:httpGet:scheme: HTTPpath: /port: 9090initialDelaySeconds: 30timeoutSeconds: 30volumes:- name: kubernetes-dashboard-certssecret:secretName: kubernetes-dashboard-certs- name: tmp-volumeemptyDir: {}serviceAccountName: kubernetes-dashboard# Comment the following tolerations if Dashboard must not be deployed on mastertolerations:- key: node-role.kubernetes.io/mastereffect: NoSchedule --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata:name: kubernetes-dashboardlabels:k8s-app: kubernetes-dashboard roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin subjects: - kind: ServiceAccountname: kubernetes-dashboardnamespace: kube-system--- # ------------------- Dashboard Service ------------------- #kind: Service apiVersion: v1 metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kube-system spec:type: NodePortports:- port: 9090targetPort: 9090selector:k8s-app: kubernetes-dashboard [root@k8s-master jtdeploy]#

使用以上配置文件即可創建

查看pods

[root@k8s-master jtdeploy]# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE calico-node-2srnw 2/2 Running 8 20d calico-node-ppnjh 2/2 Running 8 20d coredns-86c58d9df4-ptth2 1/1 Running 4 20d coredns-86c58d9df4-wxldx 1/1 Running 4 20d etcd-k8s-master 1/1 Running 4 20d kube-apiserver-k8s-master 1/1 Running 4 20d kube-controller-manager-k8s-master 1/1 Running 4 20d kube-proxy-4kwj6 1/1 Running 4 20d kube-proxy-hfmqn 1/1 Running 4 20d kube-scheduler-k8s-master 1/1 Running 4 20d kubernetes-dashboard-784b868d9d-hc77v 1/1 Running 3 16d tiller-deploy-dbb85cb99-srbch 1/1 Running 4 20d [root@k8s-master jtdeploy]#

查看svc

[root@k8s-master jtdeploy]# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE calico-typha ClusterIP 10.105.54.12 <none> 5473/TCP 20d kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 20d kubernetes-dashboard ClusterIP 10.106.65.78 <none> 9090/TCP 16d tiller-deploy ClusterIP 10.97.33.192 <none> 44134/TCP 20d [root@k8s-master jtdeploy]#

顯然沒有使用nodeport ,所有使用ingress來配置外網訪問.

  

haproxy安裝

root@xuliang-PC:~/haproxy# cat docker-compose.yml version: "2" services:haproxy:image: haproxy:1.8ports:- 80:31380- 443:31390- 8181:8181restart: alwaysvolumes:- /root/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfgnetwork_mode: host # networks: # # - haproxy_lb # # #networks: # # haproxy_lb: # # driver: bridgeroot@xuliang-PC:~/haproxy#

 haproxy配置文件

root@xuliang-PC:~/haproxy# cat haproxy.cfg globalstats timeout 30smaxconn 1000defaultsmode tcpoption dontlognullretries 3timeout http-request 30stimeout queue 1mtimeout connect 30stimeout client 1mtimeout server 1mtimeout http-keep-alive 30stimeout check 30soption redispatchoption srvtcpkaoption clitcpka## HTTP frontend http_frontbind *:80default_backend http_backendbackend http_backendserver k8s-master 192.168.100.101:31380 checkserver k8s-node1 192.168.1.102:31380 check#server k8s-node3 192.168.1.103:31380 check## HTTPS frontend https_frontbind *:443default_backend https_backendbackend https_backendserver k8s-master 192.168.100.101:31390 checkserver k8s-node1 192.168.100.102:31390 check#server k8s-node4 192.168.1.103:31390 check# HAProxy stats listen statsbind *:8181mode httpstats enablestats uri /stats realm Haproxy\ Statisticsstats auth haproxy:haproxy root@xuliang-PC:~/haproxy#

 

在本機添加hosts,有域名的可以配置域名解析

root@xuliang-PC:~/haproxy# cat /etc/hosts 192.168.100.29 myapp.test.com root@xuliang-PC:~/haproxy#

測試解析

root@xuliang-PC:~/haproxy# ping myapp.test.com PING myapp.test.com (192.168.100.29) 56(84) bytes of data. 64 bytes from myapp.test.com (192.168.100.29): icmp_seq=1 ttl=64 time=0.024 ms 64 bytes from myapp.test.com (192.168.100.29): icmp_seq=2 ttl=64 time=0.024 ms 64 bytes from myapp.test.com (192.168.100.29): icmp_seq=3 ttl=64 time=0.028 ms ^C --- myapp.test.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2032ms rtt min/avg/max/mdev = 0.024/0.025/0.028/0.004 ms root@xuliang-PC:~/haproxy#

?

配置ingress

[root@k8s-master ~]# cat ingress-dashboard.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata:name: ingress-dashboardnamespace: kube-systemannotations:kubernetes.io/ingress.class: "nginx" spec:rules:- host: myapp.test.comhttp:paths:- path: /backend:serviceName: kubernetes-dashboardservicePort: 9090--- apiVersion: v1 kind: Service metadata:name: ingress-nginxnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx spec:type: NodePortports:- name: httpport: 80targetPort: 80protocol: TCPnodePort: 31380- name: httpsport: 443targetPort: 443protocol: TCPnodePort: 31390selector:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx---[root@k8s-master ~]#

此處注意一定要配置:

annotations:kubernetes.io/ingress.class: "nginx"

查看ingress [root@k8s-master ~]# kubectl get ingress NAME HOSTS ADDRESS PORTS AGE ingress-dashboard dashboard.test.com 80 14d [root@k8s-master ~]#

 

至此可以通過域名訪問

?

 

轉載于:https://www.cnblogs.com/xuliang666/p/11136829.html

總結

以上是生活随笔為你收集整理的ingress controller 和ingress使用实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。