이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 8. Node access with kubeconfig files
Kubeconfig files supply node details, IP addresses, and authentication so that CLI tools can communicate with the API server of a node. You can use them for local access, remote access, generating additional files, and opening firewall access when needed.
8.1. Kubeconfig files for configuring node access 링크 복사링크가 클립보드에 복사되었습니다!
The two categories of kubeconfig files used in MicroShift are local access and remote access. Each time MicroShift starts, it generates a set of kubeconfig files for accessing the API server. These files are created in the /var/lib/microshift/resources/kubeadmin/ directory by using existing configuration information.
Each access type requires a different authentication certificate signed by different Certificate Authorities (CAs). The generation of multiple kubeconfig files accommodates this need.
You can use the appropriate kubeconfig file for the access type needed in each case to provide authentication details. The contents of MicroShift kubeconfig files are determined by either default built-in values or a config.yaml file.
A kubeconfig file must exist for the cluster to be accessible. The values are applied from built-in default values or a customized config.yaml file.
Example contents of the kubeconfig files
/var/lib/microshift/resources/kubeadmin/
├── kubeconfig
├── alt-name-1
│ └── kubeconfig
├── 1.2.3.4
│ └── kubeconfig
└── microshift-rhel9
└── kubeconfig
where:
kubeconfig- Specifies the local hostname. The main IP address of the host is always the default.
alt-name-1- Specifies the subject alternative name for the API server certificate.
1.2.3.4- Specifies the DNS name.
microshift-rhel9- Specifies the MicroShift hostname.
8.2. Local access kubeconfig file 링크 복사링크가 클립보드에 복사되었습니다!
The local access kubeconfig file in Red Hat build of MicroShift is written to /var/lib/microshift/resources/kubeadmin/kubeconfig. This kubeconfig file provides access to the API server by using localhost. Use this file when you connect to the node locally.
Example contents of kubeconfig for local access
clusters:
- cluster:
certificate-authority-data: <base64_encoded_CA>
server: https://localhost:6443
The localhost kubeconfig file can only be used from a client connecting to the API server from the same host. The certificates in the file do not work for remote connections.
8.2.1. Accessing the MicroShift node locally 링크 복사링크가 클립보드에 복사되었습니다!
Use the following procedure to access the MicroShift node locally by using a kubeconfig file.
Prerequisites
-
You installed the OpenShift CLI (
oc).
Procedure
Optional: to create a
~/.kube/folder if your Red Hat Enterprise Linux (RHEL) machine does not have one, run the following command:$ mkdir -p ~/.kube/Copy the generated local access
kubeconfigfile to the~/.kube/directory by running the following command:$ sudo cat /var/lib/microshift/resources/kubeadmin/kubeconfig > ~/.kube/configUpdate the permissions on your
~/.kube/configfile by running the following command:$ chmod go-r ~/.kube/config
Verification
Verify that MicroShift is running by entering the following command:
$ oc get pods -AExample output
NAMESPACE NAME READY STATUS RESTARTS AGE default i-06166fbb376f14a8bus-west-2computeinternal-debug-qtwcr 1/1 Running 0 46m kube-system csi-snapshot-controller-5c6586d546-lprv4 1/1 Running 0 51m openshift-dns dns-default-45jl7 2/2 Running 0 50m openshift-dns node-resolver-7wmzf 1/1 Running 0 51m openshift-ingress router-default-78b86fbf9d-qvj9s 1/1 Running 0 51m openshift-ovn-kubernetes ovnkube-master-5rfhh 4/4 Running 0 51m openshift-ovn-kubernetes ovnkube-node-gcnt6 1/1 Running 0 51m openshift-service-ca service-ca-bf5b7c9f8-pn6rk 1/1 Running 0 51m openshift-storage topolvm-controller-549f7fbdd5-7vrmv 5/5 Running 0 51m openshift-storage topolvm-node-rht2m 3/3 Running 0 50mNoteThis example output shows a basic MicroShift installation. If you installed optional RPMs, the status of pods running those services is also expected in your output.
8.3. Remote access kubeconfig files 링크 복사링크가 클립보드에 복사되었습니다!
MicroShift generates a default kubeconfig file that enables external clients to connect securely to the API server. The configuration uses the node hostname and certificate validation based on Subject Alternative Name (SAN) entries.
When a MicroShift node connects to the API server from an external source, a certificate with all alternative names listed in the SAN field is used for validation. MicroShift generates a default kubeconfig for external access by using the hostname value. The defaults are set in the <node.hostnameOverride>, <node.nodeIP>, and api.<dns.baseDomain> parameter values of the default kubeconfig file.
The /var/lib/microshift/resources/kubeadmin/<hostname>/kubeconfig file uses the hostname of the machine, or node.hostnameOverride if that option is set, to reach the API server. The CA in the kubeconfig file can validate certificates when the API server is accessed externally.
Example contents of a default kubeconfig file for remote access
clusters:
- cluster:
certificate-authority-data: <base64 CA>
server: https://microshift-rhel9:6443
8.3.1. Remote access customization 링크 복사링크가 클립보드에 복사되었습니다!
Multiple remote access kubeconfig file values can be generated for accessing the node with different IP addresses or host names. An additional kubeconfig file generates for each entry in the apiServer.subjectAltNames parameter. You can copy remote access kubeconfig files from the host during times of IP connectivity and then use them to access the API server from other workstations.
8.4. Generating additional kubeconfig files for remote access 링크 복사링크가 클립보드에 복사되었습니다!
To support more host names or IP addresses for remote access than the default file provides, you can generate additional kubeconfig files in MicroShift. Add the entries to apiServer.subjectAltNames in config.yaml and restart the service to create the files.
You must restart MicroShift for configuration changes to be implemented.
Prerequisites
-
You have created a
config.yamlfile for MicroShift.
Procedure
Optional: You can show the contents of the
config.yaml. Run the following command:$ cat /etc/microshift/config.yamlOptional: You can show the contents of the remote-access
kubeconfigfile. Run the following command:$ cat /var/lib/microshift/resources/kubeadmin/<hostname>/kubeconfigImportantAdditional remote access
kubeconfigfiles must include one of the server names listed in the Red Hat build of MicroShiftconfig.yamlfile. Additionalkubeconfigfiles must also use the same CA for validation.To generate additional
kubeconfigfiles for additional DNS names SANs or external IP addresses, add the entries you need to theapiServer.subjectAltNamesfield. In the following example, the DNS name used isalt-name-1and the IP address is1.2.3.4.Example
config.yamlwith additional authentication valuesdns: baseDomain: example.com node: hostnameOverride: "microshift-rhel9" nodeIP: 10.0.0.1 apiServer: subjectAltNames: - alt-name-1 - 1.2.3.4where:
microshift-rhel9- Specifies the hostname of the node.
alt-name-1- Specifies the DNS name.
1.2.3.4- Specifies the IP address or range.
Restart MicroShift to apply configuration changes and auto-generate the
kubeconfigfiles you need by running the following command:$ sudo systemctl restart microshiftTo check the contents of additional remote-access
kubeconfigfiles, insert the name or IP address as listed in theconfig.yamlinto thecatcommand. For example,alt-name-1is used in the following example command:$ cat /var/lib/microshift/resources/kubeadmin/alt-name-1/kubeconfigChoose the
kubeconfigfile to use that contains the SAN or IP address you want to use to connect your node. In this example, thekubeconfigcontainingalt-name-1in theclusters.cluster.serverfield is the correct file.Example contents of an additional
kubeconfigfileclusters: - cluster: certificate-authority-data: <base64 CA> server: https://alt-name-1:6443The
/var/lib/microshift/resources/kubeadmin/alt-name-1/kubeconfigfile values are from theapiServer.subjectAltNamesconfiguration values.NoteAll parameters are included as common names (CN) and subject alternative names (SAN) in the external serving certificates for the API server.
8.4.1. Opening the firewall for remote access to the MicroShift node 링크 복사링크가 클립보드에 복사되었습니다!
You must open the firewall before a workstation user can access the MicroShift node remotely.
For this procedure, user@microshift is the user on the MicroShift host machine and is responsible for setting up that machine so that it can be accessed by a remote user on a separate workstation.
Prerequisites
-
You installed the OpenShift CLI (
oc). - Your account has cluster administration privileges.
Procedure
As
user@microshifton the MicroShift host, open the firewall port for the Kubernetes API server (6443/tcp) by running the following command:[user@microshift]$ sudo firewall-cmd --permanent --zone=public --add-port=6443/tcp && sudo firewall-cmd --reload
Verification
As
user@microshift, verify that MicroShift is running by entering the following command:$ oc get pods -AExample output
NAMESPACE NAME READY STATUS RESTARTS AGE default i-06166fbb376f14a8bus-west-2computeinternal-debug-qtwcr 1/1 Running 0 46m kube-system csi-snapshot-controller-5c6586d546-lprv4 1/1 Running 0 51m openshift-dns dns-default-45jl7 2/2 Running 0 50m openshift-dns node-resolver-7wmzf 1/1 Running 0 51m openshift-ingress router-default-78b86fbf9d-qvj9s 1/1 Running 0 51m openshift-ovn-kubernetes ovnkube-master-5rfhh 4/4 Running 0 51m openshift-ovn-kubernetes ovnkube-node-gcnt6 1/1 Running 0 51m openshift-service-ca service-ca-bf5b7c9f8-pn6rk 1/1 Running 0 51m openshift-storage topolvm-controller-549f7fbdd5-7vrmv 5/5 Running 0 51m openshift-storage topolvm-node-rht2m 3/3 Running 0 50mNoteThis example output shows a basic MicroShift installation. If you installed optional RPMs, the status of pods running those services is also expected in your output.
8.4.2. Accessing the MicroShift node remotely 링크 복사링크가 클립보드에 복사되었습니다!
Access the MicroShift service from a remote location by using a kubeconfig file.
The user@workstation login is used to access the host machine remotely. The <user> value in the procedure is the name of the user that user@workstation logs in with to the MicroShift host.
Prerequisites
-
You installed the OpenShift CLI (
oc). -
The
user@microshifthas opened the firewall from the local host. -
You generated additional
kubeconfigfiles.
Procedure
As
user@workstation, create a~/.kube/folder if your Red Hat Enterprise Linux (RHEL) machine does not have one by running the following command:[user@workstation]$ mkdir -p ~/.kube/As
user@workstation, set a variable for the hostname of your MicroShift host by running the following command:[user@workstation]$ MICROSHIFT_MACHINE=<microshift_hostname>Replace the value, <MicroShift_hostname>, with the either the name or the IP address of the host running .
As
user@workstation, copy the generatedkubeconfigfile that contains the hostname or IP address you want to connect to from the RHEL machine running MicroShift to your local machine by running the following command:[user@workstation]$ ssh <user>@$MICROSHIFT_MACHINE "sudo cat /var/lib/microshift/resources/kubeadmin/$MICROSHIFT_MACHINE/kubeconfig" > ~/.kube/config #Replace <user> with your SSH login credentials.
As
user@workstation, update the permissions on your~/.kube/configfile by running the following command:$ chmod go-r ~/.kube/config
Verification
As
user@workstation, verify that MicroShift is running by entering the following command:$ oc get pods -AExample output
NAMESPACE NAME READY STATUS RESTARTS AGE default i-06166fbb376f14a8bus-west-2computeinternal-debug-qtwcr 1/1 Running 0 46m kube-system csi-snapshot-controller-5c6586d546-lprv4 1/1 Running 0 51m openshift-dns dns-default-45jl7 2/2 Running 0 50m openshift-dns node-resolver-7wmzf 1/1 Running 0 51m openshift-ingress router-default-78b86fbf9d-qvj9s 1/1 Running 0 51m openshift-ovn-kubernetes ovnkube-master-5rfhh 4/4 Running 0 51m openshift-ovn-kubernetes ovnkube-node-gcnt6 1/1 Running 0 51m openshift-service-ca service-ca-bf5b7c9f8-pn6rk 1/1 Running 0 51m openshift-storage topolvm-controller-549f7fbdd5-7vrmv 5/5 Running 0 51m openshift-storage topolvm-node-rht2m 3/3 Running 0 50mNoteThis example output shows a basic MicroShift installation. If you installed optional RPMs, the status of pods running those services is also expected in your output.