Skip to main content

Steps for Applying YAML to a Running Container

  1. Check the current context

    k config current-context
  2. Get all the pods in the context

    k get pods
  3. Get the names of all the containers running in the pod

    k get pod <pod-name> -o=jsonpath='{.spec.containers[*].name}'
  4. Initialise a $yaml variable which has the yaml content, which is being applied.

    $yaml = @"
    apiVersion: networking.istio.io/v1alpha3
    kind: ServiceEntry
    metadata:
    name: httpbin-ext
    spec:
    hosts:
    - httpbin.org
    ports:
    - number: 80
    name: http
    protocol: HTTP
    resolution: DNS
    location: MESH_EXTERNAL"@
  5. Apply the above variable to the container

    $yaml | k apply -f -
  6. Now exec the command by connecting to the container's shell

    k exec my-pod -c my-container -- curl -sS http://httpbin.org/headers
  7. Now tail the container's log using the container logs

    k logs "$SOURCE_POD" -c my-container | tail

reference

Every Bit of Support Helps!

If you have enjoyed this post, please consider buying me a coffee ☕ to help me keep writing!