`kubectl` not found. If you need it, try: 'minikube kubectl -- get pods -A' - kubernetes

I installed minikube in Windows 10 . I am able to start minikube
**C:\WINDOWS\system32>minikube start
* minikube v1.15.1 on Microsoft Windows 10 Pro 10.0.18363 Build 18363
* Using the hyperv driver based on existing profile
* Starting control plane node minikube in cluster minikube
* Restarting existing hyperv VM for "minikube" ...
* Preparing Kubernetes v1.19.4 on Docker 19.03.13 ...
* Verifying Kubernetes components...
* Enabled addons: storage-provisioner, default-storageclass
* kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default**
But there is a warning in above output ( 2nd last line ) says
kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
After that I executed this command too minikube kubectl -- get pods -A
Still getting below error while trying kubectl
C:\WINDOWS\system32>kubectl
'kubectl' is not recognized as an internal or external command,
operable program or batch file.

Minikube installs kubectl inside of itself.
So to use the kubectl which you installed via minikube, you have to prepend the command arguments with minikube kubectl --. For example:
# the same as `kubectl version --client`
minikube kubectl -- version --client
For convenience, you may want to add an alias in your shell configuration.
Source: https://minikube.sigs.k8s.io/docs/handbook/kubectl/

kubectl is wrapped around minikube.
Don't forget to add a -- after minikube kubectl
minikube kubectl -- describe pod kube-scheduler-minikube --namespace kube-system
minikube kubectl -- get pods --namespace kube-system

You have installed minikube, kubectl is not a part of minikube package.
It says when you do minikube start that kubectl is not present and if you need to you can use minikube kubectl instead.
This is also mentioned here
If you already have kubectl installed, you can now use it to access your shiny new cluster

It means that the kubectl might not be present on your machine or that it is not added to your PATH.
You can follow these instructions to install it either by downloading executable or by using curl:
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/windows/amd64/kubectl.exe
After that add the binary to PATH.
You can run kubectl version --client to ensure correct version is downloaded.

Use doskey.exe to create an alias for kubectl.
Example:
doskey kubectl="%PROGRAMFILES%\Kubernetes\Minikube\minikube.exe" kubectl -- $*
You might need to update the path if you've installed minikube somewhere else.

Related

Unknown image flag when creating deployment using Minikube kubectl

I am getting unknown image flag when creating a deployment using minikube on windows 10 cmd. Why?
C:\WINDOWS\system32>minikube kubectl create deployment nginxdepl --image=nginx
Error: unknown flag: --image
See 'minikube kubectl --help' for usage.
C:\WINDOWS\system32>
When using kubectl bundled with minikube the command is little different.
From the documentation, your command should be:
minikube kubectl -- create deployment nginxdepl --image=nginx
The difference is the -- right after kubectl
there problem is your command. you are mixing kubectl and minikube.
minikube is for managing your one-node local dev cluster.
kubectl is used for interacting with your cluster.
you should be using the following command:
kubectl create deployment nginxdepl --image nginx

kubectl -- create -h works but kubectl create -h doesn't

Running 'minikube' on windows 10, why minikube kubectl create -h doesn' work but minikube kubectl -- create -h does (w.r.t. showing help for create)
This is the way minikube works:
Minikube has a subcommand kubectl that will exectute the kubectl bundled with minikube (because you can also have one installed outside of minikube, on your plain system).
Minikube has to know the exact command to pass to its kubectl, thus minikube splits the command with --.
It's used to differentiate minikube arguments and kubectl's.

Minikube - /var/log/kubeproxy.log: No such file or directory

I am trying to find the kubeproxy logs on minikube, It doesn't seem they are located.
sudo cat: /var/log/kubeproxy.log: No such file or directory
A more generic way (besides what hoque described) that you can use on any kubernetes cluster is to check the logs using kubectl.
kubectl logs kube-proxy-s8lcb -n kube-system
Using this solution allow you to check logs for any K8s cluster even if you don't have access to your nodes.
Pod logs are located in /var/log/pods/.
Run
$ minikube ssh
$ ls /var/log/pods/
default_dapi-test-pod_1566526c-1051-4102-a23b-13b73b1dd904
kube-system_coredns-5d4dd4b4db-7ttnf_59d7b01c-4d7d-40f9-8d6a-ac62b1fa018e
kube-system_coredns-5d4dd4b4db-n8d5t_6aa36b9a-6539-4ef2-b163-c7e713861fa2
kube-system_etcd-minikube_188c8af9ff66b5060895a385b1bb50c2
kube-system_kube-addon-manager-minikube_f7d3bd9bbbbdd48d97a3437e231fff24
kube-system_kube-apiserver-minikube_b15fea5ed20174140af5049ecdd1c59e
kube-system_kube-controller-manager-minikube_d8cdb4170ab1aac172022591866bd7eb
kube-system_kube-proxy-qc4xl_30a6100a-db70-42c1-bbd5-4a818379a004
kube-system_kube-scheduler-minikube_14ff2730e74c595cd255e47190f474fd

What version of Operator Lifecycle Manager (OLM) am I running in my cluster?

I'm running an OpenShift cluster and am trying to figure out what version of OLM in installed in it. I'm considering an upgrade, but would like more details.
How can I find the version?
From the CLI:
You can change kubectl for oc since you are using OpenShift.
First find the name of an olm-operator pod. I'm assuming Operator Lifecycle Manager is installed in the olm namespace, but it might be "operator-lifecycle-manager".
kubectl get pods -n olm |grep olm-operator
Then run a command on that pod like this:
kubectl exec -n olm <POD_NAME> -- olm --version
From the Console:
Navigate to the namespace and find an olm-operator pod. Open the "Terminal" tap and run olm --version.
In either case, the output should be something like this:
OLM version: 0.12.0
git commit: a611449366805935939777d0182a86ba43b26cbd

Difference between kubectl and minikube-kubectl

I'm using Mac OS for development environment.
If I install minikube, the kubectl will use the local cluster made by minikube as a default option. I found I can use kubectl command with minikube prefix - just like below:
$ minikube kubectl get pods
So I tried it, and kubectl download process began. So I can get that the kubectl in my Mac and the kubectl in minikube is not identical. But what does thie mean?
It's just a wrapper for kubectl, downloading it when not installed, otherwise executing the client.
See the command with '--help' below.
$ minikube kubectl --help
Run the kubernetes client, download it if necessary.
Usage:
minikube kubectl [flags]
Flags:
-h, --help help for kubectl
Global Flags:
[...]