Created
June 18, 2022 14:04
-
-
Save ppanyukov/7da7b5fc5923671ca96cb97d9076f763 to your computer and use it in GitHub Desktop.
Using Docker in Kubernetes
This file contains 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
--- | |
# This creates a deployment where each pod has two containers: | |
# - Docker Server: the actual docker engine. | |
# - Docker Client: simple Ubuntu instance with docker cli so we can | |
# test the docker things. In practice this would be some CI agent | |
# like Azure Devops agent or Jenkins or anything at all. | |
# | |
# After this deployment is created, wait for a bit for docker CLI to be installed | |
# in the client container. Then shell into it and use docker commands like docker build etc | |
# to test that things actually work. | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: docker-demo | |
labels: | |
app: docker-demo | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: docker-demo | |
template: | |
metadata: | |
labels: | |
app: docker-demo | |
spec: | |
tolerations: | |
# So we can run on spot instances in Azure AKS, add your own as required. | |
- effect: NoSchedule | |
key: kubernetes.azure.com/scalesetpriority | |
operator: Equal | |
value: spot | |
containers: | |
# Docker server | |
- name: server | |
image: docker:20.10.17-dind | |
env: | |
# Required to talk plain HTTP, until we figure out how to talk over HTTPS or SSH. | |
- name: DOCKER_TLS_CERTDIR | |
value: "" | |
securityContext: | |
privileged: true | |
# Docker client. Installs docker cli. All docker commands talk to docker server. | |
# | |
# Once this is running we can shell into this container and try out docker commands. | |
- name: client | |
image: ubuntu:20.04 | |
env: | |
- name: DOCKER_HOST | |
value: "tcp://localhost:2375" | |
command: ["/bin/bash"] | |
args: | |
- "-c" | |
- | | |
set -e | |
echo "Installing docker client" | |
( | |
set -x | |
# Install docker client form MSFT repository | |
apt-get update | |
apt-get install --no-install-recommends -y ca-certificates | |
apt-get install --no-install-recommends -y curl | |
# Install repository configuration | |
# Install Microsoft GPG public key | |
curl -sSL https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/microsoft-prod.list | |
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc | |
# Finally docker client | |
apt-get update | |
apt-get install -y moby-cli | |
) | |
# Finally a sleep loop | |
while true | |
do | |
echo -n 'sleeping: '; date; sleep 10; | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment