ftsr 发表于 2018-11-12 09:54:17

kubernetes 1.11配置使用nginx ingress-ygqygq2

#---  #
  ## 有需要创建namespace,取消该段注释
  #apiVersion: v1
  #kind: Namespace
  #metadata:
  #name: default
  #---
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
  name: default-http-backend
  labels:
  app: default-http-backend
  namespace: default
  spec:
  replicas: 1
  selector:
  matchLabels:
  app: default-http-backend
  template:
  metadata:
  labels:
  app: default-http-backend
  spec:
  terminationGracePeriodSeconds: 60
  containers:
  - name: default-http-backend
  # Any image is permissible as long as:
  # 1. It serves a 404 page at /
  # 2. It serves 200 on a /healthz endpoint
  image: registry.cn-hangzhou.aliyuncs.com/google-containers/defaultbackend:1.4
  livenessProbe:
  httpGet:
  path: /healthz
  port: 8080
  scheme: HTTP
  initialDelaySeconds: 30
  timeoutSeconds: 5
  ports:
  - containerPort: 8080
  resources:
  limits:
  cpu: 10m
  memory: 20Mi
  requests:
  cpu: 10m
  memory: 20Mi
  ---
  apiVersion: v1
  kind: Service
  metadata:
  name: default-http-backend
  namespace: default
  labels:
  app: default-http-backend
  spec:
  ports:
  - port: 80
  targetPort: 8080
  selector:
  app: default-http-backend
  ---
  kind: ConfigMap
  apiVersion: v1
  metadata:
  name: nginx-configuration
  namespace: default
  labels:
  app: ingress-nginx
  ---
  kind: ConfigMap
  apiVersion: v1
  metadata:
  name: tcp-services
  namespace: default
  ---
  kind: ConfigMap
  apiVersion: v1
  metadata:
  name: udp-services
  namespace: default
  ---
  apiVersion: v1
  kind: ServiceAccount
  metadata:
  name: nginx-ingress-serviceaccount
  namespace: default
  ---
  apiVersion: rbac.authorization.k8s.io/v1beta1
  kind: ClusterRole
  metadata:
  name: nginx-ingress-clusterrole
  rules:
  - apiGroups:
  - ""
  resources:
  - configmaps
  - endpoints
  - nodes
  - pods
  - secrets
  verbs:
  - list
  - watch
  - apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - get
  - apiGroups:
  - ""
  resources:
  - services
  verbs:
  - get
  - list
  - watch
  - apiGroups:
  - "extensions"
  resources:
  - ingresses
  verbs:
  - get
  - list
  - watch
  - apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - patch
  - apiGroups:
  - "extensions"
  resources:
  - ingresses/status
  verbs:
  - update
  ---
  apiVersion: rbac.authorization.k8s.io/v1beta1
  kind: Role
  metadata:
  name: nginx-ingress-role
  namespace: default
  rules:
  - apiGroups:
  - ""
  resources:
  - configmaps
  - pods
  - secrets
  - namespaces
  verbs:
  - get
  - apiGroups:
  - ""
  resources:
  - configmaps
  resourceNames:
  # Defaults to "-"
  # Here: "-"
  # This has to be adapted if you change either parameter
  # when launching the nginx-ingress-controller.
  - "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: default
  roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: nginx-ingress-role
  subjects:
  - kind: ServiceAccount
  name: nginx-ingress-serviceaccount
  namespace: default
  ---
  apiVersion: rbac.authorization.k8s.io/v1beta1
  kind: ClusterRoleBinding
  metadata:
  name: nginx-ingress-clusterrole-nisa-binding
  roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: nginx-ingress-clusterrole
  subjects:
  - kind: ServiceAccount
  name: nginx-ingress-serviceaccount
  namespace: default
  ---
  apiVersion: extensions/v1beta1
  kind: DaemonSet# Deployment修改成Daemonset
  metadata:
  name: nginx-ingress-controller
  namespace: default
  spec:
  #replicas: 2# 注释该段
  #selector:
  #matchLabels:
  #    app: ingress-nginx
  template:
  metadata:
  labels:
  app: ingress-nginx
  annotations:
  prometheus.io/port: '10254'
  prometheus.io/scrape: 'true'
  spec:
  nodeSelector:# 节点标签
  LB: ingress
  #tolerations:# 声明可接受的污点
  #- key: "LB"
  #operator: "Equal"
  #value: "NIC"
  #effect: "NoSchedule"
  serviceAccountName: nginx-ingress-serviceaccount
  hostNetwork: true# 添加这行,绑定到主机
  containers:
  - name: nginx-ingress-controller
  image: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.17.1
  args:
  - /nginx-ingress-controller
  #- --apiserver-host=https://192.168.105.99:8443
  - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
  - --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
  #- --report-node-internal-ip-address=true
  securityContext:
  capabilities:
  drop:
  - ALL
  add:
  - NET_BIND_SERVICE
  # www-data -> 33
  runAsUser: 33
  env:
  - name: POD_NAME
  valueFrom:
  fieldRef:
  fieldPath: metadata.name
  - name: POD_NAMESPACE
  valueFrom:
  fieldRef:
  fieldPath: metadata.namespace
  ports:
  - name: http
  containerPort: 80
  - name: https
  containerPort: 443
  livenessProbe:
  failureThreshold: 3
  httpGet:
  path: /healthz
  port: 10254
  scheme: HTTP
  initialDelaySeconds: 10
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 1
  readinessProbe:
  failureThreshold: 3
  httpGet:
  path: /healthz
  port: 10254
  scheme: HTTP
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 1
  ---
  ## Expose Nginx Ingress controller
  #apiVersion: v1
  #kind: Service
  #metadata:
  #name: nginx-ingress-controller
  #namespace: default
  #spec:
  #type: LoadBalancer
  #ports:
  #    - port: 80
  #    #nodePort: 30000
  #      name: http
  #    #- port: 18080
  #    #nodePort: 32000
  #    #name: http-mgmt
  #selector:
  #    app: nginx-ingress-controller

页: [1]
查看完整版本: kubernetes 1.11配置使用nginx ingress-ygqygq2