kubectl cluster-info
kubectl get nodes -o wide
kubectl describe nodes
kubectl get all
kubectl get all --all-namespaces
kubectl api-resources
Use run
and --restart=Never
:
kubectl run nginx --image=nginx --restart=Never
Do not use --restart=Never
kubectl run nginx --image=nginx
To have multiple replicas use --replicas=n
, to export the service on a port use --port=PORT
, to create the service use --expose
kubectl run nginx --image=nginx --replicas=6 --port=80 --expose
Get the service IP or, if there is no service (--expose
wasn't used), get the pod IP:
kubectl get svc nginx # Service IP
kubectl get pods -o wide # Pod IP
Assuming --port=80
was used:
kubectl run busybox --image=busybox -it --rm --restart=Never -- wget -O- 10.107.69.177:80
-
Create pod manifest:
kubectl run nginx --image=nginx --restart=Never --dry-run=true -o yaml > nginx.yaml
-
Edit it to add a second container inside
spec.containers[]
, for example:
- name: fdlogger
image: fluent/fluentd
-
Create the pod:
kubectl create -f nginx.yaml
kubectl exec nginx -it -c fdlogger -- /bin/sh