kubernetes Ingess 是有2部分组成,Ingress Controller 和Ingress服务组成,经常使用的Ingress Controller 是ingress-nginx,工做的原理是:nginx
Ingress Controller 会动态感知集群中的Ingress的规则变化,而后读取,动态生成Nginx的配置文件,最后注入到运行nginx的pod的中,而后会自动reload,配置生效。vim
用kubernetes Ingress 是因为它是7层调度,能够直接卸载https会话,代理的后端的pod能够直接使用明文的http协议。后端
而Service NodePort得类型,是4层得调度,作不到这点,然而如今https是一种趋势,因此在kubernetes 对外暴露服务得时候咱们仍是要选择Ingress。api
下面咱们来看下Ingress得部署:
原理图app
首先建立一个文件夹专门放置Igress得yaml得文件,mkdir ingress
vim myapp.yamlide
apiVersion: apps/v1 kind: Deployment metadata: name: myapp spec: replicas: 3 selector: matchLabels: app: myapp template: metadata: labels: app: myapp spec: containers: - name: myapp-ding image: ikubernetes/myapp:v2 --- apiVersion: v1 kind: Service metadata: name: myapp #等会ingress就靠这个来匹配 spec: selector: app: myapp type: ClusterIP ports: - port: 80 targetPort: 80
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-ding namespace: default annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: www.yang.com #虚拟机主机域名 http: paths: - path: backend: serviceName: myapp #代理后端的service 的name servicePort: 80 #后端service的端口