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-controller
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
200 #  replicas: 1

219       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 nginx

8181 端口是nginx-controller的默认配置,当ingress没有资源可以匹配时,会自动转发到这个端口。
---------------------查看节点端口开放----------------

[root@master01 ingress]# kubectl explain ingress
KIND:     Ingress
VERSION:  networking.k8s.io/v1



[root@master01 ingress]# vim ingress-nginx1.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-client-storageclass
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.22
          ports:
            - containerPort: 80
          volumeMounts:
          - name: nfs-pvc
            mountPath: /usr/share/nginx/html
      volumes:
      - name: nfs-pvc
        persistentVolumeClaim:
          claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-daemon-svc
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-daemon-ingress
spec:
  rules:
  - host: www.xy102.com
    http:
      paths:
      - path: /
        pathType: Prefix
#前缀匹配,匹配/ /test1 /test1/test2
        backend:
#匹配的svc的名称----pod
          service:
            name: nginx-daemon-svc
            port:
              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/hosts

127.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/hosts

127.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/hosts

127.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/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.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.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"


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:
    - ReadWriteMany
  storageClassName: nfs-client-storageclass
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.22
          ports:
            - containerPort: 80
          volumeMounts:
          - name: nfs-pvc
            mountPath: /usr/share/nginx/html
      volumes:
      - name: nfs-pvc
        persistentVolumeClaim:
          claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-deployment-svc
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-deployment-ingress
spec:
  rules:
  - host: www.xy102.com
    http:
      paths:
      - path: /
        pathType: Prefix
#前缀匹配,匹配/ /test1 /test1/test2
        backend:
#匹配的svc的名称----pod
          service:
            name: nginx-deployment-svc
            port:
              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.yaml


 55 apiVersion: networking.k8s.io/v1
 56 kind: Ingress
 57 metadata:
 58   name: nginx-deployment-ingress
 59 spec:
 60   tls:
 61     - hosts:
 62       - www.xy102.com
 63       secretName: tls.secret
 64 #指定加密通信的域名,上下文一直,指定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.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-client-storageclass
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.22
          ports:
            - containerPort: 80
          volumeMounts:
          - name: nfs-pvc
            mountPath: /usr/share/nginx/html
      volumes:
      - name: nfs-pvc
        persistentVolumeClaim:
          claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-daemon-svc
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-daemon-ingress
spec:
  tls:
    - hosts:
      - www.xy102.com
      secretName: tls.secret
#指定加密通信的域名,上下文一直,指定secret加密的名称,获取私钥和证书
  rules:
  - host: www.xy102.com
    http:
      paths:
      - path: /
        pathType: Prefix
#前缀匹配,匹配/ /test1 /test1/test2
        backend:
#匹配的svc的名称----pod
          service:
            name: nginx-daemon-svc
            port:
              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.yaml


 55 apiVersion: networking.k8s.io/v1
 56 kind: Ingress
 57 metadata:
 58   name: nginx-deployment-ingress
 59 spec:
 60   tls:
 61     - hosts:
 62       - www.xy102.com
 63       secretName: tls.secret
 64 #指定加密通信的域名,上下文一直,指定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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/876152.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

线性规划------ + 案例 + Python源码求解(见文中)

目录 一、代数模型&#xff08;Algebraic Models&#xff09;详解1.1什么是代数模型&#xff1f;1.2代数模型的基本形式1.3 安装所需要的Python包--运行下述案例1.4代数模型的应用案例案例 1&#xff1a;市场供需平衡模型Python求解代码Python求解结果如下图&#xff1a; 案例 …

【快速解决】搭建VUE+VScode+elementUI开发环境,Vue环境配置

目录 1、通过这个之间下载node.js&#xff08;全选next即可&#xff09; 2、winr检验是否安装成功&#xff08;运行下面两个命令即可&#xff09; 3、将下面我给你的这个压缩包解压&#xff0c;然后放到空间足够的磁盘里面 4、【重点】设置环境变量 第一个变量路径里面长这…

ubuntu中QT+opencv在QLable上显示摄像头

ubuntu中QTopencv在QLable上显示摄像头 饭前的一篇文章吧&#xff0c;写完吃饭走 图像在机器视觉中的重要性是不可忽视的。机器视觉是指计算机利用图像处理技术进行图像识别、分析和理解的科学与技术领域。图像是机器视觉的输入数据&#xff0c;通过分析和处理图像&#xff0…

HTML中的文字与分区标记

1.font标记&#xff1a;用来设置文字的字体&#xff0c;大小&#xff0c;颜色&#xff0c;等属性 <!--font:font标记用来设置字体大小颜色属性size:设置字号&#xff0c;默认是3号&#xff0c;1表示4号&#xff0c;-1表示2号&#xff0c;取值范围是[1,7]或[-7,-1]color:设置…

Docker零基础入门

参考课程https://www.bilibili.com/video/BV1VC4y177re/?vd_source=b15169a302bee35f484245aecc69d4dd 参考书籍Docker 实践 - 面向 AI 开发人员的 Docker 实践 (dockerpractice.readthedocs.io) 1. 什么是Docker 1.1. Docker起源 随着计算机的发展,计算机上已经可以运行多…

C++ | Leetcode C++题解之第406题根据身高重建队列

题目&#xff1a; 题解&#xff1a; class Solution { public:vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {sort(people.begin(), people.end(), [](const vector<int>& u, const vector<int>& v) …

第108集《大佛顶首楞严经》

请打开讲义241面。我们讲到嗅报&#xff0c;鼻根当中嗅的功能。 本根发相 发明二相&#xff1a;一者通闻&#xff0c;被诸恶气&#xff0c;熏极心扰。二者塞闻&#xff0c;气掩不通&#xff0c;闷绝于地。 以鼻根造业到无间地狱以后&#xff0c;他有二种受苦的相状&#xf…

[C++] 剖析多态的原理及实现

文章目录 多态的概念及定义编译时多态&#xff08;静态多态&#xff09;运行时多态&#xff08;动态多态&#xff09;动态多态的原理示例&#xff1a;运行时多态 两种多态的区别 多态的实现基本条件虚函数虚函数的重写与覆盖虚函数重写的其他问题协变析构函数的重写 C11 中的 o…

引领智能家居新风尚,WTN6040F门铃解决方案——让家的呼唤更动听

在追求高效与便捷的智能家居时代&#xff0c;每一个细节都承载着我们对美好生活的向往。WTN6040F&#xff0c;作为一款专为现代家庭设计的低成本、高性能门铃解决方案&#xff0c;正以其独特的魅力&#xff0c;悄然改变着我们的居家生活体验。 芯片功能特点&#xff1a; 1.2.4…

直流电源纹波怎么测量?示波器的探头和带宽如何选择?

对于电源工程师来说&#xff0c;精确测量电源纹波是一项基本技能。本文将详细介绍直流电源纹波测试时的注意事项&#xff0c;包括示波器探头的选择、带宽设置、时基选择&#xff0c;确保精准测量直流电源纹波。 一、选择合适的示波器带宽 为了避免电路的高频噪声影响电源纹波的…

基于树莓派ubuntu20.04的ros-noetic小车

目录 一、小车的架构 1.1 总体的概述 1.2 驱动系统 1.3 控制系统 二、驱动系统开发 2.1 PC端Ubuntu20.04安装 2.2 树莓派Ubuntu20.04安装 2.3 PC端虚拟机设置静态IP 2.4 树莓派设置静态IP 2.5 树莓派启动ssh进行远程开发 2.5 arduino ide 开发环境搭建 2.5.1 PC…

C++: 二叉树进阶面试题

做每件事之前都心存诚意, 就会事半功倍. 目录 前言1. 根据二叉树创建字符串2. 二叉树的层序遍历Ⅰ3. 二叉树的层序遍历Ⅱ4. 二叉树的最近公共祖先5. 二叉搜索树与双向链表6. 根据一棵树的前序遍历与中序遍历构造二叉树7. 根据一棵树的中序遍历与后序遍历构造二叉树8. 二叉树的…

【数据结构】8——图3,十字链表,邻接多重表

数据结构8——图3&#xff0c;十字链表&#xff0c;邻接多重表 文章目录 数据结构8——图3&#xff0c;十字链表&#xff0c;邻接多重表前言一、十字链表结构例子 复杂例子 二、邻接多重表&#xff08;Adjacency Multilist&#xff09;例子 前言 除了之前的邻接矩阵和邻接表 …

在k8s中,客户端访问服务的链路流程,ingress--->service--->deployment--->pod--->container

图片来源&#xff1a;自己画的 ingress是一个API资源。 客户端访问ingress的不同url ingress给客户端返回不同的服务。 就和nginx反向代理服务器一样。 根据不同的url&#xff0c;给客户端返回不同的服务。 -----------------------------------------------------------…

MySql基础-单表操作

1. MYSQL概述 1.1 数据模型 关系型数据库 关系型数据库(RDBMS)&#xff1a;建立在关系模型基础上&#xff0c;由多张相互连接的二维表组成的数据库。 特点&#xff1a; 使用表存储数据&#xff0c;格式统一&#xff0c;便于维护 使用SQL语言操作&#xff0c;标准统一&…

班迪录屏和这三款录屏工具,一键操作,太方便了!

嘿&#xff0c;小伙伴们&#xff01;今天我要跟大家分享几款超棒的录屏工具&#xff0c;它们绝对是我们在工作和学习中不可或缺的好帮&#xff1b;这些工具功能强大且操作简单&#xff0c;下面就让我来详细介绍一下它们的使用体验和好用之处吧&#xff01; 班迪录屏工具使用体…

医学数据分析实训 项目二 数据预处理作业

文章目录 项目二 数据预处理一、实践目的二、实践平台三、实践内容任务一&#xff1a;合并数据集任务二&#xff1a;独热编码任务三&#xff1a;数据预处理任务四&#xff1a;针对“项目一 医学数据采集”中“3. 通过 UCI 机器学习库下载数据集”任务所下载的数据集进行预处理。…

新能源汽车BMS 学习笔记篇—AFE 菊花链通信中电容隔离 电感隔离的使用

在汽车高压BMS系统中&#xff0c;通常采用 CAN 总线或菊花链&#xff08;&#xff08;Daisy Chain&#xff09;架构。菊花链架构通过串行连接每个节点&#xff0c;通常只需要两条信号线穿过所有节点。相比之下&#xff0c;CAN总线通常需要多个并行连接到总线上&#xff0c;布线…

一些写leetcode的笔记

标准库中的string类没有实现像C#和Java中string类的split函数&#xff0c;所以想要分割字符串的时候需要我们自己手动实现。但是有了stringstream类就可以很容易的实现&#xff0c;stringstream默认遇到空格、tab、回车换行会停止字节流输出。 #include <sstream> #incl…

沉浸式体验Stability AI最新超强AI图片生成模型Ultra

2024年9月4日&#xff0c;亚马逊云科技在Amazon Bedrock上新了Stability AI最新的的三款文本图像生成模型&#xff1a;他们分别是Stable Image Ultra、Stable Diffusion 3 Large 和 Stable Image Core。全新的模型在处理多主题提示词、图像质量和图片排版上较上一代模型有显著提…