Skip to main content

Kubernetes Basics

This page is most useful after setting up your workstation with the proper credentials and client applications.

Copying files

Kubernetes nodes have access to your Sol /home and /data mounts. Sometimes, however, you might want to copy files to and from your workstation.

You will not use Globus or SFTP clients, but instead, treat kubernetes' filesystem as being local to your own. See for example below for copying to and from your host:

$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-worldo-7b75749899-kdv86 1/1 Running 0 149m
$ kubectl cp secrets hello-worldo-7b75749899-kdv86:/tmp/localfile.txt
$ kubectl -it exec hello-worldo-7b75749899-kdv86 -- bash
# cat /tmp/localfile.txt
sec ret da ta

Port Forwarding

Basic testing and enabling of port forwarding is done with a blocking process; that means that only during the continued execution of the process will forwarding work.

In the hello-world template, nginx is running by default, and it indicates an outward facing port 80 in the kubernetes config. However, this is not enough to connect as we can attempt from our workstation:

rcsparky@workstation$ curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server

We know that the service is running, though, by entering the kube and attempting the same there:

rcsparky@workstation$ kubectl exec -it hello-worldo-7b75749899-kdv86 -- /bin/sh       
# curl http://localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...

We can first test the service availability, then, using the emphemeral (temporary, while-running the command) port forwarding functionality. In one terminal on your workstation:

rcsparky@workstation$ kubectl port-forward pod/hello-worldo-7b75749899-kdv86 8080:80  
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80

Open a second terminal on your workstation:

rcsparky@workstation$ curl http://localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...

Great! You now have a local port :8080 which will effortlessly forward to the kube's interior port listener at 80.