Kubernetes apply command produces 'wrong encoding error' - kubernetes

I'm trying to execute:
microk8s kubectl apply -f deployment.yaml
and I am always getting:
error: string field contains invalid UTF-8
No matter which file and string as a file path parameter I'm trying to use. Even if I execute:
microk8s kubectl apply -f blablabla
Result is the same.
UPD: I resolved the problem by restarting microk8s service. After restart everything is fine, but I still have no idea what it was.

I have posted Community Wiki answer for better visibility.
As OP has mentioned in the question, he resolved the problem by restarting microk8s service:
I resolved the problem by restarting microk8s service. After restart everything is fine.

This is not a wrong format in the manifest, instead, it's a corrupted cache in $HOME/.kube/
try to delete the cache:
rm -rf $HOME/.kube/http-cache
rm -rf $HOME/.kube/cache

Related

error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

I have KUBECONFIG inside my .kube/ folder still facing this issue.
I have also tried
kubectl config set-context ~/.kube/kubeconfig.yml
kubectl config use-context ~/.kube/kubeconfig.yml
No luck! Still the same.
Answering my own question
Initially, I had lost a lot of time on this error, but later I found that my kubeconfig is not having the correct context.
I tried the same steps:
kubectl config set-context ~/.kube/kubeconfig1.yml
kubectl config use-context ~/.kube/kubeconfig1.yml
or add a line with kubeconfig to your ~/.bashrc file
export KUBECONFIG=~/.kube/<kubeconfig_env>.yml
Also, if you want to add multiple kubeconfig: Add it like in ~/.bashrc file
export KUBECONFIG=~/.kube/kubeconfig_dev.yml:~/.kube/kubeconfig_dev1.yml:~/.kube/kubeconfig_dev2.yml
with different Kube contexts and it worked well.
Though the error should simplify and return the specific error related to kubecontext.
But after some digging it worked.
if u are running k3s u can put the following line to ur ~/.zshrc / ~/.bashrc
k3s
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
By default, kubectl looks for a file named config in the $HOME/. kube directory. So you have to rename your config file or set its location properly.
Look here for more detailed explanation
I had the same problem because I used the Linux subsystem on Windows.
If you use the command kubectl in the subsystem, you must copy your config file to part of the Linux system.
For example, if your username on Windows is jammy, and your username is also jammy in the Linux subsystem, you must copy the config file
from:
/mnt/c/Users/jammy/.kube/config
to:
/home/jammy/.kube/

Getting error while trying to setup kubernetes on debian using helm

While running the helm init I was getting an error:
Error: error installing: the server could not find the requested resource (post deployments.extensions)
But I solved it by running :
helm init --client-only
But when I run:
helm upgrade --install --namespace demo demo-databases-ephemeral charts/databases-ephemeral --wait
I'm getting:
Error: serializer for text/html; charset=utf-8 doesn't exist
I found nothing convincing as a solution and I'm not able to proceed forward in the setup.
Any help would be appreciated.
Check if your ~/.kube/config exists and is properly set up. If not, run the following command:
sudo cp -i /etc/kubernetes/admin.config ~/.kube/config
Now check if kubectl is properly setup using:
kubectl version
This answer is specific to the issue you are getting. If this does not resolve the issue, please provide more error log.
Apparently, your kube-dns pod not able to find api server, so it returns text/html, rather then JSON
1) Check errors in dns container apart from Error: serializer for text/html; charset=utf-8 doesn't exist
kubectl logs <kube-dns-pod> -n kube-system kubedns
2) Update your dns pod config with following flags:
--kubecfg-file=~/.kube/config <-- path to your kube-config file
--kube-master-url=https://0.0.0.0:3000 <--address to your master node

gcloud command changes ownership of the current directory

I'm performing usual operation of fetching kubernetes cluster credentials from GCP. The gcloud command doesn't fetch the credentials and surprisingly updates the ownership of the local directory:
~/tmp/1> ls
~/tmp/1> gcloud container clusters get-credentials production-ng
Fetching cluster endpoint and auth data.
ERROR: (gcloud.container.clusters.get-credentials) Unable to write file [/home/vladimir/tmp/1]: [Errno 21] Is a directory: '/home/vladimir/tmp/1'
~/tmp/1> ls
ls: cannot open directory '.': Permission denied
Other commands, like gcloud container clusters list work fine. I've tried to reinstall the gcloud.
This happens if your KUBECONFIG has an empty entry, like :/Users/acme/.kube/config
gcloud resolves the empty value as the current directory, changes permissions and tries to write to it
Reported at https://issuetracker.google.com/issues/143911217
It happened to be a problem with kubectl. Reinstalling it solved this strange issue.
If you, like me, have stuck with strange gcloud behavior, following points could help to track an issue:
Checking alias command and if it's really pointing to the intended binary;
Launch separate docker container with gsutil and feed it your config files. If the gcloud container clusters get-credentials ... runs smoothly there, than it's the problem with binaries (not configuration):
docker run -it \
-v $HOME/.config:/root/.config \
-v $HOME/.kube:/root/.kube google/cloud-sdk:217.0.0-alpine sh
Problem with binary can be solved just by reinstalling/updating;
If it's a problem with configs, then you could back them up and reinstall kubectl / gsutil from scratch using not just apt-get remove ..., but apt-get purge .... Be aware: purge removes config files!
Hope this would help somebody else.

restarting kube-proxy wating for conditions

While running the minikube start in windows 10, getting the following error.
Error : Error restarting cluster: restarting kube-proxy: waiting for kube-proxy to be up for configmap update: timed out waiting for the condition
Please help me resolve the give issue, I delete the minikube and restarted many time.
I faced the same issue on Centos 7
minikube delete
then
minikube start
solved my issue
I was getting the same error on mac os, tried almost everything but finally, this comment on GitHub saved my life :)
see steps
Now minikube has started as expected:
Below steps works for me :
Note : Do not work with root user
$ sudo minikube stop
$ sudo minikube delete
$ sudo rm -rf ~/.minikube
$ sudo minikube start --kubernetes-version=v1.12.4
you can specify any existing kubernetes version of your choice with prefix v compulsory
make sure .minikube directory created in users home directory but not in /root

Not able to create a file using kubectl

I recently started working on microservices. I am building my docker image and want to deploy it on kubernetes. while creating a pod.yaml file I started getting the below error.
Command :
kubectl create -f podservice.yaml
Error :
error: the path "podcpeservice.yml" does not exist
Tried using the helpfor kubectl create -f help. An example in the help document is
command :
kubectl create -f ./pod.json
Even the above command gives the same error. Not able to figure out what is the problem. tried removing ./
I am using centos 7 on virtual-box with windows 7 as host.
Tushar,
First you need to create the deployment yml file using one of the editor, then pass the file as argument for kubectl command.
eg.
kubernets team already created this deployment file. you use kubectl to deploy.
kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
Somehow the filename was corrupted with unseen symbol so this helped me to get over wrong naming
mv postgres-configmap.yaml\ postgres-configmap.yaml
and then it worked:
kubectl create -f postgres-configmap.yaml
configmap/postgres-config created