在不同节点上部署Pod

时间:2019-08-12 21:48:45

标签: kubernetes

我有一个名为airflow的命名空间,其中有2个Pod:webserverscheduler。我想在节点scheduler上部署A,在节点webserver上部署B

nodes & pods

在这里您可以看到部署文件:

计划程序:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: airflow
  name: airflow-scheduler
  labels:
    name: airflow-scheduler
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: airflow-scheduler
    spec:
      terminationGracePeriodSeconds: 60
      containers:        
        - name: scheduler
          image: 123423.dkr.ecr.us-east-1.amazonaws.com/airflow:$COMMIT_SHA1          
          volumeMounts:
          - name: logs
            mountPath: /logs          
          command: ["airflow"]
          args: ["scheduler"]
          imagePullPolicy: Always
          resources:
            limits:
              memory: "3072Mi"
            requests:
              cpu: "500m"
              memory: "2048Mi"
      volumes:
          - name: logs
            persistentVolumeClaim:
              claimName: logs

网络服务器:

apiVersion: v1
kind: Service
metadata:
  name: airflow-webserver
  namespace: airflow
  labels:
    run: airflow-webserver
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    run: airflow-webserver
---    
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: airflow-webserver
  namespace: airflow
  annotations:
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
    - hosts:
        - airflow.awesome.com.br
      secretName: airflow-crt
  rules:
    - host: airflow.awesome.com.br
      http:
        paths:
          - path: /
            backend:
              serviceName: airflow-webserver
              servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: airflow
  name: airflow-webserver
  labels:
    run: airflow-webserver
spec:
  replicas: 1
  template:
    metadata:
      labels:
        run: airflow-webserver
    spec:
      terminationGracePeriodSeconds: 60
      containers:
        - name: webserver
          image: 123423.dkr.ecr.us-east-1.amazonaws.com/airflow:$COMMIT_SHA1
          volumeMounts:
          - name: logs
            mountPath: /logs          
          ports:
            - containerPort: 8080
          command: ["airflow"]
          args: ["webserver"]
          imagePullPolicy: Always
          resources:
            limits:
              cpu: "200m"
              memory: "3072Mi"
            requests:
              cpu: "100m"
              memory: "2048Mi"              
      volumes:
          - name: logs
            persistentVolumeClaim:
              claimName: logs

确保pod部署在不同节点上的正确方法是什么?

edit1:

antiaffinity不起作用:

我尝试在podAntiAffinity上设置scheduler,但是它不起作用:

  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: name
            operator: In
            values:
            - airflow-webserver
        topologyKey: "kubernetes.io/hostname"

1 个答案:

答案 0 :(得分:4)

如果您想让这些Pod在不同的节点上运行,但又不关心确切的节点,则可以使用 Pod反亲和力功能。它基本上定义了Pod X不应与Pod Y在同一节点上运行(它也可以与故障域/区域等一起使用,而不仅仅是节点),并使用标签指定Pod。因此,您将需要添加一些标签并在def login_page(request): form = LoginForm(request.POST or None) context = { "form": form, 'namespace':'accounts', } next_ = request.GET.get('next') next_post = request.POST.get('next') redirect_path = next_ or next_post or None # if redirect_path == '/': redirect_path = '/dashboard/' if form.is_valid(): username = form.cleaned_data.get("username") password = form.cleaned_data.get("password") user = authenticate(request, username=username, password=password) if user is not None: if user.is_active: login(request, user) try: del request.session['guest_email_id'] except: pass if is_safe_url(redirect_path, request.get_host()): return redirect(redirect_path) else: return redirect("/") # return redirect("dashboard/") else: # Return an 'invalid login' error message. print("LOGIN FAIL: Someone is trying to login and failed!") print("LOGIN FAIL: Username: {} and password: {}".format(username, password)) return HttpResponse("invalid username or password") else: return render(request, "accounts/login.html", context) 部分中进行指定。有关它的更多信息,请参见Kube docs

此外,如果您还希望指定它应在哪个节点上运行,则可以使用 Nodefinity 功能。有关更多详细信息,请参见Kube docs