양상헌:
Anyone can answer for this question in lighting lab,please?
Print the names of all deployments in the admin2406 namespace in the following format:
DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE
<deployment name> <container image used> <ready replica count> <Namespace>
. The data should be sorted by the increasing order of the deployment name.
Example:
DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE
deploy0 nginx:alpine 1 admin2406
Write the result to the file /opt/admin2406_data.
Hint: Make use of -o custom-columns and --sort-by to print the data in the required format.
kubectl get pods -A -o=custom-columns=‘DATA:spec.containers[*].image’
so I tried like below but lighting lab got error…
DEPLOYMENT:metadata.namespace
CONTAINER_IMAGE:spec.containers[*].image
READY_REPLICAS:spec.replicas
NAMESPACE:metadata.namespace
DEPLOYMENT:metadata.namespace,CONTAINER_IMAGE:spec.containers[*].image,READY_REPLICAS:spec.replicas,NAMESPACE:metadata.namespace
so my answer is like ;
kubectl get deploypods -n admin2406 -o=custom-columns=‘DEPLOYMENT:metadata.namespace,CONTAINER_IMAGE:spec.containers[*].image,READY_REPLICAS:spec.replicas,NAMESPACE:metadata.namespace’
is this correct, or correct me…thanks in advance.
Alicio Cerqueira:
hello, I created the resources here on my minikube
k create ns admin2406
k create deploy test-deploy-01 --image=nginx --namespace=admin2406 --replicas=1
k create deploy test-deploy-02 --image=nginx --namespace=admin2406 --replicas=2
Alicio Cerqueira:
k get deploy -n admin2406 -o=custom-columns=DEPLOYMENT:metadata.name,CONTAINER_IMAGE:spec.template.spec.containers[*].image,READY_REPLICAS:status.readyReplicas,NAMESPACE:metadata.namespace --sort-by=.metadata.name
Alicio Cerqueira:
this what I got
Alicio Cerqueira:
I hope it can help u
양상헌:
thank you very much Alicio,I should revisit the details on mine…(I also forgot sorting…^^)
Lakshminarayanan Krishnan:
There is one more way to get the output in the manner you want, without breaking your fingers with the custom-columns, which is to use custom-columns-file
option. Simply write out the columns expected into a template file, like so:
echo "DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE" > template.txt
Next, view the deployments in yaml format (or json format if you so prefer) using the command:
kubectl get deployments -n admin2406 -o yaml > deps.yaml
View the yaml file and get the paths to the spec that is expected, and edit the template.txt
file mentioned above appropriately, so the contents would be:
DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE
.metadata.name .spec.template.spec.containers[*].image .status.readyReplicas .metadata.namespace
Finally, execute the following command:
kubectl get deployments -n admin2406 -o custom-columns-file=template.txt --sort-by=.metadata.name
1 Like
use this yaml it’s pretty simple use correct volume name,mountpath, secretname and namespace in yaml.
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: secret-1401
name: secret-1401
namespace: admin1401
spec:
containers:
- command:
- sleep
- “4800”
image: busybox
name: secret-1401
resources: {}
volumeMounts:
- name: secret-volume
mountPath: “/etc/secret-volume”
readOnly: true
volumes:
- name: secret-volume
secret:
secretName: dotfile-secret
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}