kubernetes之部署traefik-ingress分为http和https
1 理解Ingress
2 理解Ingress Controller
3 RBAC
在 RBAC API 的四个重要概念:
4 部署traefik
$ cat ingress-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: ingress
namespace: kube-system --- kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: ingress
subjects:
- kind: ServiceAccount
name: ingress
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
4.2 创建DaemonSet
4.2.1 创建节点标签
kubectl label nodes 172.19.8.114 edgenode=true
kubectl label nodes 172.19.8.115 edgenode=true
4.2.2 部署traefik-ingress-controller.yml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: traefik-ingress-lb
namespace: kube-system
labels:
k8s-app: traefik-ingress-lb
spec:
template:
metadata:
labels:
k8s-app: traefik-ingress-lb
name: traefik-ingress-lb
spec:
terminationGracePeriodSeconds: 60
hostNetwork: true
restartPolicy: Always
serviceAccountName: ingress
containers:
- image: traefik
name: traefik-ingress-lb
resources:
limits:
cpu: 200m
memory: 30Mi
requests:
cpu: 100m
memory: 20Mi
ports:
- name: http
containerPort: 80
hostPort: 80
- name: admin
containerPort: 8080
hostPort: 8080
args:
- --web
- --web.address=:8080
- --kubernetes
- --insecureskipverify
nodeSelector:
edgenode: "true"
4.3 配置traefik UI
$ cat ui.yaml
apiVersion: v1
kind: Service
metadata:
name: traefik-web-ui
namespace: kube-system
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- name: web
port: 80
targetPort: 8580
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-web-ui
namespace: kube-system
spec:
rules:
- host: traefikui.test.com
http:
paths:
- path: /
backend:
serviceName: traefik-web-ui
servicePort: web
配置完成后就可以启动treafik ui ingress了。
4.3.1 访问测试
5 配置traefik支持https
5.1 https介绍
client --- (via https) ---> traefik ---- (via http) ----> services
2、 client与traefik间采用https加密通信,但traefik与svc也是采用https通信
client --- (via https) ---> traefik ---- (via https) ----> services
5.2 配置证书
# mkdir /etc/kubernetes/ssl/
# cd /etc/kubernetes/ssl/
# 将证书存放在此目录
# ls
pt1.20201216.key pt1.20201216.pem
5.3 创建secret,保存https证书,注意操作目录,如果不是在此目录下操作,须指定绝对路径,同时配置traefik多域名证书形式,traefik能够自动识别证书
[root@node-01 ssl]# kubectl create secret generic traefik-cert --from-file=/etc/kubernetes/ssl/pt1.20201216.key --from-file=/etc/kubernetes/ssl/pt1.20201216.pem
--from-file=/etc/kubernetes/ssl/pt2.20201216.key --from-file=/etc/kubernetes/ssl/pt2.20201216.pem
-n kube-system
5.4 创建configmap,保存traefik配置
说明:此处两种配置方式,1.所有http请求全部rewrite为https。2.区分http和https两种请求。此处使用第二种
# 1.所有http请求全部rewrite为https
[root@node-01 traefik]# cat traefik.toml
defaultEntryPoints = ["http","https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/etc/kubernetes/ssl/pt1.20201216.pem"
keyFile = "/etc/kubernetes/ssl/pt1.20201216.key"
[[entryPoints.https.tls.certificates]]
certFile = "/etc/kubernetes/ssl/pt2.20201216.pem"
keyFile = "/etc/kubernetes/ssl/pt2.20201216.key"
# 2.区分http和https两种请求
[root@node-01 traefik]# cat traefik.toml
defaultEntryPoints = ["http","https"]
[entryPoints]
[entryPoints.http]
address = ":80"
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/etc/kubernetes/ssl/pt1.20201216.pem"
keyFile = "/etc/kubernetes/ssl/pt1.20201216.key"
[[entryPoints.https.tls.certificates]]
certFile = "/etc/kubernetes/ssl/pt2.20201216.pem"
keyFile = "/etc/kubernetes/ssl/pt2.20201216.key"
[root@node-01 traefik]# kubectl create configmap traefik-conf --from-file=traefik.toml -n kube-system
查看创建的configmap
[root@node-01 traefik]# kubectl get configmap traefik-conf -o yaml -n kube-system
apiVersion: v1
data:
traefik.toml: |
defaultEntryPoints = ["http","https"]
[entryPoints]
[entryPoints.http]
address = ":80"
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/etc/kubernetes/ssl/pt1.20201216.pem"
keyFile = "/etc/kubernetes/ssl/pt1.20201216.key"
[[entryPoints.https.tls.certificates]]
certFile = "/etc/kubernetes/ssl/pt2.20201216.pem"
keyFile = "/etc/kubernetes/ssl/pt2.20201216.key"
kind: ConfigMap
metadata:
creationTimestamp: "2019-05-07T11:31:07Z"
name: traefik-conf
namespace: kube-system
resourceVersion: "222740"
selfLink: /api/v1/namespaces/kube-system/configmaps/traefik-conf
uid: 9b315499-70bb-11e9-9a10-fa0caed1a100
5.5 部署traefik,这里主要是要关联创建的secret和configmap,并挂载到pod中的目录。
5.5.1 为主机打标签,确定traefik部署在哪些node上面
kubectl label nodes 172.19.8.114 edgenode=true
kubectl label nodes 172.19.8.115 edgenode=true
5.5.2 由于k8s启用了rbac,因此需要创建权限
[root@node-01 traefik]# cat ingress-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik-ingress-controller
namespace: kube-system --- kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
name: traefik-ingress-controller
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
我们使用DaemonSet类型来部署Traefik,并使用nodeSelector来限定Traefik所部署的主机。
[root@node-01 traefik]# cat traefik-deployment.yaml
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
name: traefik-ingress-controller
namespace: kube-system
labels:
k8s-app: traefik-ingress-lb
spec:
selector:
matchLabels:
k8s-app: traefik-ingress-lb
template:
metadata:
labels:
k8s-app: traefik-ingress-lb
name: traefik-ingress-lb
spec:
serviceAccountName: traefik-ingress-controller
terminationGracePeriodSeconds: 60
hostNetwork: true
volumes:
- name: ssl
secret:
secretName: traefik-cert
- name: config
configMap:
name: traefik-conf
containers:
- image: traefik
name: traefik-ingress-lb
volumeMounts:
- mountPath: "/etc/kubernetes/ssl"
name: "ssl"
- mountPath: "/config"
name: "config"
resources:
limits:
cpu: 200m
memory: 300Mi
requests:
cpu: 100m
memory: 200Mi
ports:
- name: http
containerPort: 80
hostPort: 80
- name: https
containerPort: 443
hostPort: 443
- name: admin
containerPort: 8080
hostPort: 8080
args:
- --api
- --kubernetes
- --configfile=/config/traefik.toml
- --insecureskipverify
nodeSelector:
edgenode: "true" #指定部署traefik的主机标签
---
kind: Service
apiVersion: v1
metadata:
name: traefik-ingress-service
namespace: kube-system
spec:
selector:
k8s-app: traefik-ingress-lb
ports:
- protocol: TCP
port: 80
name: web
- protocol: TCP
port: 443
name: https
- protocol: TCP
port: 8080
name: admin
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-web-ui
namespace: kube-system
spec:
rules:
- host: traefikui.test.com
http:
paths:
- path: /
backend:
serviceName: traefik-ingress-service
servicePort: admin
volumes用来引用创建的secret和configmap,volumeMounts 指定将引用的secret和configmap挂载到什么位置。
5.5.3 检查创建的traefik ui
[root@node-01 traefik]# kubectl get pods -A |grep trae
kube-system traefik-ingress-controller-6q7hx 1/1 Running 0 14h
kube-system traefik-ingress-controller-wgr7d 1/1 Running 0 14h
[root@node-01 traefik]# kubectl logs -f traefik-ingress-controller-wgr7d -n kube-system
6 实战小测
[root@node-01 testnginx]# cat test-nginx.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 1
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 443
---
apiVersion: v1
kind: Service
metadata:
name: my-nginx
labels:
app: my-nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
app: my-nginx
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-nginx
spec:
rules:
- host: test.test.com
http:
paths:
- backend:
serviceName: my-nginx
servicePort: 80
path: /
tls:
- hosts:
- test.test.com
[root@node-01 ~]# cat kubernetes-dashboard-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: kube-ui
namespace: kube-system
spec:
rules:
- host: k8sui.ptengine.jp
http:
paths:
- path: '/'
backend:
serviceName: kubernetes-dashboard
servicePort: 443
kubernetes之部署traefik-ingress分为http和https的更多相关文章
- Kubernets二进制安装(16)之安装部署traefik(ingress)
K8S的DNS实现了服务在集群"内"被自动发现,如何使得服务在Kuberneters集群"外"被使用和访问呢,有二种方法 1)使用NodePort型的Servi ...
- 实操教程丨如何在K8S集群中部署Traefik Ingress Controller
注:本文使用的Traefik为1.x的版本 在生产环境中,我们常常需要控制来自互联网的外部进入集群中,而这恰巧是Ingress的职责. Ingress的主要目的是将HTTP和HTTPS从集群外部暴露给 ...
- kubernetes 部署 traefik 以及kubernetes dashborad
前言 本来打算通过 traefik 来实现 kubernetes dashborad 的服务访问,可是在配置过程中始终报错.最后无奈只能通过nodeport来实现kubernetes dashbora ...
- Kubernetes 服务入口管理 Traefik Ingress Controller
前面部署了 kubernetes/ingress-nginx 作为 Ingress Controller,使用 Nginx 反向代理与负载,通过 Ingress Controller 不断的跟 Kub ...
- kubernetes Traefik ingress配置详解
理解Ingress 简单的说,ingress就是从kubernetes集群外访问集群的入口,将用户的URL请求转发到不同的service上.Ingress相当于nginx.apache等负载均衡方向代 ...
- Kubernetes 系列(三):Kubernetes使用Traefik Ingress暴露服务
一.Kubernetes 服务暴露介绍 从 kubernetes 1.2 版本开始,kubernetes提供了 Ingress 对象来实现对外暴露服务:到目前为止 kubernetes 总共有三种暴露 ...
- 见异思迁:K8s 部署 Nginx Ingress Controller 之 kubernetes/ingress-nginx
前天才发现,区区一个 nginx ingress controller 竟然2个不同的实现.一个叫 kubernetes/ingress-nginx ,是由 kubernetes 社区维护的,对应的容 ...
- 把H2数据库从jar包部署到Kubernetes,并解决Ingress不支持TCP的问题
1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! H2 Database是一个优秀的数据库,又小又方便,支持内存和文件形式,经常会在测试.POC(proof of conce ...
- traefik ingress Controller使用
Kubernetes Ingress Kubernetes Ingress是路由规则的集合,这些规则控制外部用户如何访问Kubernetes集群中运行的服务. 在Kubernetes中,有三种方式可以 ...
随机推荐
- leetcode5225最大相等频率
题目 正整数数组nums,找到满足条件的最长前缀,返回其长度.该前缀满足:删除一个元素后,剩下的每个数字出现的次数相同. ps:如果删除后没有元素存在,也可以认为每个数字有相同的次数. 数组长度:[2 ...
- 终于做了一把MySQL调参boy
本文通过笔者经历的一个真实案例来介绍一个MySQL中的重要参数innodb_buffer_pool_size,希望能给大家带来些许收获,当遇到类似性能问题时可以多一种思考方式. 图片拍摄于大唐不夜城 ...
- ZOJ 3960:What Kind of Friends Are You?
What Kind of Friends Are You? Time Limit: 1 Second Memory Limit: 65536 KB Japari Park is a large zoo ...
- 为什么别人的 WordPress 网站那么快?
越来越多的人使用 WordPress 来搭建网站了,W3techs 最新数据统计显示[1],截止到2021年11月3日,全网有43.0%的网站都是基于WordPress 搭建的.那么问题来了,为什么别 ...
- vue项目在ie浏览器下报语法错误
错误如下: 1.用vue 写的项目最多可以兼容到IE9 及以上版本 2.使用babel-polyfill做兼容npm install babel-polyfill --save-dev 安装之后如果发 ...
- [平台建设] Spark任务的诊断调优
背景 平台目前大多数任务都是Spark任务,用户在提交Spark作业的时候都要进行的一步动作就是配置spark executor 个数.每个executor 的core 个数以及 executor 的 ...
- Blazor组件的new使用方式与动态弹窗
1. 前言 在Blazor中的无状态组件文中,我提到了无状态组件中,有人提到这个没有diff,在渲染复杂model时,性能可能会更差.确实,这一点确实是会存在的.以上文的方式来实现无状态组件,确实只要 ...
- ssm项目使用过滤器出现4040错误
目录 问题 解决方法 (1)方法一 (2)方法二 问题 过滤器处理乱码问题 public class CharFilter implements Filter { @Override public v ...
- FastAPI快速查阅
官方文档主要侧重点是循序渐进地学习FastAPI, 不利于有其他框架使用经验的人快速查阅 故本文与官方文档不一样, 并补充了一些官方文档没有的内容 安装 包括安装uvicorn $pip instal ...
- 《Python核心编程第3版中文版》(高清).PDF,免费无需任何解压密码
链接:https://pan.baidu.com/s/18d3xinNX1oH5q8zpB10ABA 提取码:dx7h