Difference between revisions of "Kubernetes"
(→get) |
|||
| Line 33: | Line 33: | ||
type: front-end | type: front-end | ||
spec: | spec: | ||
tolerations: | |||
- key: "spray" | |||
operator: "Equal" | |||
value: "mortein" | |||
effect: "NoSchedule" | |||
containers: | containers: | ||
- name: nginx-container | - name: nginx-container | ||
| Line 141: | Line 146: | ||
<code>kubectl scale deployment nginx --replicas=5</code></br> | <code>kubectl scale deployment nginx --replicas=5</code></br> | ||
<code>kubectl set image deployment nginx nginx=nginx:1.18</code></br> | <code>kubectl set image deployment nginx nginx=nginx:1.18</code></br> | ||
=== Taint === | |||
<code>kubectl taint node node01 key=value:NoSchedule</code> Add some taint to node01 | |||
Revision as of 12:30, 27 January 2026
k8s
kubectl
api-resources
kubectl api-resources List available resources
explain
kubectl explain <pods> --recursive Explain something
get
kubectl get <all/pods/replicationcontroller/replicaset/deployment/ns/svc/nodes Show all/replicationcontroller/replicaset/deployment/namespace/service objects
kubectl get pods -o wide Show all pods with more info
run/create
kubectl run <pod-name> --image=nginx Run new nginx pod
kubectl create -f <defintion.yaml> Create new object from <definition.yaml> file
describe/edit/delete
kubectl describe pod <pod-name> Describe pod
kubectl edit pod <pod-name> Edit pod with editor
kubectl delete pod <pod-name> Delete pod from default namespace
scale
kubectl scale --replicas=5 replicaset <replicaset-name> Edit the current replicas without editing the file (fleeting?).
explain
kubectl explain <something> Explain <something>
Kubernetes Definition Files
Example .yaml for Pod
This configuration defines a pod named "myapp-pod" that runs a single container using the nginx image.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
tolerations:
- key: "spray"
operator: "Equal"
value: "mortein"
effect: "NoSchedule"
containers:
- name: nginx-container
image: nginx
Example .yaml for Replication Controller
This configuration defines a replication controller for the example "myapp-pod" nginx pod.
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
Example .yaml for Replica Set
This configuration defines a replica set for the example "myapp-pod" nginx pod.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
Example .yaml for Deployment
This configuration defines a deployment for the example "myapp-pod" nginx pod.
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
Example .yaml for Namespace
This configuration defines a new namespace dev.
apiVersion: v1 kind: Namespace metadata: name: dev
Command: kubectl create namespace dev
Example .yaml for Resource Quota
This configuration defines a resource quota compute-quota for namespace dev.
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
namespace: dev
spec:
hard:
pods: "10"
requests.cpu: "4"
requests.memory: 5Gi
limit.cpu: "10"
limit.memory: 10Gi
Imperative Commands
Can be tested with: --dry-run=client
kubectl run --image=nginx nginx
kubectl create deployment --image=nginx nginx
kubectl expose deployment nginx --port 80
kubectl edit deployment nginx
kubectl scale deployment nginx --replicas=5
kubectl set image deployment nginx nginx=nginx:1.18
Taint
kubectl taint node node01 key=value:NoSchedule Add some taint to node01