Dockerfile generation fails with `Cluster not found for context 'k8s.KubeConfigModels.Context' in kubeconfig`
See original GitHub issueIf I generate a new operator using the template, I get the following build failure:
Generating Dockerfile
Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> k8s.Exceptions.KubeConfigException: Cluster not found for context `k8s.KubeConfigModels.Context` in kubeconfig
at k8s.KubernetesClientConfiguration.SetClusterDetails(K8SConfiguration k8SConfig, Context activeContext)
at k8s.KubernetesClientConfiguration.InitializeContext(K8SConfiguration k8SConfig, String currentContext)
at k8s.KubernetesClientConfiguration.GetKubernetesClientConfiguration(String currentContext, String masterUrl, K8SConfiguration k8SConfig)
at k8s.KubernetesClientConfiguration.BuildConfigFromConfigObject(K8SConfiguration k8SConfig, String currentContext, String masterUrl)
at k8s.KubernetesClientConfiguration.BuildDefaultConfig()
at DotnetKubernetesClient.KubernetesClient..ctor()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ServiceProvider.GetService(Type serviceType)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.System.IServiceProvider.GetService(Type serviceType)
at McMaster.Extensions.CommandLineUtils.Conventions.ConstructorInjectionConvention.FindMatchedConstructor[TModel](ConstructorInfo[] constructors, IServiceProvider services, Boolean throwIfNoParameterTypeRegistered)
at McMaster.Extensions.CommandLineUtils.Conventions.ConstructorInjectionConvention.ApplyImpl[TModel](ConventionContext context)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at McMaster.Extensions.CommandLineUtils.Conventions.ConstructorInjectionConvention.Apply(ConventionContext context)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Builder.McMaster.Extensions.CommandLineUtils.Conventions.IConventionBuilder.AddConvention(IConvention convention)
at McMaster.Extensions.CommandLineUtils.ConventionBuilderExtensions.UseConstructorInjection(IConventionBuilder builder, IServiceProvider additionalServices)
at KubeOps.Operator.HostExtensions.RunOperatorAsync(IHost host, String[] args)
at CloudFormationStackOperator.Program.Main(String[] args) in <redacted>
at CloudFormationStackOperator.Program.<Main>(String[] args)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
No context found by kubectl when starting cluster with kind ...
I am currently executing all docker related commands as root user so this should not be the problem. Ah, that explains it. kubernetes...
Read more >Error in configuration: context was not found for specified ...
To access your Kubernetes cluster, kubectl uses a configuration file. The default configuration file is located at ~/.kube/config and is ...
Read more >Unable to run embedded Kubernetes on Docker Desktop ...
I checked that config file still resides at my user folder “.kube/config”. Setting appropriate environment variables makes the things working ...
Read more >how to set kubectl context - docker
I have discovered there is no context set in the kubectl config but if i run kubectl config get-contexts there is nothing there....
Read more >The connection to the server localhost:8080 was refused
Hello team, I have installed kubernetes in centos. After installation when i was checking the version with below command. I am getting error...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see… I don’t get the point of your suggestion clearly, do you mind explaining which executables you mean? I use the kubernetes client quite heavily in the operator sdk, so there is no replacing it. I had built a software once that used
kubectl
, but this is error prone as hell when using it over sub-processes.When we have a look at the method that builds the kube config out of “default”: https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs#L47-L71
Is any of this “if” 's true on your machine, or can you think of any reason why it does use the wrong config?
The steps are:
KUBECONFIG
environment var is set, if yes, use this file (or multiple files) as config<user home>/.kube/config
file exists, if yes, use this fileKUBERNETES_SERVICE_HOST
andKUBERNETES_SERVICE_PORT
set, and does the service account token as well as the root ca exist on the machine), if yes, build the kube config inside the clusterhttp://localhost:8080
I’m asking this, because - despite the usage of docker and stuff - I’ve got a classical “works on my machine” problem. I cannot reproduce the error.
BUT, what you could do: as soon as you added the operator stuff with the
AddKubernetesOperator
, you may remove the transient binding forIKubernetesClient
and add it with your specific config:All right. This issue is even a non-issue for the kubernetes client that I wrote. This logic is provided by the base kubernetes client over at https://github.com/kubernetes-client/csharp. I guess, this is expected behaviour.
If a cluster is not present or cannot be connected, the logic should fail.