I'm trying to follow instructions on this guide but under docker.
I set up a folder with:
.
├── Dockerfile
└── main.py
0 directories, 2 files
main.py
is:
#!/usr/bin/env python3
print("Docker is magic!")
Dockerfile is:
FROM python:latest
COPY main.py /
CMD [ "python", "./main.py" ]
FROM python:3.7-alpine
COPY ./ /usr/src/app/
WORKDIR /usr/src/app
RUN apk add curl openssl bash --no-cache
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" \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin/kubectl
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-node --type=LoadBalancer --port=38080
minikube start --driver=docker
kubectl get pods
When I run docker run python-test I see in terminal:
Docker is magic!
but I don't see the get pods output.
My goal here is to run a simple minikube
in the docker that just print the list of the pods. What is wrong here?
If you want to use kubernetes inside a docker container my suggestion is to use k3d .
k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker.k3d makes it very easy to create single- and multi-node k3s clusters in docker, e.g. for local development on Kubernetes.
You can Download , install and use it directly with Docker. For more information you can follow the official documentation from https://k3d.io/ .
To get the list of pods you dont' need to create a k8s cluster inside a docker container . what you need is a config file for any k8s cluster . ├── Dockerfile ├-- config └── main.py 0 directories, 3 files
after that :
FROM python:latest
COPY main.py /
CMD [ "python", "./main.py" ]
FROM python:3.7-alpine
COPY ./ /usr/src/app/
WORKDIR /usr/src/app
RUN apk add curl openssl bash --no-cache
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" \
&& chmod +x ./kubectl \
&& mv ./kubectl /usr/local/bin/kubectl
COPY config ~/.kube/config
# now if you execute k get pods you can get the list of pods
#Example;
RUN kubectl get pods
to get this file config you can follow this link Organizing Cluster Access Using kubeconfig Files
I hope that can help you to resolve your issue .