Deployment error while referring deployment yaml directly from remote URL - kubernetes

I have a file uploaded in cloud storage and when I try to deploy the yaml using the url of file it always throws below error, tried with multiple files and even with sample nginx yaml. Also I tried adding the same file in github repo but it did not help either
kubectl apply -f https://github.com/saurabhumathe/jfrog-docker-repo-simple-example/blob/master/nginx.yaml -n testnginx
error: error parsing https://github.com/saurabhumathe/jfrog-docker-repo-simple-example/blob/master/nginx.yaml: error converting YAML to JSON: yaml: line 148: mapping values are not allowed in this context
However, the same file works at below URL as given in k8s documentation.
https://k8s.io/examples/controllers/nginx-deployment.yaml
Does anyone know what the issue is with using yaml URL to deploy artefacts with kubectl ?

You are getting HTTP document instead of the yaml spec. Try using the raw url, example kubectl apply -f https://raw.githubusercontent.com/saurabhumathe/jfrog-docker-repo-simple-example/master/nginx.yaml

Related

No YAML Files in K8s Deployment

TLDR: My understanding from learning all about K8s is that you need lots and lots of yaml files, however, I just deployed an app to a K8s clusters with 0 yaml files and it succeeded. Why is that? Does google cloud or K8s have defaults it uses when the app does not have any yaml file settings?
Longer:
I have a dockerized spring app that I deployed to a google cloud cluster I created via the UI.
It had 0 yaml files in there, so my expectation that kubectl deploy would fail, however, it succeeded and my stateless app is up there chugging away.
How does that work?
Well the gcp created for you in the background. I assume you pushed your docker image or CI to cluster and from there you just did few clicks right? same stuff you can do it on openshift environment. but in the background yaml file get's generated. if you edit the pod on your UI you will see that yaml file.
as above #Volodymyr Bilyachat said you can create deployment via imparative way or using declarative way(yaml). I would suggest always use declarative way.
you can see your deployment yaml file which you created from UI by doing
kubectl get deployment <deployment_name> -o yaml
kubectl get deployment <deployment_name> -o yaml > name.yaml #This will output your yaml file into name.yaml file
You can run your containers/pods using plain commands.
kubectl run podname --image=name
As you said 0 yaml files. But main idea of those files that you push them to source control and run test them via different environments using CI/CD.
Other benefit of yaml files that you can share configuration and someone else will be able to create infrastructure without having to write anything. Here is example how you can run elasticsearch with one command
kubectl apply -f https://download.elastic.co/downloads/eck/1.2.0/all-in-one.yaml

How to view the manifest file used to create a Kubenetes resource?

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

kubernetes deployment- container not starting- error- InvalidImageName

Below is the Kubernetes deployment yaml file -container image section:
image: https://registry.ng.bluemix.net/****/test-service:test-branch-67
imagePullPolicy: Always
Below is the error message after deploying:
ubuntu#ip-xxxx:~$ kubectl logs test-deployment-69c6d8xxx -n test
Error from server (BadRequest): container "test-deployment" in pod "test-deployment-ccccxxx" is waiting to start: InvalidImageName
Another error log:
Failed to apply default image tag "https://registry.ng.bluemix.net/test/test-service:test-branch-66": couldn't parse image reference "https://registry.ng.bluemix.net/test/test-service:test-branch-66": invalid reference format
Any idea why the pod is not coming up?
Remove the https:// from the image name, and if you are using a private registry, make sure to use imagePullSecrets.
This could be because in your YAML file your image name would be wrong, maybe a tag missed, you can trace from there.
Please add your complete deployment file to know the problem in detail. But looking at the file make sure you are not missing
imagePullSecrets (Add valid credentials with access to pull the image from repository)
Also you need not provide the protocol like you added
https
Your image field in yml should look like below example:
image: repository:organization_name/image_name:image_version
curl --insecure -sfL https://192.168.2.217/v3/import/zc2t5qstv4l9f6wv8stmfsqcks47x7z5m4xnnrbf7hn9c9vj65bwd7_c-4mdds.yaml > tmp.yaml
# edit tmp.yaml file and delete https:/hub.docker.com/rancher/rancher-agent:v2.5.7 => rancher/rancher-agent:v2.5.7
# apply again:
kubectl apply -f tmp.yaml

Kubernetes Dashboard Update Deployment Issue

When I am trying to update the deployment by uploading an updated deployment.yaml, there is an error showing deployments.apps {my-app-name} already exists.
I know that I can update the image version from deployment, but I want to do all the work using yaml, so that I can keep track of what I am doing.
Thanks
p.s. I do not have console access to that machine, only the dashboard web interface.
please try following on command line :
kubectl apply -f deployment.yaml -n <namespace name>
To do this from dashboard by uploading the yaml file -
delete your existing deployment and upload the modified file. While your deployment is running, you cannot upload the file for the same deployment again.
Didn't find the other way as to update deployment through the Dashboard WEB UI submenu: Deployments > View/edit YAML.Seems that POST request within https://Web_ui_dashboard_IP/api/v1/appdeploymentfromfile does not support deployment modification.

Using kubectl to tear down from yaml

I created a .yaml file following this tutorial. You deploy the web service with kubectl apply -f shopfront-service.yaml. So far so good. The author says nothing though about how to tear everything down.
With TerraForm or CloudFormation you use the same .yaml file to remove all resources. I would think that K8 would also support cleaning up using the same .yaml file, but I can't find any way to do this.
Is there a way to delete resources with the same .yaml file used to create the deployment?
kubectl delete -f shopfront-service.yaml
see kubectl delete docs