k8s

21. September 2021 / Stephan Post

Kubernetes

get shell

# kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-0 -- /bin/bash
# curl -D - -H 'host: otc.ref.dsk8s.telekomcloud.com' 'http://localhost:8080/blueprint/servlet/de' 2> /dev/null | head -20
# curl -D - -H 'host: open-telekom.cloud.com' 'http://localhost:8080/blueprint/servlet/de' 2> /dev/null | head -20

exec on node cms-dev pod mysql-client-0

kubectl -n cms-dev exec -it mysql-client-0 -- bash

samples

export KUBECONFIG=/home/martin/proj/ghs/Technik/kube-config-prod.yml
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-0 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de'> 00.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-1 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de'> 01.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-01-0 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de'> 10.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-01-1 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de'> 11.html

export KUBECONFIG=/home/martin/proj/ghs/Technik/kube-config.yml
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-0 -- curl -D - -H 'host: otc.ref.dsk8s.telekomcloud.com' 'http://localhost:8080/blueprint/servlet/de' > 00.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-1 -- curl -D - -H 'host: otc.ref.dsk8s.telekomcloud.com' 'http://localhost:8080/blueprint/servlet/de' > 01.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-01-0 -- curl -D - -H 'host: otc.ref.dsk8s.telekomcloud.com' 'http://localhost:8080/blueprint/servlet/de' > 10.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-01-1 -- curl -D - -H 'host: otc.ref.dsk8s.telekomcloud.com' 'http://localhost:8080/blueprint/servlet/de' > 11.html

export KUBECONFIG=/home/martin/proj/ghs/Technik/kube-config-prod.yml
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-0 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de/blog/isg-provider-lens-2020'> 00.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-00-1 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de/blog/isg-provider-lens-2020'> 01.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-01-0 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de/blog/isg-provider-lens-2020'> 10.html
kubectl exec -n cms --stdin --tty -c cae cae-live-delivery-environment-01-1 -- curl -D - -H 'host: open-telekom-cloud.com' 'http://localhost:8080/blueprint/servlet/de/blog/isg-provider-lens-2020'> 11.html

list all services

kubectl get services                          # List all services in the namespace

list all pods

# Get commands with basic output
kubectl get pods --all-namespaces             # List all pods in all namespaces
kubectl get pods -o wide                      # List all pods in the current namespace, with more details
kubectl get deployment my-dep                 # List a particular deployment
kubectl get pods                              # List all pods in the namespace
kubectl get pod my-pod -o yaml                # Get a pod's YAML

log

pod: cae-preview-0
namespace: cms
container: cae

kubectl logs cae-preview-0 -n cms -c cae

Stream Log

kubectl logs -f my-pod -c my-container

Interact

kubectl logs deploy/my-deployment                         # dump Pod logs for a Deployment (single-container case)
kubectl logs deploy/my-deployment -c my-container         # dump Pod logs for a Deployment (multi-container case)

listen on local port 5000 and forward to port 5000 on Service backend

kubectl port-forward svc/my-service 5000                  

listen on local port 5000 and forward to Service target port with name

kubectl port-forward svc/my-service 5000:my-service-port  

listen on local port 5000 and forward to port 6000 on a Pod created by

kubectl port-forward deploy/my-deployment 5000:6000       
kubectl exec deploy/my-deployment -- ls                   # run command in first Pod and first container in Deployment (single- or multi-container cases)

Get container from pod

kubectl get pod management-tools-0 -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image -n cms-dev

Exec Management-tools

kubectl exec -n cms-dev --stdin --tty -c management-tools management-tools-0 -- /bin/bash

List pods and services

kubectl get pods -n cms-dev
kubectl get service -n cms-dev 
DRAFT
Weiterlesen: