Deploying local Docker image (DockerFIle) as local Kubernetes pod - docker

I started Kubernetes master and minion on local machine using Vagrant. I can create a json file for my Kubernetes pod where I can start several public containers.
However, one Docker container is local one, ontop on java:8-jdk, configured with DockerFile.
How can I reference this local Docker container in the kubernetes json pod so Kubernetes can run it?
In other words, does Kubernetes support docker build ;)

After you build the docker image, you can "side-load" it into your locally available images by running docker load -i /path/to/image.tar. Once you've done this, Kubernetes will be able to load the image without reaching out to an external hub.

Related

Unable to connect internet on a docker container running on GKE pod

We have a GKE pod running with Jenkins image having docker installed in it. When I tried to build a image using Dockerfile on this Jenkins GKE pod, It is not working as background containers created while building image from Dockerfile are unable to access internet to fetch data.

Best way to export minikube cluster to a new machine

I have a fullstack application running in minikube cluster, i'm using docker as a minikube driver, and it's working perfectly, unfortunately i'm still new to kubernetes, how can i run this same cluster on a new machine, i'm loading local docker images of my app services to minikube.
I came up with this method:
Push all of my app images to docker hub
Export all my services and deployments as yaml files ( after modiying image pull source)
Install minikube on the new machine
Create a new cluster
Apply all declaration files
Exposing my frontend service
App can be accessed on localhost:someport
any suggestions of an easier way to achieve this?

Using local images without creating a local registry in kubernetes

I am fairly new to docker and kubernetes and going through kubernetes docs it says,
When using a single VM for Kubernetes, it’s useful to reuse Minikube’s built-in Docker daemon. Reusing the built-in daemon means you don’t have to build a Docker registry on your host machine and push the image into it. Instead, you can build inside the same Docker daemon as Minikube, which speeds up local experiments.
So, my understanding is there are two instances are running in my local machine, one in macOS and the other one in the VM.
Suppose I created a image using the docker instance on my macOS, and then I want to use it on Kubernetes then,
Question 1: Do I strictly need to create a local registry and then pull it from within Kubernetes cluster ?
It further says,
To work with the Docker daemon on your Mac/Linux host, use the docker-env command in your shell: eval $(minikube docker-env)
Running this creates a few environment variables in the current shell.
Question 2: Will this be able to pull images that I build from within the docker in my macOS without creating the local registry.
Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop.
So it will create a k8s setup on a VM running on your macOS.
eval $(minikube docker-env)
this command on you macOS will help you to switch context to docker, so that you can run docker commands from your macOS.
Question 1: Do I strictly need to create a local registry and then pull it from within Kubernetes cluster ?
No you don't need to explicitly create a local registry as everthing runs on a single VM in minikube.
Question 2: Will this be able to pull images that I build from within the docker in my macOS without creating the local registry?
By switching docker env context on your host machine you can able to pull the images you don't need create a registry for that. Remember your macOS is not the part of you k8s cluster. Your k8s cluster is running on the single VM created by minikube.

how to find directory of a kafka in pod in GCP?

I'm using Kubernetes on Google Cloud Platform; I installed the Kafka image in a pod, but when I try to make communication between producer and consumer with Kafkacat nothing is working.
I want to find the directory kafka in pod.
The containers running inside a pod are actually run by the docker daemon (assuming docker is the chosen container runtime for this Kubernetes deployment) of the host machine.
So in case of GCP the host machine will be the worker VM where the pod is scheduled by Kubernetes.
You can get to know which worker VM by looking at the node by running the command:
kubectl get pod pod name -o wide
Hence the image will be stored in the file system of the host machine. The exact path depends on the OS distribution of the host machine.
This is discussed here Where are Docker images stored on the host machine?

connecting to Kubernetes kops pod using docker deamon

I created Kubernetes cluster with kops (on AWS), and i want to access to one of my nodes as a root.According to this post, it's possible only with Docker command.
When i type docker image ls i'm getting nothing. When i was using minikube i solved this issue with minikube docker-env and from output i just copied last line into new CMD line #FOR /f "tokens=*" %i IN ('minikube docker-env') DO #%i
(I'm using Widnows 10) and using above procedure, after typing docker image ls or docker image ps i was able to see all minikube pods. Is there any way to do the same for pods created with kops ?
I'm able to do it connecting to Kubernetes node, install docker on it, and then i can connect to pod specifying -u root switch, but i wonder is it possible to do the same from host machine (Windows 10 in my case)
It's a bit unclear what you're trying to do. So I'm going to give some general info here based on this scenario : You've created a K8S cluster on AWS using Kops
I want to access one of my AWS node as root
This has nothing to do with kops nor it has with Docker. This is basic AWS management. You need to check on your AWS console management to get all the info to connect to your node.
I want to see all the docker image from my windows laptop
Again, this has nothing to do with kops. Kops is a Kubernetes distribution. In Kubernetes, the smallest units of computing that can be managed is the pod. You cannot manage directly docker containers or images with kubernetes.
So if you want to see your docker images, you'll need to somehow connect to your AWS node and then execute
docker image ls
In fact, that's what you're doing with your minikube example. You're just executing the docker command on the VM managed by minikube.
More info on what's a pod here
I want to see all the pods created with kops
Well, assuming that you've succesfully configured your system to access AWS with kops (more info on that here), then you'll just have to directly execute any kubectl command. For example, to list all the pods located in the kube-system namespace :
kubectl -n kube-system get po
Hope this helps !
That is not possible. A pod is an abstraction created and managed by kubernetes. The docker daemon has no idea to what is a pod. You can only see the containers using docker command. But then again, you wont be able to tell which container is associated to which pod.
Answered by #Marc ABOUCHACRA

Resources