├── dockerfile
├── kubeps1.sh
└── readme.md
/dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.10-alpine
2 |
3 | #Some Tools
4 | RUN apk add --no-cache curl bash-completion ncurses-terminfo-base ncurses-terminfo readline ncurses-libs bash nano ncurses docker git
5 |
6 | #Google Kubernetes control cmd
7 | RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
8 | RUN chmod +x ./kubectl
9 | RUN mv ./kubectl /usr/local/bin/kubectl
10 |
11 | #Expose for kubectl proxy
12 | EXPOSE 8001
13 |
14 | #K8 Helm
15 | RUN wget -q "https://get.helm.sh/helm-v3.14.4-linux-amd64.tar.gz" -O helm.tar.gz && \
16 | tar -xzf helm.tar.gz && \
17 | rm helm.tar.gz && \
18 | mv linux-amd64/helm /usr/local/bin/helm
19 |
20 |
21 | # Kubens \ Kubectx
22 | RUN curl -L https://github.com/ahmetb/kubectx/archive/v0.4.0.tar.gz | tar xz \
23 | && cd ./kubectx-0.4.0 \
24 | && mv kubectx kubens utils.bash /usr/local/bin/ \
25 | && chmod +x /usr/local/bin/kubectx \
26 | && chmod +x /usr/local/bin/kubens \
27 | && cat completion/kubectx.bash >> ~/.bashrc \
28 | && cat completion/kubens.bash >> ~/.bashrc \
29 | && cd ../ \
30 | && rm -fr ./kubectx-0.4.0
31 |
32 | #Cloudfare SSL Tools
33 | RUN curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssl_1.5.0_linux_amd64 -o /usr/local/bin/cfssl && \
34 | curl -L https://github.com/cloudflare/cfssl/releases/download/v1.5.0/cfssljson_1.5.0_linux_amd64 -o /usr/local/bin/cfssljson && \
35 | chmod +x /usr/local/bin/cfssl && \
36 | chmod +x /usr/local/bin/cfssljson
37 |
38 | #Syntax highlighting
39 | RUN git clone https://github.com/scopatz/nanorc.git ~/.nano && \
40 | echo "include ~/.nano/*.nanorc" >> ~/.nanorc && \
41 | rm ~/.nano/hcl.nanorc && rm /root/.nano/prolog.nanorc #These cause errors-remove them
42 |
43 | #Azure CLI
44 | WORKDIR azure-cli
45 |
46 | ENV AZ_CLI_VERSION=2.72.0
47 | #Download the version we want!
48 |
49 | RUN wget -q "https://github.com/Azure/azure-cli/archive/azure-cli-${AZ_CLI_VERSION}.tar.gz" -O azcli.tar.gz && \
50 | tar -xzf azcli.tar.gz && ls -l
51 |
52 | RUN cp azure-cli-azure-cli-${AZ_CLI_VERSION}/** /azure-cli/ -r && \
53 | rm azcli.tar.gz
54 |
55 | RUN apk add --no-cache bash openssh ca-certificates jq curl openssl perl git zip \
56 | && apk add --no-cache --virtual .build-deps gcc make openssl-dev libffi-dev musl-dev linux-headers \
57 | && apk add --no-cache libintl icu-libs libc6-compat \
58 | && apk add --no-cache bash-completion \
59 | && update-ca-certificates
60 |
61 | ARG JP_VERSION="0.1.3"
62 |
63 | RUN curl -L https://github.com/jmespath/jp/releases/download/${JP_VERSION}/jp-linux-amd64 -o /usr/local/bin/jp \
64 | && chmod +x /usr/local/bin/jp
65 |
66 | # 1. Build packages and store in tmp dir
67 | # 2. Install the cli and the other command modules that weren't included
68 | RUN ./scripts/install_full.sh \
69 | && cat /azure-cli/az.completion > ~/.bashrc \
70 | && runDeps="$( \
71 | scanelf --needed --nobanner --recursive /usr/local \
72 | | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
73 | | sort -u \
74 | | xargs -r apk info --installed \
75 | | sort -u \
76 | )" \
77 | && apk add --virtual .rundeps $runDeps
78 |
79 | # Remove CLI source code from the final image and normalize line endings.
80 | RUN rm -rf ./azure-cli && \
81 | dos2unix /root/.bashrc /usr/local/bin/az
82 | ENV AZ_INSTALLER=DOCKER
83 |
84 | # Tab completion
85 | #RUN cat /azure-cli/az.completion >> ~/.bashrc
86 | #RUN echo -e "\n" >> ~/.bashrc
87 | RUN echo -e "source <(kubectl completion bash)" >> ~/.bashrc
88 | RUN echo "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc
89 |
90 | #Azure kubelogin
91 | RUN curl -L https://github.com/Azure/kubelogin/releases/download/v0.0.13/kubelogin-linux-amd64.zip -o /tmp/kubelogin.zip && \
92 | unzip /tmp/kubelogin.zip -d /tmp/ && \
93 | mv /tmp/bin/linux_amd64/kubelogin /usr/local/bin/kubelogin && \
94 | chmod +X /usr/local/bin/kubelogin
95 |
96 | # Kube-ps1 - order so we can change themes without pulling kubeps1 every build
97 | RUN curl -L https://github.com/jonmosco/kube-ps1/archive/0.6.0.tar.gz | tar xz && \
98 | cd ./kube-ps1-0.6.0 && \
99 | mkdir -p ~/kube-ps1 && \
100 | mv kube-ps1.sh ~/kube-ps1/ && \
101 | rm -fr ./kube-ps1-0.6.0
102 | COPY kubeps1.sh /root/kube-ps1/
103 | RUN chmod +x ~/kube-ps1/*.sh && \
104 | echo "source ~/kube-ps1/kube-ps1.sh" >> ~/.bashrc && \
105 | echo "source ~/kube-ps1/kubeps1.sh" >> ~/.bashrc && \
106 | echo "PROMPT_COMMAND=\"my_kube_ps1\"" >> ~/.bashrc
107 |
108 | # Aliases
109 | RUN echo "alias k=kubectl" >> ~/.bashrc
110 | RUN echo "alias kubedev=\"export KUBECONFIG=~/.kube/dev-config\"" >> ~/.bashrc
111 | RUN echo "alias kubeprod=\"export KUBECONFIG=~/.kube/production-config\"" >> ~/.bashrc
112 |
113 | ENV KUBE_EDITOR nano
114 |
115 | WORKDIR /
116 |
117 | ENTRYPOINT ["bash"]
118 |
--------------------------------------------------------------------------------
/kubeps1.sh:
--------------------------------------------------------------------------------
1 |
2 | parse_git_branch() {
3 | git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
4 | }
5 |
6 | my_kube_ps1() {
7 | source <(kubectl completion bash)
8 | KUBE_PS1_SYMBOL_COLOR=blue
9 | KUBE_PS1_CTX_COLOR="${KUBE_PS1_CTX_COLOR-48;5;4m}"
10 | KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-48;5;4m}"
11 | KUBE_PS1_BG_COLOR=''
12 | KUBE_PS1_SYMBOL="⎈"
13 | KUBE_PS1_USER_COLOR="${KUBE_PS1_USER_COLOR-48;5;4m}"
14 | KUBE_PS1_FOLDER_COLOR="${KUBE_PS1_FOLDER_COLOR-48;5;242m}"
15 | KUBE_PS1_GIT_BRANCH_COLOR="${KUBE_PS1_GIT_BRANCH_COLOR-0;33;49m}"
16 | source ~/kube-ps1/kube-ps1.sh
17 | PS1='\[\e[${KUBE_PS1_USER_COLOR}\][\u@\h]\[\e[0;0m\]\[\e[${KUBE_PS1_FOLDER_COLOR}\][\W]\[\e[0;0m\] \[\e[${KUBE_PS1_GIT_BRANCH_COLOR}\]$(parse_git_branch)\[\e[0;0m\] $(kube_ps1)\n'
18 | PS1+=' |--> '
19 | export PS1
20 | }
21 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Kubernetes Toolset
2 |
3 | This docker image is made up of common used tools I use for working with Kubernetes on Azure.
4 | You do not need to install tools seperately and only need docker to run this container
5 |
6 | This docker image includes:
7 |
8 | * Kubectl
9 | * Azure CLI
10 | * Helm
11 | * kubectx
12 | * kubens
13 | * Heptio ark
14 | * Cloudfare SSL tools (for boostrapping clusters)
15 |
16 | ## Setup
17 |
18 | You will want to persist your files on your pc somewhere.
19 | On Windows, I do this in `C:\Users\\kube-tools\`
20 | On Linux, I use my home dir.
21 |
22 | Make sure the above folder exists!
23 |
24 | I recommend using Powershell for Windows, but for bash on windows:
25 | Ensure `$PWD` works, set this in your bash terminal: ` export MSYS_NO_PATHCONV=1`
26 |
27 | ### How to Install
28 |
29 | You can install kube-tools via your bash profile and then simply run `kubetools` to start it up.
30 |
31 | #### Windows
32 |
33 | Run it: (Replace the user directory with yours!)
34 | ```
35 | docker run -it -v ${PWD}:/work `
36 | -v $home/kube-tools/.azure:/root/.azure `
37 | -v $home/kube-tools/.kube:/root/.kube `
38 | --rm --workdir /work aimvector/kube-tools:latest
39 | ```
40 |
41 | #### Linux
42 |
43 | Setup an alias for `kubetools`
44 |
45 | ```
46 | echo "alias kubetools='docker run -it --rm -v ~/.azure:/root/.azure -v \$PWD:/kubetools -v ~/.kube:/root/.kube --rm --network=host --workdir /kubetools aimvector/kube-tools'" >> ~/.bashrc
47 |
48 | ```
49 | Or just run the image:
50 |
51 | ```
52 | docker run -it --rm -v ~/.azure:/root/.azure -v $PWD:/var/lib/src -v ~/.kube:/root/.kube --rm --network=host --workdir /var/lib/src aimvector/kube-tools
53 | ```
54 |
55 | Once in, you can access the tools:
56 | ```
57 | kubectl --help
58 | helm --help
59 | az --help
60 | kubectx
61 | kubens
62 | ark --help
63 |
64 | ```
65 |
66 | Alternatively, grab running the following command and get `kubetools` add to your `/usr/local/bin`
67 |
68 | ```bash
69 | wget -qO https://raw.githubusercontent.com/marcel-dempers/kube-tools/master/kubetools.sh ~/kubetools
70 | chdmox +x ~/kubetools
71 | sudo mv ~/kubetools /usr/local/bin/kubetools
72 | ```
73 |
74 | ## Build from source
75 |
76 | If you wish to customise it, you can build it from source:
77 |
78 | ```
79 | docker build . -t kube-tools
80 | ```
81 |
--------------------------------------------------------------------------------