美文网首页
LFS258-LAB-Ingress

LFS258-LAB-Ingress

作者: xiao_b4b1 | 来源:发表于2018-12-05 11:14 被阅读0次

安装traefik

  1. 添加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://<NODE-ip>:8080/dashboard/

5.查看反向代理

student@ubuntu:~/ingress$curl http://172.30.81.194/ -H"Host: nginx.xj.com"
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

student@ubuntu:~/ingress$curl http://172.30.81.194/ -H"Host: nginx-no.xj.com"
404 page not found

相关文章

  • LFS258-LAB-Ingress

    安装traefik 添加rbac 2.添加traefik ds 3.添加ingress 4.查看uihttp://...

网友评论

      本文标题:LFS258-LAB-Ingress

      本文链接:https://www.haomeiwen.com/subject/xcsicqtx.html