Okay, so let's go through the lab on KubeConfig or security context.
Where is the default kubeconfig file located in the current environment?
Find the current HOME directory by looking at the HOME environment variable.
Let's look at HOME,
and HOME is set root which is current directory we're in.
We know that it's usually under the hidden kube directory.
We have our kube directory here, and we have config here.
If you look at this, you have .kube/config
and that's really the kubeconfig file.
It's at root.kube/config.
root.kube/config.
That's the one.
Now how many clusters are defined in the default kubeconfig file?
If you look at this, in your clusters,
you have one cluster, and then you have context.
So you just have one cluster.
That's one.
How many users are defined in the default kubeconfig file?
Here, see the users are just one again.
Here you have the user,
and you have the certificate information here,
so it's just one.
How many contexts are defined in the default kubeconfig file?
If you look at the context, you have one.
That's just one, so you just have one context.
Now, what is the user configured in the current context?
If you look at the current context, it's kubernetes-admin@kubernetes.
That's the name of the context, and so that is this.
This is that context.
If you look at this, the user is kubernetes-admin.
Remember that this is just the name,
so you shouldn't assume that this is the actual user configured,
but it so happens that in this case,
the naming convention is this user at the cluster,
but you should always look at this field.
This is the actual user that's configured for that context.
It is kubernetes-admin.
What is the name of the cluster configuring the default kubeconfig file?
The name of the cluster, so this is the cluster,
and the name is kubernetes.
Okay, so a new kubeconfig file named my-kube-config is created,
and it's in the root directory.
Let's look at that.
My-kube-config,
and it is placed in the root directory,
and how many clusters are defined in that kubeconfig file.
Let's look at this file, so you have one, two, three, four, four clusters.
How many contexts are configured in the my-kube-config file?
If you look at this, you have one, two, three, four, four context.
What user is configured in the research context?
If you look at the research context,
you see that the user is dev-user,
so that's dev-user, is that user.
Now, what is the name of the client certificate file
configured for the aws-user?
You have users here and you have aws-user,
the client certificate file, the file name is aws-user.crt,
so that's aws-user.crt.
What is the current context set to in the my-kube-config file?
The current context, as you can see here,
it's test-user@development, so that's the current context.
That's test-user@development.
Now, I would like to use the dev-user to access test-cluster-1,
and set the current context to the right one,
so I can do that.
Once the right context is identified,
use the kubectl config use-context command.
So dev-user to access test-cluster-1.
We're going to look at context and dev-user.
This is the dev-user,
and to access test-cluster-1, there's already a context called research,
so we're going to use that.
What we need to do is use the kubectl config command,
so kubectl config command
and use for use-context command,
and the context that we're going to use is research.
Now remember that by default, the kubectl config command
will use the default kubeconfig file which is in root.kube/config.
This is in a different file that we want it to work on
so we have to provide this file name like this.
Okay, so I switched to context research.
Let's check it out.
We see that the current context within the file is set to research.
Okay, let's check the work.
Now, we don't want to have to specify the kubeconfig file option on each command
to make the main cube config, file the default kubeconfig file.
This is what we want to use going forward.
What we're going to do is
we're going to move this kubeconfig file
as a default one, which is available here.
Let's make sure that move is complete.
Yes.
Going forward, we don't have to do
a kubectl config view.
We can see that this is the new view.
Yes, check it.
This is the new file.
Now, with the current context set to research,
we are trying to access the cluster, however, something seems to be wrong,
identify and fix the issue.
Let's do a kubectl get nodes command,
we see that there's something wrong.
It says unable to read client-cert
/etc/kubernetes/pki/user /dev-user/developer-user.crt
for the dev-user.
Let's check the contents of the file.
We see that the dev user
has client certificate,
which is set to dev-user/developer-user.crt.
Now, all user certificates are stored in this directory.
Let's go here.
We have the dev user.
Let's go here.
We see that it's dev-user.crt, dev-user.csr, dev-user.key.
It's dev-user.crt, not developer user.crt.
We're going to have to modify that.
Let's go in
and let's change this,
so that's fixed.
Let's try it again.
Yes, that seems to be working.
Okay, so that is the end of this lab.