活動資訊:https://www.open-ecosystem.io/
本篇為什麼會先貼出活動資訊呢?,因為就在發文的同時,我們也在Cloud Native forum 2019的活動現場,本次活動(似乎也有簡介K3s的東西)。
回歸正題~,本篇我們延續一下上篇Affinity的技術執行,在上篇提到其實Affinity的主軸概念是以標籤化識別機制(Label Regionize),在Node機制時我們可以透過設計Node Label,在Pod派送的過程中進行功能進行選擇Node機制的中介,而本篇所需要介紹的Pod Affinity這東西,基本功能上也是參考標籤,但基準是從Node標籤演變成了Pod標籤,而基於 Affinity-傾向性派送功能之上,其實也衍生了AntiAffinity-反傾向性派送,概念上說就是在 Pod 派送時,防止將Pod擺放在相同的Node之上的派送防護性質,本篇我們就從 Pod Affinity持續進行k3s的測試吧。
apiVersion: v1
kind: Pod
metadata:
name: mysql-pod
namespace: default
labels:
app: mysql
spec:
containers:
- image: mysql:latest
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: password
kubectl create -f ${pod-name}
kubectl get pod -o wide
apiVersion: v1
kind: Pod
metadata:
name: grafana-pod-mysql
labels:
app: grafana
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- mysql
topologyKey: kubernetes.io/hostname
containers:
- name: grafana
image: grafana/grafana
kubectl create -f ${pod-name}
kubectl get pod -o wide
kubectl describe pod -o wide
apiVersion: v1
kind: Pod
metadata:
name: grafana-pod-mongodb
labels:
app: grafana
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- mongodb
topologyKey: kubernetes.io/hostname
containers:
- name: grafana
image: grafana/grafana
kubectl create -f ${pod-name}
kubectl get pod -o wide
kubectl describe pod -o wide
apiVersion: v1
kind: Pod
metadata:
name: mysql-pod
namespace: default
labels:
app: mysql
spec:
containers:
- image: mysql:latest
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: password
apiVersion: v1
kind: Pod
metadata:
name: grafana-pod-mysql
labels:
app: grafana
spec:
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- mysql
topologyKey: kubernetes.io/hostname
containers:
- name: grafana
image: grafana/grafana
kubectl create -f ${pod-name}
kubectl get pod -o wide
kubectl describe pod -o wide
apiVersion: v1
kind: Pod
metadata:
name: grafana-pod-mongodb
labels:
app: grafana
spec:
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- mongodb
topologyKey: kubernetes.io/hostname
containers:
- name: grafana
image: grafana/grafana
kubectl create -f ${pod-name}
kubectl get pod -o wide
kubectl describe pod -o wide
Pod 之間互不相依擺放,將對於節點壓力較大的Pod(如:DB/ML/DL功能)進行間格擺放。
apiVersion: v1
kind: Pod
metadata:
name: mysql-pod
namespace: default
labels:
app: mysql
spec:
containers:
- image: mysql:latest
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: password
apiVersion: v1
kind: Pod
metadata:
name: postgresql-antipod-mysql
labels:
app: postgresql
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- mysql
topologyKey: kubernetes.io/hostname
containers:
- name: postgresql
image: postgres:latest
env:
- name: POSTGRES_PASSWORD
value: password
kubectl create -f ${pod-name}
kubectl get pod -o wide
kubectl describe pod -o wide