Basic YAML Structure in Kubernetes
Basic YAML Structure
1
2
3
4
5
6
| apiVersion:
kind:
metadata:
spec:
|
Kind | Version |
---|
POD | v1 |
Service | v1 |
ReplicaSet | apps/v1 |
Deployment | apps/v1 |
POD YAML
pod-definition.yml
1
2
3
4
5
6
7
8
9
10
11
| apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-continer
image: nginx
|
Create a POD with YAML file
1
| kubectl create -f pod-definition.yml
|
Create a POD with Command
1
| kubectl run myapp-pod --image nginx
|
Show PODs List
Show POD Detail
1
| kubectl describe pod myapp-pod
|
Replication Controller YAML
rc-definition.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| apiVersion: v1
kind: ReplicationController
metadata: # -> Replication Controller
name: myapp-rc
labels:
app: myapp
type: front-end
spec: # -> Replication Controller
template:
metadata: # -> POD
name: myapp-pod
labels:
app: myapp
type: front-end
spec: # -> POD
containers:
- name: nginx-continer
image: nginx
replicas: 3
|
Create a Replication Controller
1
| kubectl create -f rc-definition.yml
|
Show Replication Controller List
1
| kubectl get replicationcontroller
|
Show PODs List
ReplicaSet
rs-definition.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| apiVersion: apps/v1
kind: ReplicaSet
metadata: # -> ReplicaSet
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec: # -> ReplicaSet
template:
metadata: # -> POD
name: myapp-pod
labels:
app: myapp
type: front-end
spec: # -> POD
containers:
- name: nginx-continer
image: nginx
replicas: 3
selector: # -> `selector` is not required by Replication Controller
matchLabels:
type: front-end
|
Labels and Selector
selector
is to find the matched labels for managing the PODs.
Create a ReplicaSet
1
| kubectl create -f rs-definition.yml
|
Show ReplicaSet List
Show ReplicaSet Detail
1
| kubectl describe replicaset myapp-replicaset
|
Show PODs List
Delete ReplicaSet
1
| kubectl delete replicaset myapp-replicaset
|
Scale
Change replicas
in the YAML file with repliace
1
| kubectl replace -f rs-definition.yml
|
Origin YAML file and --replicas
option with scale
1
| kubectl scale --replicas=6 -f rs-definition.yml
|
Change Running ReplicaSet’s name and --replicas
option with scale
1
| kubectl scale --replicas=6 replicaset myapp-replicaset
|