container cli snippets

container

container cli snippets

run container nginx from image nginx, accessible on url http://localhost:8000
docker run -d -p 8000:80 --name nginx nginx
show logs of container named nginx
docker logs nginx

kubernetes

show version
kubectl version
usage
kubectl create ns sample
kubectl apply -n sample -f nginx.deployment.yml
kubectl get pods -n sample
kubectl logs -n sample -l app=nginx-sample

will expose nginx service as http://localhost:30000/ on node (no ingress)

proxy
kubectl proxy -n sample

will expose the pod as http://localhost:8001/api/v1/namespaces/sample/pods/ nginx-sample-6d9f59b4f7-jzbvc:80/proxy/

where "sample" is the namespace and "nginx-sample-6d…​." the running pod as listed with "get-pods"

and remove
kubectl delete pod/nginx-pod

the deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-sample
  name: nginx-sample
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-sample
  template:
    metadata:
      labels:
        app: nginx-sample
    spec:
      containers:
        - image: nginx:latest
          name: nginx-sample
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  type: NodePort
  selector:
    app: nginx-sample
  ports:
    - port: 80
      nodePort: 30000