Kubernetes¶
Labels and Selectors¶
Grouping objects by label
Command examples¶
Create Pod¶
Create Deployment¶
Generate YAML¶
Create Pod¶
will create the outputapiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
Create Deployment¶
will create the output:apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 4
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
Create Service¶
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
run: alpine
name: redis-service
namespace: falco
spec:
ports:
- port: 6379
protocol: TCP
targetPort: 6379
selector:
run: alpine
status:
loadBalancer: {}
Imperative and Declarative style¶
In Kubernetes you can both use declarative and imperative methods.
Imperative examples¶
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
kubectl create -f nginx.yaml
kubectl replace -f nginx.yaml
kubectl delete -f nginx.yaml
Declarative examples¶
You manage files directly and only files. Changes to the environment are only made by applying files, not using one of the above imperative examples.