Table of contents
kubernetes yaml files
general
multiple definitions in one yaml file with ---
apiVersion: v1
kind: Pod
metadata:
name: bb
spec:
containers:
- image: busybox
name: busybox
---
apiVersion: v1
kind: Pod
metadata:
name: ub
spec:
containers:
- image: ubuntu
name: ubuntu
pods
hello world
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mycontainer
image: nginx
custom command for container
spec:
containers:
- name: mycontainer
image: ubuntu
command: ["sleep"]
args: ["infinity"]
passing a command to the shell
spec:
containers:
- name: mycontainer
image: busybox
command:
- sh
- -c
- 'echo "foo bar" > /dev/termination-log; exit 55'
setting a label
metadata:
name: bb
labels:
foo: bar
multipod: "false"
setting the restart policy
spec:
restartPolicy: OnFailure
setting environment variables
spec:
containers:
- image: busybox
name: mycontainer
env:
- name: MYVAR1
value: MYVAL1
- name: MYVAR2
value: MYVAL2
command: ["echo"]
args: ["$(MYVAR1) - $(MYVAR2)"]
use configmap as environment variables
spec:
restartPolicy: OnFailure
containers:
- image: busybox
name: mycontainer
command: ["echo"]
args: ["$(a) - $(b)"]
envFrom:
- configMapRef:
name: myconfigmap
use a secret as an environment variable
spec:
containers:
- image: busybox
name: mycontainer
env:
- name: POPA
valueFrom:
secretKeyRef:
name: postgres
key: password
mounting a directory as a volume
spec:
containers:
- name: mycontainer
image: ubuntu
command: ["sleep"]
args: ["infinity"]
volumeMounts:
- mountPath: /vol/myvol
name: myvolume
volumes:
- name: myvolume
hostPath:
path: /tmp/myvol
type: Directory
specifying a node to run a pod on with a label
spec:
containers:
- name: [container]
image: [image]
nodeSelector:
node-pool: int
adding a toleration for a taint
spec:
containers:
- name: [container]
image: [image]
tolerations:
- key: "key"
operator: "Equal"
value: "int"
effect: "NoExecute"
configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfig
data:
entry1: "one"
entry2: "two"
replication controller
apiVersion: v1
kind: ReplicationController
metadata:
name: myrc
spec:
replicas: 3
selector:
mylabel: myvalue
template:
metadata:
name: myrcpod
labels:
mylabel: myvalue
spec:
containers:
- name: nginx
image: nginx
services
apiVersion: v1
kind: Service
metadata:
name: mysvc
spec:
selector:
mysvc: mypod
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: v1
kind: Pod
metadata:
name: httpd
labels:
mysvc: mypod
spec:
containers:
- image: httpd
name: mycontainer