温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

k8s ingress-nginx 0.25.1 最新版部署和例子

发布时间:2020-07-06 22:17:06 来源:网络 阅读:1999 作者:295631788 栏目:系统运维

k8s ingress-nginx 0.25.1 最新版部署和例子

说明

https://github.com/kubernetes/ingress-nginx/blob/master/docs/deploy/index.md

增加了7层的识别能力,可以根据 http header, path 等进行路由转发

部署

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

sed -i 's#quay.io/kubernetes-ingress-controller/nginx-ingress-controller#registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller#g' mandatory.yaml

cat 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: 32080  #http
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP
      nodePort: 32443  #https
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
kubectl create -f  mandatory.yaml
kubectl create -f  service-nodeport.yaml

检查

kubectl get pod -n ingress-nginx -o wide

kubectl scale --replicas=2  deploy/nginx-ingress-controller -n ingress-nginx

例子

vim  deploy-demo.yaml
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    app: myapp
    release: stable
  ports:
  - name: myapp
    port: 80
    targetPort: 80
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    matchLabels:
      app: myapp
      release: stable
   replicas: 3
   template:
     metadata:
       labels:
         app: myapp
         release: stable
      spec:
        containers:
        - name: myapp
          image: nginx
          imagePullPolicy: IfNotPresent
        ports:
        - name: myapp
      containerPort: 80

vim  ingress-myapp.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myapp
namespace: default
annotations:
   kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: httpd.hequan.com
    http:
     paths:
     - path:
       backend:
        serviceName: myapp
        servicePort: 80

kubectl create -f  deploy-demo.yaml
kubectl create -f  ingress-myapp.yaml

 
#修改hosts   node节点ip
192.168.100.112   httpd.hequan.com  

访问 httpd.hequan.com:32080
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI