I want to apply a folder which contains some yaml file and also to change the image which is used in a deployment. Is it possible to do something like:
kubectl apply -k ./folder set image xxx -n namespace
Related
Kubectl allows you to create ad hoc jobs based on existing crons.
This works great but in the documentation there is no specification for passing arguments upon creation of the job.
Example:
kubectl -n my-namespace create job --from=cronjob/myjob my-job-clone
Is there any way I can pass arguements to this job upon creation?
Although kubectl currently does not allow you to use the --from flag and specify a command in the same clause, you can work around this limitation by getting the yaml from a dry run and using yq to apply a patch to it.
For example:
# get the original yaml file
kubectl create job myjob --from cronjob/mycronjob --dry-run=client --output yaml > original.yaml
# generate a patch with your new arguments
yq new 'spec.template.spec.containers[0].args[+]' '{INSERT NEW ARGS HERE}' > patch.yaml
# apply the patch
yq merge --arrays update patch.yaml original.yaml > final.yaml
# create job from the final yaml
kubectl create -f final.yaml
Ok turns out that kubectl does not allow you to use the --from and specify a command in the same clause.
You will get the following error cannot specify --from and command.
For example:
kubectl create job --from=cronjob/my-job.yaml my-job-test -- node run.js --date '2021-04-04'
error: cannot specify --from and command
So in short you cannot use your existing cron template and specify a command.
Closest thing you can get is use the --image flag and manually pass in the image that your file needs, then specify the command and args after.
kubectl create job --image=<YOUR IMAGE NAME> my-job-test -- node run.js --date '2021-04-04'
job.batch/my-job-test created
I am trying to install Kube Prometheus Stack using helm.
I have already setup ingress, so it needs to be running behind a proxy.
For that I have updated values of the chart by using below command.
helm show values prometheus-com/kube-prometheus-stack > values.yaml
I followed this doc and changed configurations,
[server]
domain = example.com
Now I am trying to install using below command.
helm install monitoring ./values.yaml -n monitoring
I have already created a namespace monitoring
I get below error on running above command.
Error: file '/home/user/values.yaml' seems to be a YAML file, but expected a gzipped archive
Your helm command should be something like this:
$ helm install <release-name> <registry-name>/<chart-name> --values ./values.yaml -n monitoring
I need to use now multiple cluster, currently what I did is simple put all the kubeconfig
under .kube folder and any time update the config file with the cluster which I need , e.g.
mv config cluserone
vi config
insert new kubeconfig to the config file and start working with the new cluster,
Let say inside the /Users/i033346/.kube I've all the kubeconfig file one by one.
is there a way to use them as contexts without creating a new file which contain all of them.
I try to use also kubectx however when I use:
export KUBECONFIG=/Users/i033346/.kube/trial
and
export KUBECONFIG=/Users/i033346/.kube/prod
and use kubectx I always get the last one and doenst get list of the defined contexts,any idea?
KUBECONFIG env var supports multiple files, comma-separated:
export KUBECONFIG="/Users/i033346/.kube/trial,/Users/i033346/.kube/prod"
This should be enough to see all of them in kubectx.
You can even merge all configs to 1 file:
export KUBECONFIG="/Users/i033346/.kube/trial,/Users/i033346/.kube/prod"
kubectl config view --flatten > ~/.kube/config
What I used to do in this scenario is to create multiple aliases pointing to different config files.
e.g
in your .bashrc/.zshrc
edited in your ~/.bashrc or your ~/.zshrc
alias k-cluster1="kubectl --kubeconfig /my_path/config_cluster1"
alias k-cluster2="kubectl --kubeconfig /my_path/config_cluster2"
after loading the terminal k-cluster1 get pods or k-cluster2 get pods should work
I am writing a script which involves kubectl delete , it is of course existential to run in against correct context-cluster.
The problem is that from what I observe, if you open two terminals and do:
kubectl config use-context bla
in one window, then the other one will switch as well. Therefore, concern if something switches context during script execution my delete operation will start deleting resources in the wrong cluster.
I understand that I could use labels on my pods or different namespaces, but in my case namespaces are the same and there are no labels.
So is there a way to specify for each command individually which context it should execute against? Something like:
kubectl get po use-context bla
Use the --context flag:
kubectl get po --context bla
If you run any kubectl command, you'll also see it says you can run kubectl options to see a list of global options that can be applied to any command. --context is one such global option.
I am trying to resgister an amazon image, and I keep getting the error Client.null: null.
I am able to browse to the URL and see the xml file.
The command I execute is:
ec2-register output.raw.manifest.xml -U <URL>
Client.null: null
any idea what could be the problem?
Thanks!
Keep in mind that this command is used to register instance store images rather than EBS back images.
Usually the xml file with a series of 10GB files are uploaded to S3 prior to registering the AMI. Are you sure the bundle is in one of your S3 buckets?
Did you run something like this from the instance you want to create the image from?:
ec2-bundle-vol -d /<someplace-where-you-have-a-lot-of-space> -k YOUR_PRIVATE_KEY -c YOUR_CERTIFICATE -u YOUR_ACCOUNT_NUMBER
ec2-upload-bundle -b YOUR_BUCKET_NAME -m output.raw.manifest.xml -a YOUR_ACCESS_KEY -s YOUR_SECRET_KEY
Then you can run:
ec2-register output.raw.manifest.xml
You can also register your image from the AWS console once you have created the bundle like shown here:
There are several blogs that talk about how to do this too. For example:
http://www.ryannitz.org/tech-notes/2009/08/09/create-amazon-ec2-ami/
Finally, if you are registering and EBS backed AMI you can just simply use:
ec2-create-image <instance id>