Difference between revisions of "Kubernetes"
| Line 20: | Line 20: | ||
<code>kubectl explain <something></code> Explain <something> | <code>kubectl explain <something></code> Explain <something> | ||
== Kubernetes Definition | == Kubernetes Definition Files == | ||
=== Example .yaml for Pod === | === Example .yaml for Pod === | ||
This configuration defines a pod named "myapp-pod" that runs a single container using the nginx image.</br> | This configuration defines a pod named "myapp-pod" that runs a single container using the nginx image.</br> | ||
| Line 106: | Line 106: | ||
matchLabels: | matchLabels: | ||
type: front-end</nowiki> | type: front-end</nowiki> | ||
=== Example .yaml for Namespace === | |||
This configuration defines a new namespace dev. | |||
<nowiki>apiVersion: v1 | |||
kind: Namespace | |||
metadata: | |||
name: dev</nowiki> | |||
Command: <code>kubectl create namespace dev</code> | |||
=== Example .yaml for Resource Quota === | |||
This configuration defines a resource quota compute-quota for namespace dev. | |||
<nowiki>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</nowiki> | |||
Revision as of 15:57, 26 January 2026
k8s
kubectl
get
kubectl get <all/pods/replicationcontroller/replicaset/deployment Show all/replicationcontroller/replicaset/deployment objects
kubectl get pods -o wide Show all pods with more info
kubectl get replicationcontroller Show all replication controllers
kubectl get replicaset Show all replica sets
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:
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