安装traefik
- 添加rbac
student@ubuntu:~/ingress$cat traefik-rbac.yaml
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
rules:
- apiGroups:
- ""
resources:
- services
- endpoints
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- ingresses
verbs:
- get
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
name: traefik-ingress-controller
namespace: kube-system
student@ubuntu:~/ingress$kubectl create -f traefik-rbac.yaml
clusterrole.rbac.authorization.k8s.io/traefik-ingress-controller created
clusterrolebinding.rbac.authorization.k8s.io/traefik-ingress-controller created
2.添加traefik ds
student@ubuntu:~/ingress$cat traefik-ds.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik-ingress-controller
namespace: kube-system
---
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
name: traefik-ingress-controller
namespace: kube-system
labels:
k8s-app: traefik-ingress-lb
spec:
template:
metadata:
labels:
k8s-app: traefik-ingress-lb
name: traefik-ingress-lb
spec:
serviceAccountName: traefik-ingress-controller
terminationGracePeriodSeconds: 60
hostNetwork: true
containers:
- image: traefik
name: traefik-ingress-lb
ports:
- name: http
containerPort: 80
hostPort: 80
- name: admin
containerPort: 8080
hostPort: 8080
volumeMounts:
- mountPath: "/ssl"
name: "ssl"
- mountPath: "/config"
name: "config"
args:
- --api
- --kubernetes
- --logLevel=INFO
# - --configfile=/config/traefik.toml
volumes:
- name: ssl
secret:
secretName: traefik-cert
- name: config
configMap:
name: traefik-conf
student@ubuntu:~/ingress$kubectl create -f traefik-ds.yaml
serviceaccount/traefik-ingress-controller created
3.添加ingress
student@ubuntu:~/ingress$cat nginx-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-nginx
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: nginx.xj.com
http:
paths:
- path: /
backend:
serviceName: nginx
servicePort: 80
- host: nginx-1.xj.com
http:
paths:
- path: /
backend:
serviceName: nginx-1
servicePort: 80
student@ubuntu:~/ingress$kubectl create -f nginx-ingress.yaml
ingress.extensions/ingress-nginx created
student@ubuntu:~/ingress$kubectl run nginx --image=nginx
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/nginx created
student@ubuntu:~/ingress$kubectl run nginx-1 --image=nginx
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/nginx-1 created
student@ubuntu:~/ingress$kubectl expose deployment nginx --port=80
service/nginx exposed
student@ubuntu:~/ingress$kubectl expose deployment nginx-1 --port=80
4.查看ui
http://
5.查看反向代理
student@ubuntu:~/ingress$curl http://172.30.81.194/ -H"Host: nginx.xj.com"
Welcome to nginx!
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.
student@ubuntu:~/ingress$curl http://172.30.81.194/ -H"Host: nginx-no.xj.com"
404 page not found