Kubernetes - error: no resource "deployment" has been defined - kubernetes

I've install Kubernetes 1.3.5 on Ubuntu 14.04 server as a single-node-cluster.
I'm able to deploy docker images successfully and access the running container via HTTP and see them in docker ps.
When I try to follow the Kubernetes-Quick-Start after running the command kubectl run my-nginx --image=nginx --replicas=2 --port=80 the output is
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
my-nginx my-nginx nginx run=my-nginx 2
and it is not deployment "my-nginx" created.
Also when I run kubectl expose deployment my-nginx --target-port=80 --type=LoadBalancer I get the error:
error: no resource "deployment" has been defined
Did I miss something during the setup?

I was using an old version of Kubernetes 1.0.1.\
After update to 1.3.5 this was fixed.

Related

kubectl expose deployment not working with ingress-controller

I'm currently following a course on udemy called Microservices with Node JS and React from Stephen Grider, and I've come to a part where I need to run a command:
kubectl expose deployment ingress-nginx-controller --target-port=80 --type=NodePort -n kube-system
And this command is producing this error:
Error from server (NotFound): deployments.apps "ingress-nginx-controller" not found
when I run the command kubectl get deployments I do not see an ingress-nginx-controller deployment so I tried kubectl get namespace and I saw then entry ingress-nginx from that so I then tried kubectl get deployments -n ingress-nginx and then I finally see ingress-nginx-controller from output of that command. So I now know where the ingress-nginx-controller is but I am still pretty clueless as to how i get the initial command of kubectl explose deployment ingress-nginx-controller --target-port=80 --type=NodePort -n kube-system to work i've been stuck on this for a long time now any help is appreciated, thanks.
Edit 1: this is probably not relevant but I also tried putting ingress-nginx after the -n instead of kube-system and it did not work
Also I am using minikube on ubuntu
Edit 2: this is a screenshot of what the course wants me to do because I'm running minikube
The first time you ran it (with the correct namespace) it worked and you probably didn't notice. Your tutorial seems to be fairly out of date, you might want to find a newer one. If you want to remove the previously created service and do it again, kubectl delete service -n ingress-nginx ingress-nginx-controller.

Helm and minikube: service ip missing

I am trying examples from the book Learning Helm. I seem to be missing something. I cannot install chart from helm repo:
xxxxx:~ $ helm install my-nginx bitnami/nginx
NAME: my-nginx
LAST DEPLOYED: Sat Jan 9 20:26:22 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:
my-nginx.default.svc.cluster.local (port 80)
To access NGINX from outside the cluster, follow the steps below:
1. Get the NGINX URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
Watch the status with: 'kubectl get svc --namespace default -w my-nginx'
export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-nginx)
export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "http://${SERVICE_IP}:${SERVICE_PORT}"
xxxxx:~ $ export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-nginx)
xxxxx:~ $ export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
xxxxx:~ $ echo "http://${SERVICE_IP}:${SERVICE_PORT}"
http://:80
$ kubectl get svc --namespace default -w my-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx LoadBalancer 10.104.16.177 <pending> 80:30977/TCP 17h
Some more details.
The line in the following to extract the service IP is to get the external IP in the service object.
export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
In LoadBalancer service type, Kubernetes tries to get an external IP address and release the target service with that IP address. In self-hosted Kubernetes cluster, the external IP cannot be provisioned automatically. In most of the hosted clusters in public cloud, like GKE, EKS etc, they have had the integration with the external IP address provision. So, you can get it automatically once you set up the service as LoadBalancer.
It is still possible to do this automation with 3rd party operators/applications, like MetalLB. But in most of the self-hosted Kubernetes cluster, it is suggested to access the service with NodePort service type.
Please rerun the helm command with the follow argument. It will change the service type from LoadBalancer to NodePort. Following the instruction from the stdout may allow you to access your service.
> helm install my-nginx bitnami/nginx --set service.type=NodePort
On the other hand, you can follow the minikube official doc here to set up the support in LoadBalancer service.

Why service does not have any active Endpoint when install grafana from helm to kubernetes-sigs/kind?

https://github.com/kubernetes-sigs/kind - version 0.4.0
Create kubernetes from kubernetes-sigs/kind
kind create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.15.0) 🖼
kubectl create serviceaccount
kubectl create serviceaccount --namespace kube-system tiller
serviceaccount/tiller created
kubectl create clusterrolebinding
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
clusterrolebinding.rbac.authorization.k8s.io/tiller-cluster-rule created
kubectl patch deploy
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
deployment.extensions/tiller-deploy patched
helm init
helm install stable/nginx-ingress
helm install --name grafana stable/grafana --set=ingress.enabled=True,ingress.hosts={grafana.domain.com} --namespace demo --set rbac.create=true
kubectl logs loping-wallaby-nginx-ingress-controller-76d574f8b7-5m6n5
W0629 17:13:59.709497 6 controller.go:797] Service "demo/grafana" does not have any active Endpoint.
[29/Jun/2019:17:14:03 +0000]TCP200000.000
I0629 17:14:45.223234 6 status.go:295] updating Ingress demo/grafana status from [] to [{ }]
I0629 17:14:45.226343 6 event.go:209] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"demo", Name:"grafana", UID:"228cde81-cb97-4313-ad86-90a273b2206d", APIVersion:"extensions/v1beta1", ResourceVersion:"1938", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress demo/grafana
kubectl get ingress --all-namespaces
NAMESPACE NAME HOSTS ADDRESS PORTS AGE
demo grafana grafana.domain.com 80 3m58s
kubectl get svc --all-namespaces -l app=grafana
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default grafana ClusterIP 10.104.203.243 <none> 80/TCP 24m
kubectl get endpoints
NAME ENDPOINTS AGE
grafana 10.244.0.10:3000 21m
kubernetes 172.17.0.2:6443 56m
loping-wallaby-nginx-ingress-controller 10.244.0.8:80,10.244.0.8:443 48m
loping-wallaby-nginx-ingress-default-backend 10.244.0.7:8080 48m
Thanks!
A few concerns about your current scenario:
You have to check installed nginx-ingress helm chart in order to find out why grafana service resides in separate namespace default and not in demo namespace as per helm deploy parameter --namespace demo.
Since you have not specified in helm install command controller.service.type parameter, Nginx Ingress Controller would be implemented with LoadBalancer type of relevant service, in this case Ingress Controller expects to receive external IP address using cloud provider’s load balancer and I assume that your current kubernetes provisioner kubernetes-sigs/kind is not a good choice to adopt outward access to the Kubernetes cluster. Therefore, I would suggest to use NodePort service for Nginx Ingress controller in order to expose 80 and 443 port on some specific port in the host machine.
helm install --name grafana stable/grafana --set=ingress.enabled=True,ingress.hosts={grafana.domain.com} --namespace demo --set rbac.create=true --controller.service.type=NodePort
Issue that you mentioned is more like harmless and doesn't significantly affect the Nginx Ingress Controller's functionality, because it means that for some short period of time Liveness probe for Grafana Pod has not been initiated and target enpoint has not been released during Grafana Helm chart deploy. You can even re-spawn Nginx Ingress controller Pod to justify my assumption.
you are using type of service as "ClusterIp" , so you will not get external Ip address.
Change the Service type to "Loadbalancer" then you get Ip address which you can browse through internet.

How to start a pod in command line without deployment in kubernetes?

I want to debug the pod in a simple way, therefore I want to start the pod without deployment.
But it will automatically create a deployment
$ kubectl run nginx --image=nginx --port=80
deployment "nginx" created
So I have to create the nginx.yaml file
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
And create the pod like below, then it creates pod only
kubectl create -f nginx.yaml
pod "nginx" created
How can I specify in the command line the kind:Pod to avoid deployment?
// I run under minikue 0.20.0 and kubernetes 1.7.0 under Windows 7
kubectl run nginx --image=nginx --port=80 --restart=Never
--restart=Always: The restart policy for this Pod. Legal values [Always, OnFailure, Never]. If set to Always
a deployment is created, if set to OnFailure a job is created, if set to Never, a regular pod is created. For the latter two --replicas must be 1. Default Always [...]
see official document https://kubernetes.io/docs/user-guide/kubectl-conventions/#generators
Now there are two ways one can create pod through command line.
kubectl run nginx --image=nginx --restart=Never
OR
kubectl run --generator=run-pod/v1 nginx1 --image=nginx
See official documentation.
https://kubernetes.io/docs/reference/kubectl/conventions/#generators
Use generators for this, default kubectl run will create a deployment object. If you want to override this behavior use "run-pod/v1" generator.
kubectl run --generator=run-pod/v1 nginx1 --image=nginx
You may refer the link below for better understanding.
https://kubernetes.io/docs/reference/kubectl/conventions/#generators
I'm relatively new to kubernetes, but it seems it has evolved quite a bit since this question was asked. As of its latest versions(I'm running v1.16) generators are deprecated and they are completely removed in v1.18.
See the corresponding ticket and the release notes.
Release notes explicitly say:
Remove all the generators from kubectl run. It will now only create
pods.
I've tested kubectl run with various --restart flags and never got any deployments created. What we do have now is called "naked" Pod. And while you might be tempted to use it, it goes against k8s best practices:
Don’t use naked Pods (that is, Pods not bound to a ReplicaSet or
Deployment) if you can avoid it. Naked Pods will not be rescheduled in
the event of a node failure.
When you are using "kubectl run nginx --image=nginx --port=80" it creates a deployment by default.
To create a pod you have two options.
kubectl run --generator=run-pod/v1 nginx --image=nginx --port=80
kubectl create pod nginx --image=nginx --port=80

Using Traefik as an ingress controller for minikube

I am looking at traefik for an ingress controller for my minikube cluster. I have tried to follow the instructions provide in Traefik but my service External-IP is stuck in state indefinitely. Can anyone recommend a command that might explain why my service is failing to get an external-ip. kubectl describe svc traefik fails to provide any information. I have the latest minikube installed on MacOS with NO addons installed.
I also have the latest version of Helm installed. And executed the command
helm install --name ingress --namespace kube-system --set dashboard.enabled=true stable/traefik
I have successfully install nginx as an ingress controller.