Similar to Firewalls
Deny Ingress / Egress traffic
Use Label Selectors & IP blocks
apiVersion: v1
kind: Pod
spec:
initContainers:
- name: init-db
image: busybox
command: ['sh', '-c', 'until nslookup db; do sleep 2; done;']
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
POD
POD
init-db
POD
init-db
POD
init-db
POD
init-db
POD
my-app
kubectl label nodes \ <node-name> \ <label-key>=<label-value>
kubectl label nodes \ my-node-1 \ gpu=nvidia-tesla-p100
requiredDuringSchedulingIgnoredDuringExecution
preferredDuringSchedulingIgnoredDuringExecution
In Pod's spec.affinity.nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution
preferredDuringSchedulingIgnoredDuringExecution
In Pod's spec.affinity.nodeAffinity:
kubectl label nodes <node-name> <label-key>=<label-value>
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
nodeSelector:
disktype: ssd
Service Type: ClusterIP
10.47.240.1:80
my-app-1h4md
label selection
my-app.my-ns.svc.cluster.local
10.47.242.240:8080
10.47.242.241:8080
10.47.242.242:8080
my-app-j2vek
my-app-xt8lx
my-app-1h4md.my-app.my-ns.svc.cluster.local
my-app-xt81x.my-app.my-ns.svc.cluster.local
10.47.242.240:8080
10.47.242.241:8080
10.47.242.242:8080
Headless Service
(clusterIP: None)
my-app-1h4md
my-app-j2vek
my-app-xt8lx
my-app-j2vek.my-app.my-ns.svc.cluster.local
my-app-1h4md.my-app.my-ns.svc.cluster.local
my-app-xt81x.my-app.my-ns.svc.cluster.local
10.47.242.240:8080
10.47.242.241:8080
10.47.242.242:8080
Headless Service
(clusterIP: None)
my-app-1h4md
my-app-j2vek
my-app-xt8lx
my-app-j2vek.my-app.my-ns.svc.cluster.local
my-app-1h4md
my-app-j2vek
my-app-xt8lx
my-app-2
my-app-1
my-app-0
DEPLOYMENT
STATEFULSET
my-app-2
my-app-1
STATEFULSET
my-app-0.my-app.my-ns.svc.cluster.local
my-app-2.my-app.my-ns.svc.cluster.local
Headless Service
my-app-1.my-app.my-ns.svc.cluster.local
my-app-0
my-app-0
my-app-1
my-app-2
Created
Created
Created
/
/Znode1
Value: "foo"
/Znode2
Value: "bar"
/Znode1/subnode
Value: "foo"
/Znode2/hello
Value: "world"
/Znode2/mutex
Value: "locked"
my-app-2
my-app-0
my-app-0
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: zk-pdb
spec:
selector:
matchLabels:
app: zk
maxUnavailable: 2
my-app-2
my-app-0
my-app-0
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: zk-pdb
spec:
selector:
matchLabels:
app: zk
maxUnavailable: 2
# To add the NoSchedule taint kubectl taint nodes worker-1 key=value:NoSchedule
# To remove the taint
kubectl taint nodes worker-1 key:NoSchedule-
# In a PodSpec tolerations: - key: "key" operator: "Equal" value: "value" effect: "NoSchedule"
# In a PodSpec tolerations: - key: "key" operator: "Equal" value: "value" effect: "NoSchedule"
Effects:
- NoSchedule
- PreferNoSchedule
- NoExecute
https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/#taint-based-evictions
Builtins
These get applied automatically by NodeController
https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/#taint-based-evictions
Builtins
These get applied automatically by NodeController
# Allows User to get all pods
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
users:
- name: corey
user:
client-certificate: <xxx>
client-key: <xxx>
Role
users:
- name: corey
user:
client-certificate: <xxx>
client-key: <xxx>
Role
https://github.com/coreos/dex/blob/master/Documentation/kubernetes.md
# This role binding allows "jane" to read pods in the "default" namespace.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader # this must match the name of the Role
apiGroup: rbac.authorization.k8s.io
# This cluster role binding allows anyone in the "manager" group
# to read secrets in any namespace.
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-secrets-global
subjects:
- kind: Group
name: manager
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
# This cluster role binding allows anyone in the "manager" group
# to read secrets in any namespace.
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-secrets-global
subjects:
- kind: Group
name: manager
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io