mkdir ~/ctrk3s && cd ~/ctrk3s
git clone https://gist.github.com/revant/2cfff3d63216f2d36557c4e098b810cb .devcontainer
code .
Reopen in VSCode Devcontainer to start playing around with k3s in devcontainer.
version: "3.7" | |
services: | |
kubectl: | |
build: . | |
command: ["tail", "-f", "/dev/null"] | |
environment: | |
- SHELL=/bin/zsh | |
volumes: | |
- ..:/workspace | |
- ${HOME}/.ssh:/home/castlecraft/.ssh | |
working_dir: /workspace | |
k3s: | |
image: registry.gitlab.com/gitlab-org/cluster-integration/test-utils/k3s-gitlab-ci/releases/v1.31.2-k3s1:latest | |
command: | |
- server | |
- --tls-san=k3s | |
- --disable=traefik | |
volumes: | |
- k3s:/var/lib/rancher/k3s | |
tmpfs: | |
- /run | |
- /var/run | |
privileged: true | |
ports: | |
- 80:80 | |
- 443:443 | |
volumes: | |
k3s: |
{ | |
"name": "K3s in devcontainer", | |
"remoteUser": "castlecraft", | |
"customizations": { | |
"settings": { | |
"debug.node.autoAttach": "disabled" | |
}, | |
"extensions": [ | |
"ms-python.python", | |
"visualstudioexptteam.vscodeintellicode" | |
] | |
}, | |
"dockerComposeFile": "./compose.yml", | |
"service": "kubectl", | |
"workspaceFolder": "/workspace", | |
"shutdownAction": "stopCompose" | |
} |
FROM debian:bookworm-slim | |
COPY entrypoint.sh /entrypoint.sh | |
RUN apt-get update \ | |
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ | |
locales \ | |
ca-certificates \ | |
curl \ | |
sudo \ | |
zsh \ | |
&& rm -rf /var/lib/apt/lists/* \ | |
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \ | |
&& dpkg-reconfigure --frontend=noninteractive locales | |
RUN groupadd -g 1000 castlecraft \ | |
&& useradd --no-log-init -r -m -u 1000 -g 1000 -G sudo castlecraft \ | |
&& echo "castlecraft ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers | |
ENV KUBECONFIG=/home/castlecraft/.kube/config | |
USER castlecraft | |
WORKDIR /home/castlecraft | |
# Install Tools | |
RUN sudo curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \ | |
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \ | |
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | sudo bash && \ | |
mkdir -p /home/castlecraft/.kube && \ | |
sudo chmod +x /entrypoint.sh | |
RUN sh -c "$(curl -L https://github.com/deluan/zsh-in-docker/releases/download/v1.2.1/zsh-in-docker.sh)" -- \ | |
-p git \ | |
-p kubectl \ | |
-p https://github.com/zsh-users/zsh-autosuggestions \ | |
-p https://github.com/zsh-users/zsh-completions | |
ENTRYPOINT [ "/entrypoint.sh" ] |
#!/bin/bash | |
kubectl get svc 1>/dev/null || curl -sSL k3s:8081>"${KUBECONFIG}" | |
exec "$@" |