91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

k8s集群中的ingress----基于nginx實現

發布時間:2020-07-19 17:03:04 來源:網絡 閱讀:363 作者:dongyali521521 欄目:云計算

基于nginx創建ingress
1、創建基于nginx的ingress控制器pod及svc
$ docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.25.0
$ wget https://github.com/kubernetes/ingress-nginx/blob/master/deploy/static/mandatory.yaml
$ mv mandatory.yaml nginx-ingress-controller.yaml
$ vim nginx-ingress-controller.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: tcp-services
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: udp-services
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nginx-ingress-serviceaccount
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: nginx-ingress-clusterrole
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
rules:
  - apiGroups:
      - ""
    resources:
      - configmaps
      - endpoints
      - nodes
      - pods
      - secrets
    verbs:
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - create
      - patch
  - apiGroups:
      - "extensions"
      - "networking.k8s.io"
    resources:
      - ingresses
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - "extensions"
      - "networking.k8s.io"
    resources:
      - ingresses/status
    verbs:
      - update
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  name: nginx-ingress-role
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
rules:
  - apiGroups:
      - ""
    resources:
      - configmaps
      - pods
      - secrets
      - namespaces
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - configmaps
    resourceNames:
      - "ingress-controller-leader-nginx"
    verbs:
      - get
      - update
  - apiGroups:
      - ""
    resources:
      - configmaps
    verbs:
      - create
  - apiGroups:
      - ""
    resources:
      - endpoints
    verbs:
      - get
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: nginx-ingress-role-nisa-binding
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: nginx-ingress-role
subjects:
  - kind: ServiceAccount
    name: nginx-ingress-serviceaccount
    namespace: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: nginx-ingress-clusterrole-nisa-binding
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: nginx-ingress-clusterrole
subjects:
  - kind: ServiceAccount
    name: nginx-ingress-serviceaccount
    namespace: ingress-nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: ingress-nginx
      app.kubernetes.io/part-of: ingress-nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/name: ingress-nginx
        app.kubernetes.io/part-of: ingress-nginx
      annotations:
        prometheus.io/port: "10254"
        prometheus.io/scrape: "true"
    spec:
      serviceAccountName: nginx-ingress-serviceaccount
      containers:
        - name: nginx-ingress-controller
          image: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.25.0          #修改鏡像文件
                    args:
            - /nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
            - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
            - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
            - --publish-service=$(POD_NAMESPACE)/ingress-nginx
            - --annotations-prefix=nginx.ingress.kubernetes.io
          securityContext:
            allowPrivilegeEscalation: true
            capabilities:
              drop:
                - ALL
              add:
                - NET_BIND_SERVICE
            runAsUser: 33
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - name: http
              containerPort: 80
              hostPort: 80        #增加hostPort
            - name: https
              containerPort: 443
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10

$ kubectl get pod -n ingress-nginx -o wide |grep ingress
使用命令創建svc
$ kubectl expose deployment nginx-ingress-controller --name=ingress-nginx --type=NodePort -n ingress-nginx
$ kubectl get svc -n ingress-nginx |grep ingress

2、創建應用pod及svc
$ kubectl run nginx1 --image=nginx --port=80
$ kubectl run nginx3 --image=nginx --port=80
$ kubectl run nginx5 --image=nginx --port=80
$ kubectl expose deployment nginx1 --name=nginx1
$ kubectl expose deployment nginx3 --name=nginx3
$ kubectl expose deployment nginx5 --name=nginx5
$ kubectl get pod |grep nginx
$ kubectl exec nginx1-6697bccbf9-gdcxd -it bash
/# cd /usr/share/nginx/html/
/# echo 11111 > index.html
$ kubectl exec nginx3-b869cb8df-5vfgg -it bash
/# cd /usr/share/nginx/html/
/# mkdir rhce
/# echo 33333 > rhce/index.html
$ kubectl exec nginx5-76c7c85869-4ttrr -it bash
/# cd /usr/share/nginx/html/
/# echo 55555 > index.html

3、為應用pod及svc創建ingress策略

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
spec:
  rules:
  - host: www.rhce.cc
    http:
      paths:
      - path: /     #網頁文件必須在/usr/share/nginx/html/內
        backend:
          serviceName: nginx1
          servicePort: 80
      - path: /rhce     #網頁文件必須在/usr/share/nginx/html/rhce/內
        backend:
          serviceName: nginx3
          servicePort: 80
  - host: www5.rhce.cc
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx5
          servicePort: 80
$ kubectl get ingress
myingress         www.example.cc,www5.example.cc             80      81d

4、訪問測試
查看ingress控制器pod在哪個node上
$ kubectl get pod -n ingress-nginx -o wide
在server241.example.com上
模擬dns
$ vim /etc/hosts
192.168.1.241        www.example.cc
192.168.1.241        www5.example.cc
http://www.example.cc ----訪問nginx1
http://www.example.cc/rhce ----訪問nginx3
http://www5.example.cc ----訪問nginx5
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宁晋县| 威信县| 闽清县| 海南省| 紫阳县| 安吉县| 兰州市| 格尔木市| 平塘县| 德安县| 霍州市| 綦江县| 河曲县| 彭州市| 名山县| 美姑县| 新竹县| 泊头市| 临湘市| 邵阳县| 阳西县| 康定县| 垫江县| 竹山县| 南陵县| 鹤壁市| 宣城市| 高唐县| 沽源县| 罗城| 鄱阳县| 湾仔区| 马山县| 株洲市| 浦江县| 吐鲁番市| 民权县| 法库县| 清原| 梅州市| 易门县|