Created
February 11, 2024 17:07
-
-
Save jpetazzo/63ad363937ce5b7d48ed4af8e06fe38b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
data: | |
authorized_keys: | | |
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID9Zt/CR+kt1omLPJmMLCJu1w3aIpg7IO0Vv7up+MVFI jp@hex | |
kind: ConfigMap | |
metadata: | |
name: shpod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: shpod | |
labels: | |
app: shpod | |
spec: | |
volumes: | |
- name: home | |
persistentVolumeClaim: | |
claimName: shpod | |
- name: pubkey | |
configMap: | |
name: shpod | |
containers: | |
- name: sshd | |
image: alpine | |
volumeMounts: | |
- name: home | |
mountPath: /home | |
- name: pubkey | |
mountPath: /home/user/.ssh | |
command: | |
- sh | |
- -c | |
- | | |
set -e | |
apk add openssh | |
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" | |
echo "StrictModes no" >> /etc/ssh/sshd_config | |
echo "group:x:1000:" >> /etc/group | |
echo "user:x:1000:1000::/home/user:/bin/sh" >> /etc/passwd | |
mkdir -p /home/user | |
chown user /home/user | |
exec /usr/sbin/sshd -D -e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kind: PersistentVolumeClaim | |
apiVersion: v1 | |
metadata: | |
name: shpod | |
spec: | |
accessModes: | |
- ReadWriteOnce | |
resources: | |
requests: | |
storage: 1G |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: shpod | |
spec: | |
ports: | |
- name: ssh | |
port: 22 | |
protocol: TCP | |
targetPort: 22 | |
selector: | |
app: shpod | |
type: ClusterIP |
Fixed the connectivity issue with
sudo kubectl port-forward --address 0.0.0.0 service/shpod 2222:22
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to use this example in the following way (using my own ssh credentials):
curl -sfL https://get.k3s.io | sh -
sudo kubectl apply -f pvc.yaml sudo kubectl apply -f configmap.yaml sudo kubectl apply -f service.yaml sudo kubectl apply -f pod.yaml sudo kubectl get pod shpod sudo kubectl describe configmaps shpod sudo kubectl exec -it shpod -- /bin/sh
I get a prompt and can see that the mounting points are available
Setting up port forwarding
Now I try to connect from another machine in the network, but the internal network does not seem to be exposed.
I guess I have to configure the network in more detail. Any hints how to do this?