Steps for Applying YAML to a Running Container
-
Check the current context
k config current-context
-
Get all the pods in the context
k get pods
-
Get the names of all the containers running in the pod
k get pod <pod-name> -o=jsonpath='{.spec.containers[*].name}'
-
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"@ -
Apply the above variable to the container
$yaml | k apply -f -
-
Now exec the command by connecting to the container's shell
k exec my-pod -c my-container -- curl -sS http://httpbin.org/headers
-
Now tail the container's log using the container logs
k logs "$SOURCE_POD" -c my-container | tail
Every Bit of Support Helps!
If you have enjoyed this post, please consider buying me a coffee ☕ to help me keep writing!