Posted on 2 Comments

error: the namespace from the provided object does not match the namespace. You must pass –namespace to perform this operation

When you need to copy a secret from one namespace to another in a Kubernetes cluster you may face the below error.

error: the namespace from the provided object "" does not match the namespace "". You must pass --namespace to perform this operation

The issue can be found because of the origin namespace that is referenced inside the secret. In order to bypass you can export the secret and change the referenced namespace.

kubectl get secret mysecret --namespace=ns1 -o yaml > export.yaml

In order to get it work you will need to change the namespace according to your new namespace in the export.yaml and apply it.

namespace: ns2
Posted on Leave a comment

Install kubernetes plugins with krew

There are a lot of tools built around Kubernetes the industry standard orchestration tool that enterprises use in order to host micro-services. One open source project which allow you to install helpful plugins for k8s is krew and you can find it on GitHub.

By installing krew, you will get access to many helpful plugins that have been created for developers and uploaded to krew marketplace. One example of these plugins is the resource-capacity plugin which gives you at a glance limit, resources usage for your k8s pods.

First you will need to install krew for your operating system. The installation instructions can be found in the link below, and you should follow the steps provided.

If you use windows, you will need to add krew on your path in order to have the tool available on your command line. First navigate in your system advanced settings and press environmental variables.

Then you will need to add in your path variable, the installation path of krew which should be %USERPROFILE%\.krew\bin

After installing krew, you can run a command to verify if PATH variables work. You will need first to restart your cmd

As a last step you can install plugins using krew with

kubectl krew install plugin-name

In my case I installed the resource capacity plugin which give CPU, Memory Requests and Limits for your k8s cluster.

FInally you can find your installed plugins inside .krew/store folder.

Posted on Leave a comment

Error while proxying request: getting credentials: exec: executable kubelogin not found

For those who do not know Lens, it is a powerful IDE tool for managing Kubernetes. When it comes to k8s administration, sometimes command line would be a pain for engineers so various companies create tools that can provide the same functionality with a modern GUI. Such tool is Lens and you can find it using the link below.

After you setup Lens you may encounter an error when you try to connect to your k8s cluster.

The error indicates that you are missing kubelogin tool. You can verify that by typing kubelogin –version in the command line. If you get an error you should go and install the tool.

Following the instructions provided by the documentation you will be able to install kubelogin.

I personally used the setup for windows through powershell.

After you install kubelogin, close and open the application again so that the PATH settings get updated. Finally you will be able to browse your cluster with Lens.

Posted on Leave a comment

kubectl commands cheat sheet for daily kubernetes administration

This is a cheat sheet for basic k8s commands that one k8s administrator can use daily.

Apply a YAML definition on k8s-cluster:

kubectl apply -f pod.yaml

Apply a definition on specific namespace:

Kubectl apply -f kati.yml -n namespacename

Create a new namespace:

kubectl create ns namespacename

Set k8s cluster context:

kubectl config use-context geralexgr-aks

Get k8s cluster context:

kubectl config view

Create a deployment:

kubectl create deployment new-app --image=hello-world:latest

Delete a deployment:

kubectl delete deployment nginx -n nginx

Describe a service:

Kubectl describe service/myservice

Get logs for pod:

Kubectl logs pod-123

Get cluster namespaces:

kubectl get namespace

Set active namespace:

kubectl config set-context --current --namespace nginx

Delete a pod:

kubectl delete pod nginx-pod

Scale a deployment:

kubectl scale --replicas=5 deployment/deploymentname

Get pods with labels:

kubectl get pods --show-labels

Get cluster scoped resources:

kubectl api-resources