MicroK8s Access Cluster Remotely
If you have the kubectl command line command installed on your local workstation you can skip the step of establishing an SSH session to a node in your cluster to manage it. Instead you can generate a kubectl config file which will be everything you need to authenticate to your cluster via your local kubectl command on your local workstation. Then from your workstation managing your cluster will look like this kubectl get pods
as if you were ssh'ed into your cluster. Microk8s provides a very easy way to generate the file you need.
Generate Config File
To generate the kubectl configuration file, on any node of your cluster enter the following command.
$ microk8s config
You will get output similar to below
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: axtvgladwablpeuneapwwmiyaykjulunmukmszklvhznbwtjxbgnycihobdkfhchzidtklcaofabakwsnjcoagwjeggjpciuckabvfzysiquaqcsgxuzhileodnolmhnzcfsnpzoqftfuocwyznauxntrofxprtjowyyyidhojvrapcqffjarzwrfmimkpcvmljnkvfiodrfqkuzpepvgmbtotwcyoypcfdnzkepkpxtnrlkqwbotgkkegyuwxroxgoshmlnhqlbnronxfvoljfafqhnbvuxkaibixmeuxhmtduvgytpzcozfyonwnefhcxormsbytzjhicbxhkblchwpkfqngiyibtraikoyrcforgmwvghiaybpwqryxzgdiwfracrujicxexxbbnauhtltogawcvuibeuhhubuljbaskuffpiyhepyyagdihfrzurzpzfjomhtqvslcmbshfhnekdmyjcswlldgdrvpotqvgkirugeldvgaeqanzencdivgdfzsdtszflhfezqkfkmyarbukqaojhosncuxrngaxsjnxvzjlnitwvlqnwetehfmcxxbvwrjbdqauzvcmgtqjrxiafbaqrbvblpqaeouwsiivjtbmlcphhhujuwncdktrcvdrmkvzflzpiknugsbvfmwryjfnruwskikezqjbydjcfjrcwkowshhbibvzodvuvqaevcctlcwciixiphlfokmrxwdfvmvjvsoulzmgnkpxrykmhfusjdfggsshdtifgsijlvyyfyoldmfpmmzktyygtuaggxxswzjsfwasgdeabzvzhkiwhtozkobaecpmuycrsjcmpzmwrvlgoakmpnbponsiwyniwyaqumktekhghgphwpjqtybbjcvileuqdigxpuzpzbvopputahgbmrgmryuxjqzkexzfrebkacbxqhsuiooyzsgcvjbcfzqhmfevernmbwhartqunvjedxcxlfqowltazcvcaddrroktwzjireiqysegwyvfidcjiudqhrgaferbhaczcstzgtqifbymuqzgcwuatddemfsyyaunnqvubfomytnlmuqcglhvfwnulyonmtorjiuihkuijluzmixuappyiiclvqvfmvdjrjvrgdnjbyybsbhgqnrgwwitqvnnhsomivzjjwtvgwwuibpzwbynspiliutptkvezkepogsuvcbvcacqeousdrsawzcqiprycgpfwfbcwdjmfdjgmfcpsjyxahjwbmmsfwwkbvsjtufqaoopznnwfgazqyschgzhnhcdiutididawtpprxylmcskrubvswfvxhbhmqgdyvglcxgsezpylbymzydtaknsdpbywfuhthmswiyymnwhlkofdgfyxbfewilfuruqvqiqibsatjywhncwqdlvmqdpqojdmcrpxalutzfyhyxkramrlmbsriqynhgmxkgicprhzpkgqeufhoyrwkadibonalb==
server: https://10.204.255.10:16443
name: microk8s-cluster
contexts:
- context:
cluster: microk8s-cluster
user: admin
name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
user:
token: bgoshuzbjkvamsxirhmtvouqtpttfzignqeeyrmmbzudmoytzlswohufuesu
That output is the contents of your configuration file that you need, copy and paste that to the file below. Note the path below is a relative path in the root of your users home folder.
.kube/config
Once you paste in the contents of that file and save it. Entering the kubectl command on your workstation will execute it on your cluster. It is worth noting that it will communicate with whatever node in the cluster you ran it on, if that node is down for whatever reason you can SSH to any other node and do the same steps to use that node instead.