Command Tip!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # Create a POD with nginx image
kubectl run nginx --image=nginx
# Generate POD Manifest YAML file without create(--dry-run)
kubectl run nginx --image=nginx --dry-run=client -o yaml > nginx-pod.yml
# Create a Deployment
kubectl create deployment --image=nginx nginx
# Generate Deployment Manifest YAML file without create(--dry-run)
kubectl create deployment --image=nginx nginx --dry-run=client -o yaml > nginx-deployment.yml
# Generate Deployment Manifest YAML file without create(--dry-run) with 4 replicas(--replicas=4)
kubectl create deployment --image=nginx --replicas=4 nginx --dry-run -o yaml > nginx-deployment.yml
|
POD
POD List
1
2
3
4
5
6
7
8
9
10
11
| # Basic
kubectl get pods
# Wide
kubectl get pods -o wide
# Selector
kubectl get pods --selector key=value
# Selector with no headers and count PODs
kubectl get pods --selector key=value --no-headers | wc -l
|
Create a POD with YAML
1
| kubectl create -f pod-definition.yml
|
Create a POD with Command
1
| kubectl run myapp-pod --image nginx
|
POD Detail
1
| kubectl describe pod myapp-pod
|
Change Running POD
1
| kubectl edit pod myapp-pod
|
Delete POD
1
| kubectl delete pod myapp-pod
|
Generate a YAML file from and exist POD
1
| kubectl get pod myapp-pod -o yaml > my-new-pod.yml
|
ReplicaSet
ReplicaSet List
Create a ReplicaSet with YAML
1
| kubectl create -f rs-definition.yml
|
ReplicaSet Detail
1
| kubectl describe replicaset myapp-replicaset
|
Change Running ReplicaSet
1
| kubectl edit replicaset myapp-replicaset
|
If you change image and then, you need to delete all the PODs of the ReplicaSet.
Delete ReplicaSet
1
| kubectl delete replicaset myapp-replicaset
|
Node
Node List
1
2
3
4
5
| # Default
kubectl get nodes
# Show Labels
kubectl get nodes --show-labels
|
Set label to Node
Set label to Node Command Structure
1
| kubectl label nodes [node-name] [key]=[value]
|
Name | Example |
---|
[node-name] | node01 |
[key] | size |
[value] | Large |
Set label to Node Command
1
| kubectl label nodes node01 size=Large
|
Execute Command at Running Container
1
2
3
4
5
6
| # Structure
kubectl exec -it <container-name> -- <comaand>
# Examples
kubectl exec -it <container-name> -- sleep 10
kubectl exec -it <container-name> -- date -s '19 APR 2012 11:14:00'
|