scorpion5211
scorpion5211

Reputation: 1070

Kubernetes Single Container Node Architecture

I am semi new to kubernetes and as i understand many things cherry picked around the topic, some things are still hard to put together.

I have a following project setup and need an architectural advice on whats a best way to setup my k8 cluster.

I have two applications for now: API-APP and WORKER-APP, they both have heavy resource consumption so i need one node to be reserved for one application (pod).

I create total of 6 nodes so that 3 API-APP (replicated using replicationcontroller) and 3 WORKER-APP (replicated using replication controller) can all have its own node (they use about 90% CPU/Memory).

Currently k8 just deploys them out to whichever node and sometimes i have a case that all 3 of my API-APP live on 1 node i have 2 nodes just doing nothing.

Is there any way to specify that i want 1 node to be reserved for 1 app ?

I have looked at specifying requests/limit but either simply nothing happens or im doing something wrong.

yaml file:

# RC for svc1
kind: ReplicationController
apiVersion: v1
metadata:
  name: APP-API
spec:
  replicas: 3
  selector:
  template:
    metadata:
      labels:
        app: APP-API
    spec:
      containers:
      - name: APP-API
        image: SOME-IMAGE
        resources:
          limits:
            cpu: "7000m"
        requests:
          cpu: "7000m"
        env:
        - name: APP_SVC
          value: APP-API
        ports:
        - containerPort: 80
          protocol: TCP
---
# Service for svc1
kind: Service
apiVersion: v1
metadata:
  labels:
    app: APP-API
  name: APP-API
spec:
  type: ClusterIP
  ports:
  - port: 80
    name: http
  selector:
    app: APP-API

my machines have all 8 cores so in this case i am trying to tell it to request 7 cores but nothing happens.

enter image description here

Upvotes: 0

Views: 89

Answers (1)

scorpion5211
scorpion5211

Reputation: 1070

i came across this https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ which led me to the right direction. Inter-Pod affinity and anti-affinity was exactly what i was looking for. It allowed me to make sure that no 2 apps ran on the same node based on the labeling key/values provided in the yaml file.

my yaml ended up looking very similar to this:

apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1
kind: Deployment
metadata:
  name: redis-cache
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: store
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - store
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: redis-server
        image: redis:3.2-alpine

Upvotes: 1

Related Questions