当前位置: 首页 > news >正文

91、K8s之ingress上集

一、Ingress

service模式:

loadbalance

NodePort:每个节点都会有一个指定的端口 30000-32767 内网

clusterip:默认模式,只能pod内部访问

externalName:需要dns提供域名

1.1、对外提供服务的ingress

service:网关的概念-----标签来匹配pod,还能通过endpoint更新pod的变化,集群内部的ip地址。也可以实现负载均衡,四层代理。

service暴露的端口只能用于内网访问,局域网。

loadbalance-------公有云--------提供负载均衡的ip-------公网地址。

Ingress

Ingress:在k8s当中,Ingress是一个独立的组件(deployment ns svc)独立的配置,只能通过yaml文件配置。不能命令行。

定义请求如何转发到service的规则。

ingress通过http或者https暴露内部的service,给service提供外部的url,负载均衡 SSL/TLS。基于域名的反向代理。

ingess通过ingress-controller来实现上述的功能。

ingress-controller不是k8s自带的组件,这是插件的统称。

k8s维护的插件类型

  • glogle云的GCE
  • Ingress-nginx-------最常用的模式
  • traefik--------------带可视化界面—ui界面—并发量只有ingress-nginx的流程。
流量转发示意图:

在这里插入图片描述

1.2、ingress-nginx暴露服务的方式:

  • 1、deployment+loadbalance------->service
  • 需要公有云提供负载均衡的ip地址---------公网地址。
  • 2、DaemonSet+HostNetwork + NodeSelector
  • ingress-controller会在每个节点部署一个pod,ingress-controller直接使用每个节点的80和443端口,直接实现流量的转发和访问。

NodeSelector用来选择设备优良,或者选择端口没被占用的节点。

DaemonSet+HostNetwork + NodeSelector模式:
  • 优点:
    使用宿主机端口,适合大并发的生产环境,性能是最好的
  • 缺点:
  • 和宿主机公用端口,一个node节点只能部署一个ingress-controller的pod

在这里插入图片描述

3、Deployment+nodePort模式:

nodePort--------->30000-------80—80

ingress根据副本数和调度在节点上部署多个pod。在根据nodePort在每个节点打开一个指定的端口 30000-32767

在这里插入图片描述

客户端--------->www.xy102.com------------->service-------------->nodeport---------->clusterip-------容器端口

1、这种模式优点:不占用宿主机的端口,配置简单使用于内部并发不大的访问。

2、缺点,性能差,多了一个nodeport还涉及nodeport的转发,实际上通过nat模式做地址转换,性能上有影响。

在这里插入图片描述

3、DaemonSet+HostNetwork + NodeSelector模式


-----------------同步操作--------------------------
[root@master01 opt]# tar -xf ingree.contro-0.30.0.tar.gz [root@master01 opt]# docker load -i ingree.contro-0.30.0.tar[root@master01 opt]# mkdir ingress
[root@master01 opt]# cd ingress/
[root@master01 ingress]# wget https://gitee.com/mirrors/ingress-nginx/raw/0.30.0/deploy/static/mandatory.yaml
-------------------结束同步---------------------[root@master01 ingress]# vim mandatory.yaml apiVersion: apps/v1
191 #kind: Deployment
192 kind: DaemonSet
metadata:name: nginx-ingress-controllernamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
spec:
200 #  replicas: 1219       hostNetwork: true[root@master01 ingress]# kubectl apply -f mandatory.yaml [root@master01 ingress]# kubectl get pod -o wide -n ingress-nginx 
NAME                             READY   STATUS    RESTARTS   AGE   IP               NODE       NOMINATED NODE   READINESS GATES
nginx-ingress-controller-27lvf   1/1     Running   0          23s   192.168.168.81   master01   <none>           <none>
nginx-ingress-controller-29ckx   1/1     Running   0          23s   192.168.168.83   node02     <none>           <none>
nginx-ingress-controller-kn8ww   1/1     Running   0          23s   192.168.168.82   node01     <none>           <none>
---------------开启同步-------------------------
打开同步查看80+443端口
[root@master01 ingress]# netstat -antp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22509/nginx: master 
tcp        0      0 0.0.0.0:8181            0.0.0.0:*               LISTEN      22509/nginx: master 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      22509/nginx: master 
[root@node01 ingress]# netstat -antp | grep nginx[root@node02 ingress]# netstat -antp | grep nginx8181 端口是nginx-controller的默认配置,当ingress没有资源可以匹配时,会自动转发到这个端口。
---------------------查看节点端口开放----------------[root@master01 ingress]# kubectl explain ingress
KIND:     Ingress
VERSION:  networking.k8s.io/v1[root@master01 ingress]# vim ingress-nginx1.yamlapiVersion: v1
kind: PersistentVolumeClaim
metadata:name: nfs-pvc
spec:accessModes:- ReadWriteManystorageClassName: nfs-client-storageclassresources:requests:storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-applabels:app: nginx
spec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.22ports:- containerPort: 80volumeMounts:- name: nfs-pvcmountPath: /usr/share/nginx/htmlvolumes:- name: nfs-pvcpersistentVolumeClaim:claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:name: nginx-daemon-svc
spec:type: ClusterIPports:- protocol: TCPport: 80targetPort: 80selector:app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-daemon-ingress
spec:rules:- host: www.xy102.comhttp:paths:- path: /pathType: Prefix
#前缀匹配,匹配/ /test1 /test1/test2backend:
#匹配的svc的名称----podservice:name: nginx-daemon-svcport:number: 80[root@master01 ingress]# kubectl apply -f ingress-nginx1.yaml [root@k8s5 k8s]# ll
总用量 0
drwxrwxrwx. 2 root root  6 9月  10 10:34 default-nfs-pvc-pvc-8e552463-1055-4d12-9fcf-1f0da12cf3d9
drwxrwxrwx. 2 root root 62 9月   8 16:55 default-redis-data-redis-master-0-pvc-4c38e65b-5e5d-45c5-a58d-6d7c0bd69b39
drwxrwxrwx. 2 root root 62 9月   8 16:55 default-redis-data-redis-replica-0-pvc-eabc2e78-7b0c-4c72-ac16-bf44eca0d524
drwxrwxrwx. 2 root root 62 9月   8 16:43 default-redis-data-redis-replica-1-pvc-d5b0e813-8bed-4b00-8df6-69ad648ecc2c
[root@k8s5 k8s]# rm -rf default-redis-data-redis-*
[root@k8s5 k8s]# ll
总用量 0
drwxrwxrwx. 2 root root 6 9月  10 10:34 default-nfs-pvc-pvc-8e552463-1055-4d12-9fcf-1f0da12cf3d9
[root@k8s5 k8s]# cd default-nfs-pvc-pvc-8e552463-1055-4d12-9fcf-1f0da12cf3d9/
[root@k8s5 default-nfs-pvc-pvc-8e552463-1055-4d12-9fcf-1f0da12cf3d9]# ls
[root@k8s5 default-nfs-pvc-pvc-8e552463-1055-4d12-9fcf-1f0da12cf3d9]# echo 123 > index.html[root@master01 ingress]# vim /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.168.81 master01 www.xy102.com
192.168.168.82 node01
192.168.168.83 node02
192.168.168.84 hub.test.com
192.168.168.85 k8s5[root@master01 ingress]# curl www.xy102.com
123[root@node01 ingress]# vim /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.168.81 master01 www.xy102.com[root@node01 ingress]# curl www.xy102.com
123[root@node02 ingress]# vim /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.168.81 master01 www.xy102.com[root@node02 ingress]# curl www.xy102.com
123[root@k8s5 default-nfs-pvc-pvc-51fc1314-0c17-4f04-b539-d2508ac35ca3]# mkdir test1
[root@k8s5 default-nfs-pvc-pvc-51fc1314-0c17-4f04-b539-d2508ac35ca3]# ll
总用量 4
-rw-r--r--. 1 root root 4 9月  10 11:51 index.html
drwxr-xr-x. 2 root root 6 9月  10 12:32 test1
[root@k8s5 default-nfs-pvc-pvc-51fc1314-0c17-4f04-b539-d2508ac35ca3]# cd test1/
[root@k8s5 test1]# echo 456 > index.html
[root@k8s5 test1]# [root@master01 ingress]# curl www.xy102.com/test1
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.22.1</center>
</body>
</html>
[root@master01 ingress]# curl -L www.xy102.com/test1
456[root@k8s5 test1]# pwd
/opt/k8s/default-nfs-pvc-pvc-51fc1314-0c17-4f04-b539-d2508ac35ca3/test1
[root@k8s5 test1]# ll
总用量 4
-rw-r--r--. 1 root root 4 9月  10 12:32 index.html
[root@k8s5 test1]# mkdir test2
[root@k8s5 test1]# cd test2/
[root@k8s5 test2]# echo 789 > index.html[root@master01 ingress]# curl -L www.xy102.com/test1/test2
789
-----------------------------------------------------------------------------------------------------------------DaemonSet+HostNetwork+NodeSelector模式----------------------------
##节点选择NodeSelector模式
[root@master01 ingress]# vim mandatory.yaml 190 apiVersion: apps/v1
191 #kind: Deployment
192 kind: DaemonSet
193 metadata:
194   name: nginx-ingress-controller
195   namespace: ingress-nginx
196   labels:
197     app.kubernetes.io/name: ingress-nginx
198     app.kubernetes.io/part-of: ingress-nginx
199 spec:
200 #  replicas: 1
201   selector:
202     matchLabels:
203       app.kubernetes.io/name: ingress-nginx
204       app.kubernetes.io/part-of: ingress-nginx
205   template:
206     metadata:
207       labels:
208         app.kubernetes.io/name: ingress-nginx
209         app.kubernetes.io/part-of: ingress-nginx
210       annotations:
211         prometheus.io/port: "10254"
212         prometheus.io/scrape: "true"
213     spec:
214       # wait up to five minutes for the drain of connections
215       terminationGracePeriodSeconds: 300
216       serviceAccountName: nginx-ingress-serviceaccount
217       nodeSelector:
218         kubernetes.io/os: linux
219       hostNetwork: true
220       nodeSelector:
221         ingress: "true"[root@master01 ingress]# kubectl get nodes --show-labels 
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   14d   v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 14d   v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,memory=1000,test1=a,test3=b
node02     Ready    <none>                 14d   v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b,xy102=98打上ingress=true标签
[root@master01 ingress]# kubectl label nodes node01 ingress=true
node/node01 labeled
[root@master01 ingress]# kubectl get nodes --show-labels 
NAME       STATUS   ROLES                  AGE   VERSION    LABELS
master01   Ready    control-plane,master   14d   v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=
node01     Ready    <none>                 14d   v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,ingress=true,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,memory=1000,test1=a,test3=b
node02     Ready    <none>                 14d   v1.20.15   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,test2=b,xy102=98[root@master01 ingress]# kubectl apply -f mandatory.yaml [root@master01 ingress]# kubectl get pod -o wide -n ingress-nginx
NAME                             READY   STATUS    RESTARTS   AGE   IP               NODE     NOMINATED NODE   READINESS GATES
nginx-ingress-controller-p52jc   1/1     Running   0          11s   192.168.168.82   node01   <none>           <none>[root@node01 ingress]# curl www.xy102.com
curl: (7) Failed connect to www.xy102.com:80; 拒绝连接
[root@node01 ingress]# vim /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.168.82 node01 www.xy102.com[root@node01 ingress]# curl www.xy102.com
123
[root@node01 ingress]# curl -L www.xy102.com/test1/test2
789
[root@node01 ingress]# curl -L www.xy102.com/test1
456

4、基于deployment+nodeport

[root@master01 ingress]# kubectl delete -f mandatory.yaml [root@master01 ingress]# vim mandatory.yaml190 apiVersion: apps/v1
191 kind: Deployment
192 #kind: DaemonSet
193 metadata:
194   name: nginx-ingress-controller
195   namespace: ingress-nginx
196   labels:
197     app.kubernetes.io/name: ingress-nginx
198     app.kubernetes.io/part-of: ingress-nginx
199 spec:
200   replicas: 1
201   selector:
202     matchLabels:
203       app.kubernetes.io/name: ingress-nginx
204       app.kubernetes.io/part-of: ingress-nginx
205   template:
206     metadata:
207       labels:
208         app.kubernetes.io/name: ingress-nginx
209         app.kubernetes.io/part-of: ingress-nginx
210       annotations:
211         prometheus.io/port: "10254"
212         prometheus.io/scrape: "true"
213     spec:
214       # wait up to five minutes for the drain of connections
215       terminationGracePeriodSeconds: 300
216       serviceAccountName: nginx-ingress-serviceaccount
217       nodeSelector:
218         kubernetes.io/os: linux
219 #      hostNetwork: true
220 #      nodeSelector:
221 #        ingress: "true"wget https://gitee.com/mirrors/ingress-nginx/raw/nginx-0.30.0/deploy/static/provider/baremetal/service-nodeport.yaml[root@master01 ingress]# kubectl apply -f mandatory.yaml [root@master01 ingress]# kubectl get pod -o wide -n ingress-nginx
NAME                                        READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
nginx-ingress-controller-54b86f8f7b-4qszc   1/1     Running   0          2m15s   10.244.2.239   node02   <none>           <none>[root@master01 ingress]# kubectl get svc -o wide -n ingress-nginx
NAME            TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE   SELECTOR
ingress-nginx   NodePort   10.96.183.19   <none>        80:31185/TCP,443:32676/TCP   19s   app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/part-of=ingress-nginx[root@master01 ingress]# netstat -antp | grep 31185
tcp        0      0 0.0.0.0:31185           0.0.0.0:*               LISTEN      28697/kube-proxy [root@node01 ingress]# netstat -antp | grep 31185
tcp        0      0 0.0.0.0:31185           0.0.0.0:*               LISTEN      20187/kube-proxy  [root@node02 ingress]# netstat -antp | grep 31185
tcp        0      0 0.0.0.0:31185           0.0.0.0:*               LISTEN      44530/kube-proxy  [root@master01 ingress]# vim ingress-nginx1.yaml apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: nfs-pvc
spec:accessModes:- ReadWriteManystorageClassName: nfs-client-storageclassresources:requests:storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-applabels:app: nginx
spec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.22ports:- containerPort: 80volumeMounts:- name: nfs-pvcmountPath: /usr/share/nginx/htmlvolumes:- name: nfs-pvcpersistentVolumeClaim:claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:name: nginx-deployment-svc
spec:type: ClusterIPports:- protocol: TCPport: 80targetPort: 80selector:app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-deployment-ingress
spec:rules:- host: www.xy102.comhttp:paths:- path: /pathType: Prefix
#前缀匹配,匹配/ /test1 /test1/test2backend:
#匹配的svc的名称----podservice:name: nginx-deployment-svcport:number: 80[root@master01 ingress]# kubectl apply -f ingress-nginx1.yaml [root@master01 ingress]# curl www.xy102.com:31185
123

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

5、https

[root@master01 ingress]# mkdir https
[root@master01 ingress]# cd https/
[root@master01 https]# ls
[root@master01 https]# openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=CHINA/O=NJ" 
Generating a 2048 bit RSA private key
.............................+++
...+++
writing new private key to 'tls.key'
-----
##解释
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=CHINA/O=NJ"req:表示指定证书请求和生成相关文件
-x509:生成自签名的x.509证书
-sha256:sha-256的散列算法
-nodes:生成的私钥不加密
-days 365: 证书的有效期为365天
-newkey rsa:2048::表示使用RSA的密钥队,长度2048个单位
-keyout tls.key -out tls.cr:生成两个文件
-keyout 私钥保存到tls.key文件
-out 保存证书到tls.crt
-subj 添加证书的主题[root@master01 https]# kubectl create secret tls tls.secret --key tls.key --cert tls.crt[root@master01 https]# kubectl create secret tls(指定type) tls.secret --key(指定密钥) tls.key --cert(指定证书) tls.crt [root@master01 ingress]# vim ingress-nginx1.yaml55 apiVersion: networking.k8s.io/v156 kind: Ingress57 metadata:58   name: nginx-deployment-ingress59 spec:60   tls:61     - hosts:62       - www.xy102.com63       secretName: tls.secret64 #指定加密通信的域名,上下文一直,指定secret加密的名称,获取私钥和证书[root@master01 ingress]# kubectl apply -f ingress-nginx1.yaml
[root@master01 ingress]# curl -k https://www.xy102.com:32676
123

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

作业:

#daemonset+hostnetwork实现https访问。

[root@master01 ingress]# vim mandatory.yaml 190 apiVersion: apps/v1
191 #kind: Deployment
192 kind: DaemonSet
193 metadata:
194   name: nginx-ingress-controller
195   namespace: ingress-nginx
196   labels:
197     app.kubernetes.io/name: ingress-nginx
198     app.kubernetes.io/part-of: ingress-nginx
199 spec:
200 #  replicas: 1
201   selector:
202     matchLabels:
203       app.kubernetes.io/name: ingress-nginx
204       app.kubernetes.io/part-of: ingress-nginx
205   template:
206     metadata:
207       labels:
208         app.kubernetes.io/name: ingress-nginx
209         app.kubernetes.io/part-of: ingress-nginx
210       annotations:
211         prometheus.io/port: "10254"
212         prometheus.io/scrape: "true"
213     spec:
214       # wait up to five minutes for the drain of connections
215       terminationGracePeriodSeconds: 300
216       serviceAccountName: nginx-ingress-serviceaccount
217       nodeSelector:
218         kubernetes.io/os: linux
219       hostNetwork: true
220 #      nodeSelector:
221 #        ingress: "true"
222       containers:[root@master01 ingress]# kubectl apply -f mandatory.yaml [root@master01 ingress]# vim ingress-nginx1.yamlapiVersion: v1
kind: PersistentVolumeClaim
metadata:name: nfs-pvc
spec:accessModes:- ReadWriteManystorageClassName: nfs-client-storageclassresources:requests:storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-applabels:app: nginx
spec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.22ports:- containerPort: 80volumeMounts:- name: nfs-pvcmountPath: /usr/share/nginx/htmlvolumes:- name: nfs-pvcpersistentVolumeClaim:claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:name: nginx-daemon-svc
spec:type: ClusterIPports:- protocol: TCPport: 80targetPort: 80selector:app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-daemon-ingress
spec:tls:- hosts:- www.xy102.comsecretName: tls.secret
#指定加密通信的域名,上下文一直,指定secret加密的名称,获取私钥和证书rules:- host: www.xy102.comhttp:paths:- path: /pathType: Prefix
#前缀匹配,匹配/ /test1 /test1/test2backend:
#匹配的svc的名称----podservice:name: nginx-daemon-svcport:number: 80[root@master01 ingress]# kubectl apply -f ingress-nginx1.yaml 
persistentvolumeclaim/nfs-pvc created
deployment.apps/nginx-app created
service/nginx-daemon-svc unchanged
ingress.networking.k8s.io/nginx-daemon-ingress configured
[root@master01 ingress]# kubectl get pod -o wide -n ingress-nginx 
NAME                             READY   STATUS    RESTARTS   AGE     IP               NODE       NOMINATED NODE   READINESS GATES
nginx-ingress-controller-44ktd   1/1     Running   0          7m52s   192.168.168.83   node02     <none>           <none>
nginx-ingress-controller-ksjkr   1/1     Running   0          7m52s   192.168.168.81   master01   <none>           <none>
nginx-ingress-controller-z4lrr   1/1     Running   0          7m52s   192.168.168.82   node01     <none>           <none>##之前https已经创建
-----------------------------------------------------------------------------------------------------------------------------------
[root@master01 ingress]# mkdir https
[root@master01 ingress]# cd https/
[root@master01 https]# ls
[root@master01 https]# openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=CHINA/O=NJ" 
Generating a 2048 bit RSA private key
.............................+++
...+++
writing new private key to 'tls.key'
-----
##解释
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=CHINA/O=NJ"req:表示指定证书请求和生成相关文件
-x509:生成自签名的x.509证书
-sha256:sha-256的散列算法
-nodes:生成的私钥不加密
-days 365: 证书的有效期为365天
-newkey rsa:2048::表示使用RSA的密钥队,长度2048个单位
-keyout tls.key -out tls.cr:生成两个文件
-keyout 私钥保存到tls.key文件
-out 保存证书到tls.crt
-subj 添加证书的主题[root@master01 https]# kubectl create secret tls tls.secret --key tls.key --cert tls.crt[root@master01 https]# kubectl create secret tls(指定type) tls.secret --key(指定密钥) tls.key --cert(指定证书) tls.crt [root@master01 ingress]# vim ingress-nginx1.yaml55 apiVersion: networking.k8s.io/v156 kind: Ingress57 metadata:58   name: nginx-deployment-ingress59 spec:60   tls:61     - hosts:62       - www.xy102.com63       secretName: tls.secret64 #指定加密通信的域名,上下文一直,指定secret加密的名称,获取私钥和证书[root@master01 ingress]# kubectl apply -f ingress-nginx1.yaml
[root@master01 ingress]# curl -k https://www.xy102.com:32676
123----------------------------------------------------------------------------------------------------------------------------------[root@master01 ingress]# curl www.xy102.com
<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx/1.17.8</center>
</body>
</html>[root@k8s5 k8s]# cd default-nfs-pvc-pvc-6a14c29f-4ba6-48e2-9f22-bc3dee4b2feb/
[root@k8s5 default-nfs-pvc-pvc-6a14c29f-4ba6-48e2-9f22-bc3dee4b2feb]# ll
总用量 0
[root@k8s5 default-nfs-pvc-pvc-6a14c29f-4ba6-48e2-9f22-bc3dee4b2feb]# echo 123 > index.html[root@master01 ingress]# curl -Lk https://www.xy102.com
123[root@k8s5 default-nfs-pvc-pvc-6a14c29f-4ba6-48e2-9f22-bc3dee4b2feb]# mkdir test1
[root@k8s5 default-nfs-pvc-pvc-6a14c29f-4ba6-48e2-9f22-bc3dee4b2feb]# cd test1/
[root@k8s5 test1]# echo 456 > index.html[root@master01 ingress]# curl -Lk https://www.xy102.com/test1
456[root@master01 ingress]# curl -Lk https://www.xy102.com/test1/test2
789

相关文章:

91、K8s之ingress上集

一、Ingress service模式&#xff1a; loadbalance NodePort&#xff1a;每个节点都会有一个指定的端口 30000-32767 内网 clusterip&#xff1a;默认模式&#xff0c;只能pod内部访问 externalName&#xff1a;需要dns提供域名 1.1、对外提供服务的ingress service&…...

NISP 一级 | 2.1 密码学

关注这个证书的其他相关笔记&#xff1a;NISP 一级 —— 考证笔记合集-CSDN博客 通过上一章的学习&#xff0c;我们知道了&#xff0c;网络安全的 CIA 模型&#xff0c;而本期学习的“密码学”&#xff0c;则能为 CIA 模型提供很好的技术支持&#xff1a; 面临的攻击威胁所破坏…...

深度学习速通系列:混淆矩阵是什么

混淆矩阵&#xff08;Confusion Matrix&#xff09;是一种评估分类模型性能的工具&#xff0c;尤其在监督学习中用于分析分类结果。它通过一个矩阵的形式&#xff0c;将模型的预测结果与实际标签进行比较&#xff0c;从而可以清晰地看到模型在各个类别上的表现。以下是混淆矩阵…...

综合评价 | 基于熵权-变异系数-博弈组合法的综合评价模型(Matlab)

目录 效果一览基本介绍程序设计参考资料 效果一览 基本介绍 根据信息熵的定义&#xff0c;对于某项指标&#xff0c;可以用熵值来判断某个指标的离散程度&#xff0c;其信息熵值越小&#xff0c;指标的离散程度越大&#xff0c; 该指标对综合评价的影响&#xff08;即权重&…...

模板与泛型编程笔记(一)

1. 推荐书籍 《C新经典 模板与泛型编程》难得的很容易看得懂的好书&#xff0c;作者讲技术不跳跃&#xff0c;娓娓道来&#xff0c;只要花点时间就能看懂。 2. 笔记 模板为什么要用尖括号&#xff1f;因为便于编译器解析&#xff0c;可以将模板和普通函数声明分开。其实尖括…...

ubuntu 和windows用samba服务器实现数据传输

1&#xff0c;linux安装samba服务器 sudo apt-get install samba samba-common 2&#xff0c;linux 配置权限&#xff0c;修改目录权限&#xff0c;linux下共享的文件权限设置。 sudo chmod 777 /home/lark -R 3. 添加samba用户 sudo smbpasswd -a lark 4&#xff0c;配置共享…...

NISP 一级 | 3.2 网络安全威胁

关注这个证书的其他相关笔记&#xff1a;NISP 一级 —— 考证笔记合集-CSDN博客 网络安全威胁主要来自攻击者对网络及信息系统的攻击&#xff0c;攻击者可以通过网络嗅探、网络钓鱼、拒绝服务、远程控制、社会工程学等网络攻击手段&#xff0c;获得目标计算机的控制权&#xff…...

【技术实践】MySQL分表分库全解析:从理论到实战

文章目录 【技术实践】MySQL分表分库全解析&#xff1a;从理论到实战1. 引言1.1 MySQL数据库面临的挑战1.2 分表分库的概念与优势 2. MySQL分表分库的基本原理2.1 水平分表2.2 垂直分表2.3 水平分库2.4 分表分库的选择标准 3. 实现分表分库的技术方案3.1 中间件解决方案3.2 自定…...

动手学深度学习(一)简介+预备知识+基础知识(上)

一、简介 1、机器学习 机器学习研究如何使用经验改善计算机系统的性能。 2、表征学习 表征学习是机器学习的一类&#xff0c;研究的是&#xff0c;如何自动学习出数据合适的表示方式&#xff0c;更好地由输入得到正确的输出。 3、深度学习 深度学习是具有多级表示的表征学…...

dubbo 服务消费原理分析之应用级服务发现

文章目录 前言一、MigrationRuleListener1、迁移状态模型2、Provider 端升级3、Consumer 端升级4、服务消费选址5、MigrationRuleListener.onRefer6、MigrationRuleHandler.doMigrate6、MigrationRuleHandler.refreshInvoker7、MigrationClusterInvoker.migrateToApplicationFi…...

QT如何在对话框中插入表格

在Qt中&#xff0c;如果你想要在对话框中插入表格&#xff0c;通常会使用QTableWidget或QTableView结合QStandardItemModel&#xff08;对于QTableView&#xff09;或直接在QTableWidget中操作。这里&#xff0c;我将介绍如何使用QTableWidget在对话框中插入表格&#xff0c;因…...

如何使用SSHFS通过SSH挂载远程文件系统?

SHFS&#xff08;SSH 文件系统&#xff09;是一款功能强大的工具&#xff0c;它允许用户通过 SSH 挂载远程文件系统&#xff0c;从而提供一种安全便捷的方式来访问远程文件&#xff0c;就像访问本地文件一样。本文将引导您完成使用 SSHFS 挂载远程文件系统的过程&#xff0c;为…...

SEELE 框架是

SEELE 框架是一个相对新颖的组织管理和优化框架&#xff0c;旨在帮助团队或企业更好地实现目标。它的核心思想是通过科学的管理方法来提升组织的执行力和决策能力。以下是对 SEELE 框架的详细讲解&#xff0c;包括定义、内容、实施步骤、实施策略以及推荐的实践方法和工具。 一…...

高教社杯数模竞赛特辑论文篇-2013年B题:碎纸复原模型与算法(续)(附MATLAB代码实现)

目录 4.3 三维碎纸复原模型 4.3.1 三维模型的降维 4.3.2 三维碎纸复原算法 4.3.3 模型求解 五、模型改进与推广 5.1 模型优点 5.2 模型缺点 5.3 模型改进 5.3.1 适用彩色图片的改进 5.3.2 最小干预度算法 5.4 模型推广 参考文献 代码实现 模拟退火法代码 GUI 程序代码 层次特征…...

Java操作Miscrosoft Office各类文件格式的开源免费工具库

Aspose.Words库 是一个商业Java库&#xff0c;还封装了常用的word、pdf、防伪码、水印等诸多功能。Apache 库需要注意的前置问题 问题1&#xff1a;Word的两个格式doc和docx&#xff0c;POI并没有提供统一的处理类。分别用 HWPFDocument 处理doc文档&#xff0c;用 XWPFTempl…...

Redis 缓存淘汰算法策略详解

引言 Redis 作为一款高性能的内存数据库&#xff0c;在处理大量数据时&#xff0c;由于内存有限&#xff0c;需要在数据达到设定的内存上限后&#xff0c;使用缓存淘汰策略来决定哪些数据应该被移除&#xff0c;以腾出空间存储新的数据。这一过程被称为缓存淘汰&#xff0c;通…...

Kubernetes PV生命周期的四个阶段

Kubernetes PV生命周期的四个阶段 1. Available(可用)2. Bound(已绑定)3. Released(已释放)4. Failed(失败)💖The Begin💖点点关注,收藏不迷路💖 在Kubernetes中,PersistentVolume(PV)的生命周期主要包括以下四个阶段: 1. Available(可用) 状态:PV刚创建…...

Azure OpenAI models being unable to correctly identify model

题意&#xff1a;Azure OpenAI模型无法正确识别模型。 问题背景&#xff1a; In Azure OpenAI Studio, while I am able to deploy a GPT-4 instance, the responses are based solely on GPT-3.5 Turbo. I test the same prompts in my personal ChatGPT sub and it returns …...

项目小结二()

一.个人信息的界面 这里可以进行用户信息的修改&#xff0c;并渲染数据上去 二.这两天&#xff0c;出现的问题&#xff1a; 1.mybatis中 字段取别名 &#xff08;还没验证&#xff0c;是否正确&#xff09; 问题描述&#xff1a;由于实体类中的变量名&#xff0c;与数据库中…...

《论层次架构及其在软件系统中的应用》写作框架,软考高级系统架构设计师

论文真题 层次架构作为软件系统设计的一种基本模式,对于实现系统的模块化、可维护性和可扩展性具有至关重要的作用。在软件系统的构建过程中,采用层次架构不仅可以使系统结构更加清晰,还有助于提高开发效率和质量。因此,对层次架构的理解和应用是软件工程师必备的技能之一…...

19c补丁后oracle属主变化,导致不能识别磁盘组

补丁后服务器重启&#xff0c;数据库再次无法启动 ORA01017: invalid username/password; logon denied Oracle 19c 在打上 19.23 或以上补丁版本后&#xff0c;存在与用户组权限相关的问题。具体表现为&#xff0c;Oracle 实例的运行用户&#xff08;oracle&#xff09;和集…...

vscode里如何用git

打开vs终端执行如下&#xff1a; 1 初始化 Git 仓库&#xff08;如果尚未初始化&#xff09; git init 2 添加文件到 Git 仓库 git add . 3 使用 git commit 命令来提交你的更改。确保在提交时加上一个有用的消息。 git commit -m "备注信息" 4 …...

理解 MCP 工作流:使用 Ollama 和 LangChain 构建本地 MCP 客户端

&#x1f31f; 什么是 MCP&#xff1f; 模型控制协议 (MCP) 是一种创新的协议&#xff0c;旨在无缝连接 AI 模型与应用程序。 MCP 是一个开源协议&#xff0c;它标准化了我们的 LLM 应用程序连接所需工具和数据源并与之协作的方式。 可以把它想象成你的 AI 模型 和想要使用它…...

Python爬虫实战:研究feedparser库相关技术

1. 引言 1.1 研究背景与意义 在当今信息爆炸的时代,互联网上存在着海量的信息资源。RSS(Really Simple Syndication)作为一种标准化的信息聚合技术,被广泛用于网站内容的发布和订阅。通过 RSS,用户可以方便地获取网站更新的内容,而无需频繁访问各个网站。 然而,互联网…...

《通信之道——从微积分到 5G》读书总结

第1章 绪 论 1.1 这是一本什么样的书 通信技术&#xff0c;说到底就是数学。 那些最基础、最本质的部分。 1.2 什么是通信 通信 发送方 接收方 承载信息的信号 解调出其中承载的信息 信息在发送方那里被加工成信号&#xff08;调制&#xff09; 把信息从信号中抽取出来&am…...

GitHub 趋势日报 (2025年06月08日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...

BCS 2025|百度副总裁陈洋:智能体在安全领域的应用实践

6月5日&#xff0c;2025全球数字经济大会数字安全主论坛暨北京网络安全大会在国家会议中心隆重开幕。百度副总裁陈洋受邀出席&#xff0c;并作《智能体在安全领域的应用实践》主题演讲&#xff0c;分享了在智能体在安全领域的突破性实践。他指出&#xff0c;百度通过将安全能力…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)

UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中&#xff0c;UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化&#xf…...

sipsak:SIP瑞士军刀!全参数详细教程!Kali Linux教程!

简介 sipsak 是一个面向会话初始协议 (SIP) 应用程序开发人员和管理员的小型命令行工具。它可以用于对 SIP 应用程序和设备进行一些简单的测试。 sipsak 是一款 SIP 压力和诊断实用程序。它通过 sip-uri 向服务器发送 SIP 请求&#xff0c;并检查收到的响应。它以以下模式之一…...

VM虚拟机网络配置(ubuntu24桥接模式):配置静态IP

编辑-虚拟网络编辑器-更改设置 选择桥接模式&#xff0c;然后找到相应的网卡&#xff08;可以查看自己本机的网络连接&#xff09; windows连接的网络点击查看属性 编辑虚拟机设置更改网络配置&#xff0c;选择刚才配置的桥接模式 静态ip设置&#xff1a; 我用的ubuntu24桌…...