在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
前言
一、部署配置Ingress1、获取配置文件 #文件已下载到本地 https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0/deploy 2、准备镜像 unzip ingress-nginx-nginx-0.20.0.zip cd ingress-nginx-nginx-0.20.0/deploy/ vim mandatory.yaml #其他文件的集合 #编辑mandatory.yaml文件,将defaultbackend镜像地址改成阿里云的镜像地址(如下图) image: registry.cn-hangzhou.aliyuncs.com/allinpay/defaultbackend-amd64:v1.5 3、安装 kubectl apply -f mandatory.yaml #稍等片刻,使用下列命令查询 kubectl get namespace kubectl get pods -n ingress-nginx 4、创建后端pod和service (pod-B、service-B) vim deploy-demo.yaml apiVersion: v1 kind: Service metadata: name: myapp namespace: default spec: selector: app: myapp release: canary ports: - name: http targetPort: 80 port: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: myapp-deploy namespace: default spec: replicas: 3 selector: matchLabels: app: myapp release: canary template: metadata: labels: app: myapp release: canary spec: containers: - name: myapp image: ikubernetes/myapp:v2 ports: - name: http containerPort: 80 #应用配置 kubectl apply -f deploy-demo.yaml #查看 kubectl get pods 5、创建service-A vim service-nodeport.yaml apiVersion: v1 kind: Service metadata: name: ingress-nginx namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx spec: type: NodePort ports: - name: http port: 80 targetPort: 80 protocol: TCP nodePort: 30080 - name: https port: 443 targetPort: 443 protocol: TCP nodePort: 30443 selector: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx #应用配置 kubectl apply -f service-nodeport.yaml #查看 kubectl get svc -n ingress-nginx 在外部浏览器中中访问:ip:30080
6、定义ingress规则
vim ingress-myapp.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-myapp namespace: default annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: myapp.magedu.com http: paths: - path: backend: serviceName: myapp servicePort: 80
#应用配置 kubectl apply -f ingress-myapp.yaml 在外部主机上配置好host文件 然后在浏览器中再访问,发现已经可以访问到后端pod了 二、使用https1、创建k8s证书(要注意和后端的pod使用相同的namespace) kubectl -n default create secret tls ingress-test --key /home/centos/cert/cash432.key --cert /home/centos/cert/cash432.crt 2、创建ingress规则
vim ingress-myapp-cash432.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-myapp namespace: default annotations: kubernetes.io/ingress.class: "nginx" kubernetes.io/secure-backends: "true" kubernetes.io/ssl-passthrough: "true" spec: tls: - hosts: - myapp.cash432.xyz secretName: ingress-test rules: - host: myapp.cash432.xyz http: paths: - path: backend: serviceName: myapp servicePort: 80 #应用配置 kubectl apply -f ingress-myapp-cash432.yaml 浏览器访问 到此这篇关于k8s部署ingress-nginx的方法步骤的文章就介绍到这了,更多相关k8s部署ingress-nginx内容请搜索极客世界以前的文章或继续浏览下面的相关文章希望大家以后多多支持极客世界! |
请发表评论