Kubernetes – Set max pod (replica) limit per node

We have to allocate exactly N pod of service A per node. When new pod of A (N+1) is coming, pod cannot schedule due to lack of capacity and new nodes are added by Cluster Autoscaler

We can find a similar user case from this issue of Kubernetes Github repo add a new predicate: max replicas limit per node · Issue #71930

From Kubernetes 1.6, it seems we can use Pod Topology Spread Constraints to resolve.

You can use topology spread constraints to control how Pods are spread across your cluster among failure-domains such as regions, zones, nodes, and other user-defined topology domains. This can help to achieve high availability as well as efficient resource utilization.

Unfortunately, i am working on a old version of Kubernetes cluster (v1.12). It requires a workaround for this problem.

I found a workaround using Kubernetes QoS class Guaranteed setting to implement it.

When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:

  • Guaranteed
  • Burstable
  • BestEffort

Kubernetes QoS class

For a Pod to be given a QoS class of Guaranteed: Pods where both limit and (optionally) request are set for all resources (CPU and memory) and their values are the same. These pods are high priority, therefore they are terminated only if they are over the limit and there are no lower priority pods to terminate.

Example, 1 node t3.xlarge have 4 CPUs, 16 GBs. We want to spread 3 pods per node the resources/limits, requests are the same value 1 CPU (1 CPU for Kubernetes system pod, log pod such as Fluentd, …)

Pod manifest

containers:
  name: pong
    resources:
      limits:
        cpu: 1
        memory: 1Gi
      requests:
        cpu: 1
        memory: 1Gi

This workaround works like a charm for my case.

nvm – Node Version Manager

Nhân dịp update node version lên bản v0.10.21 (http://blog.nodejs.org/2013/10/18/node-v0-10-21-stable/)

1. nvm là gì?

Là chương trình dùng để quản lý version của Node.js . HP: https://github.com/creationix/nvm

2.Cài đặt nvm trên Mac OS

tuan@tmac ~ $git clone git://github.com/creationix/nvm.git ~/.nvm
tuan@tmac ~ $ source ~/.nvm/nvm.sh
tuan@tmac ~ $ // .bashrc or .bash_profile
[[ -s USER_HOME/.nvm/nvm.sh ]] && . USER_HOME/.nvm/nvm.sh
nvm use default
npm_dir=${NVM_PATH}_modules
export NODE_PATH=$npm_dir

3. Sử dụng


tuan@tmac ~ $ nvm
Node Version Manager
Usage:
nvm help Show this message
nvm install [-s] <version> Download and install a <version>
nvm uninstall <version> Uninstall a version
nvm use <version> Modify PATH to use <version>
nvm run <version> [<args>] Run <version> with <args> as arguments
nvm ls List installed versions
nvm ls <version> List versions matching a given description
nvm ls-remote List remote versions available for install
nvm deactivate Undo effects of NVM on current shell
nvm alias [<pattern>] Show all aliases beginning with <pattern>
nvm alias <name> <version> Set an alias named <name> pointing to <version>
nvm unalias <name> Deletes the alias named <name>
nvm copy-packages <version> Install global NPM packages contained in <version> to current version
Example:
nvm install v0.4.12 Install a specific version number
nvm use 0.2 Use the latest available 0.2.x release
nvm run 0.4.12 myApp.js Run myApp.js using node v0.4.12
nvm alias default 0.4 Auto use the latest installed v0.4.x version

3.Cài đặt node.js

List tất cả các version có thể cài đặt được.

tuan@tmac ~ $ nvm ls-remote
tuan@tmac ~ $ nvm install 0.10.21
######################################################################## 100.0%
-f: move to trash.
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
/Users/tuan/.nvm/bin/node-v0.10.21-darwin-x64/node-v0.10.21-darwin-x64.tar.gz: move to trash.
Now using node v0.10.21

4.Chạy node.js với version chỉ định


tuan@tmac ~ $nvm use v0.10.21
tuan@tmac ~ $node -v
v0.10.21

5.Thiết định version mặc định


tuan@mac ~$nvm alias use default  v0.10.21