Is there any kubectl command to bootstrap yaml file for certain object?
For example
kubectl generate deployment --yml
After which I would fill it with values I want.
Thanks
You could try playing with:
kubectl create <resourcetype> <otheroptions> --output=yaml --dry-run
See:
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#create
for different <resourcetype> you could use this with.
Related
Is there an easy way to query for all deployments that use given ConfigMap as valueFrom: configMapKeyRef.
I need to know which deployments use my config map in order to be able to restart them after the config map changes.
I'm looking for something like:
kubectl get deployments --with-config-map my-config-map
There is no way to do it as easily as you want. However you can still get the data you want in one command by using jsonpath as the output of your kubectl command.
I am using helm to deploy my applications which has deployments, pods and jobs and others.
Is there any way to get "kubectl describe" output of all objects loaded by "helm install" ?
Tell me if it is working, but I tried with my helm charts (custom one, ES and kibana).
TL;DR
kubectl get all -l chart=myb5 -n myb5
-n stands for namespace
-l stands for label
Explanations
Labeling your kubernetes objects is really important, and most of the helm charts out there are using labels to easily access and select objects.
When you install a chart, it adds a label such chart=my-chart-name. If the chart is not using it (maybe you are creating one for yourself), it is a good practice to add it.
So querying all resources with get all should retrieve all the resources created in the default namespace.
Depending where you installed your helm chart, it is good to add the namespace field in your query.
Note that if you use 1 namespace for only 1 helm chart resources, you do not need to filter with labels.
PS: should work the same with describe ;)
Best,
Since you're using helm install, i assume your Chart's resources are installed into a specific namespace.
In that case, you can simply use the command kubectl describe all -n <your-namespace>.
Its output should be the same as using kubectl describe on each resource of your Helm Chart.
kubectl describe all -l chart=<chartName> -n namespace
or
kubectl get events -n namespace -w
I have a yaml file which works if I deploy it using
kubectl apply -f myComponents.yaml
My question is, is there a way to deploy just one component from this YAML? For example, if my YAML has both deployment and service and I just want to deploy the service
I am looking for something like
kubectl apply -f myComponents.yaml Service
No. ⛔
At least not yet. Currently, you can take advantage of tools like kustomize, to apply/create/delete what you'd like, but that's not necessarily the same thing.
Having said I've made a feature request for kubectl 💡.
✌️
No. You can use a command line tool to do this like yq though, depending on how fancy you want to be:
cat myComponents.yaml | yq 'some selector' | kubectl apply -f -
I'm new to k8s and I'm trying to learn how to setup deployments.
I'm searching for a way to create a new deployment without any images. Over time, I will add new (0 or more) images (and specify thier desired state). As I don't know what images the deployment will contain in advance, I can't use any existing configuration files.
Is it possible? If yes, how?
If it's possible, a command-line solution will be great.
If you want to start a single instance of nginx, you can do
$ kubectl run nginx --image=nginx
But it is not possible to create any deployments without image.
$ kubectl run demo --image=""
error: --image is required
If you want to edit your existing deployment, then you can run
$ kubectl edit deployments <deployment-name> -n <namespace>
You can also patch container with new image to existing deployments by running following command
$ kubectl patch deployment <deployment-name> -p '{"spec":{"template":{"spec":{"containers":[{"name":"myapp","image":"newimage"}]}}}}'
To replace image of a containers in deployment, run
$ kubectl set image deployment/<deployment-name> <container-name>=<image>
I have K8s deployed on an EC2 based cluster,
There is an application running in the deployment, and I am trying to figure out the manifest files that were used to create the resources,
There were deployment, service and ingress files used to create the App setup.
I tried the following command, but I'm not sure if it's the correct one as it's also returning a lot of unusual data like lastTransitionTime, lastUpdateTime and status-
kubectl get deployment -o yaml
What is the correct command to view the manifest yaml files of an existing deployed resource?
There is no specific way to do that. You should store your source files in source control like any other code. Think of it like decompiling, you can do it, but what you get back is not the same as what you put in. That said, check for the last-applied annotation, if you use kubectl apply that would have a JSON version of a more original-ish manifest, but again probably with some defaulted fields.
You can try using the --export flag, but it is deprecated and may not work perfectly.
kubectl get deployment -o yaml --export
Refer: https://github.com/kubernetes/kubernetes/pull/73787
KUBE_EDITOR="cat" kubectl edit secrets rook-ceph-mon -o yaml -n rook-ceph 2>/dev/null >user.yaml