apiVersion: apps/v1
kind: Deployment
metadata:
  name: fastapi-deployment
  labels:
    app: fastapi
spec:
  replicas: 2
  selector:
    matchLabels:
      app: fastapi
  template:
    metadata:
      labels:
        app: fastapi
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - fastapi
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: servercontainer-fastapi
        image: <your-image>
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 5050
        resources:
          limits:
            memory: 256Mi
            cpu: "1"
          requests:
            memory: 128Mi
            cpu: "0.2"