Specific Docker Command in Kubernetes - kubernetes

I am trying to start a Bro container in a Pod. In docker I would normally run something like this:
docker run -d --net=host --name bro
Is there something in the container spec that would replicate that functionality?

You can use the hostNetwork option of the API to run a pod on the host's network.

Related

How to create a pod and attach with a terminal later on

I want to run a multi-container pod, and interactuate with it via a terminal.
With kubectl run -ti I can run a monocontainer pod and attach easily to it.
I think I have to kubectl apply to create a complex pod, and later attach to it.
I've tried this and it doesn't work:
 kubectl run alpine --image alpine pod/alpine created
 kubectl attach -i alpine If you don't see a command prompt, try pressing enter.
error: unable to upgrade connection: container alpine not found in pod alpine
I'm using latest k3s v1.25.4+k3s1 under a Linux host (Ubuntu 22.04).
This does work:
 kubectl run alpine --image alpine --command sleep -- 999d
pod/alpine created
 kubectl exec -ti alpine -- ash
/ #
I need an auxiliary sleep.
You need attach interactively first:
kubectl run -it alpine --image alpine
Then detach by using CTRL-P, then CTRL-Q
To reattach, you then use:
kubectl attach alpine -c alpine -i -t
Note that if you close the shell at any point, you terminate the pod, and it will restart

How to ssh into docker-desktop kubernetes node?

Able to ssh to minikube, but not in docker-desktop node in Kubernetes ?
From a minikube instance, the idea is not to ssh to docker desktop, but to use docker directly through:
eval $(minikube docker-env)
See "Goodbye Docker Desktop, Hello Minikube!" from Abhinav Sonkar as an example.

Container in dind access another container in the same Kubernetes pod

In a Kubernetes pod, I have:
busybox container running in a dind container
fluentd container
I understand if dind wants to access fluentd, it needs to simply connect to localhost:9880. But what if busybox wants to access fluentd as the depicted diagram below. Which address should I use?
These tips may help you:
1. First approach
From inside the docker:latest container, where you were trying to access it originally, it will be available on whatever hostname is set for the docker:dind container. In this case, you used --name dind, therefore curl dind:busybox_port would give you the standard.
And then you could from inside the docker:dind container (busybox) connect to fluentd, it will be available on localhost:9880.
2. Second approach
Another approach is to EXPOSE [/<protocol>...] and in this case we assume that busyboox and fluentd are in different networks
You can also specify this within a docker run command, such as:
$ docker run --expose=1234 busybox
But EXPOSE will not allow communication via the defined ports to containers outside of the same network or to the host machine. To allow this to happen you need to publish the ports.
Publish ports and map them to the host
To publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.
$ docker run -p 80:80/tcp -p 80:80/udp busybox
And then connect from busybox to fluentd using localhost:9880
You can find more information here: docker-in-docker.
I hope it helps.

Accessing to service by name

I am a beginner in swarm and I have some troubles with accessing to service from host by name of service.
My steps:
1) Creating 1 manager and 2 workers
$ docker-machine create --driver virtualbox manager1
$ docker-machine create --driver virtualbox worker1
$ docker-machine create --driver virtualbox worker2
2) Initialization manager:
$ docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.100"
3) Initialization workers:
$ docker swarm join --token SWMTKN-1-2xrmha8wyxo471h85sttujbt28f95rm32d40ql3lr3kf3mf27q-4kjyqz4a5lz5ks390k35oc969 192.168.99.100:2377
4) Creating env:
$ docker-machine env manager1
$ eval $(docker-machine env manager1)
5) Creating overlay:
$ docker network create --driver overlay --subnet 10.10.10.0/24 my-overlay-network
6) Creating service:
$ docker service create -p 5000:5000 --replicas 3 --network my-overlay-network --name qwe vaomaohao/app_qwe
After this steps service was successfully deployed, but I can access to it only by IP address, not by service name.
Can you explain me please, why?
Thank you in advance!
a single solution but you need implemented it. You can use traefik or docker flow proxy, and file file hosts in windows or linux.
I recommend you traefik, have easy use. DFP Now project is not a good time.
Hosts File example:
Linux: /etc/hosts
Windows: c:\Windows\System32\Drivers\etc\hosts
172.16.1.186 yourdomain.swarm

Kubernetes Connectivity

I have a POD running which had a Java Application running. This Java Application talks to a MySql which is on-prem. The MySql accepts connections from 192.* ip's
I have the pod running on EKS worker nodes with Ip - 192.. I am able to telnet Mysql from the worker nodes. When the pod starts, the Java application tries to connect to the Mysql with the POD Ip (which is some random 172. ip) and fails with MySQL connection error.
How can I solve this?
Try to execute a shell inside the pod and connect to the MySQL server from there.
kubectl exec -it -n <namespace-name> <pod-name> -c <container-name> -- COMMAND [args...]
E.g.:
kubectl exec -it -n default mypod -c container1 -- bash
Then check the MySQL connectivity:
#/> mysql --host mysql.dns.name.or.ip --port 3306 --user root --password --verbose
Or start another pod with usual tools and check MySQL port connectivity:
$ kubectl run busybox --rm -it --image busybox --restart=Never
#/> ping mysql.dns.name.or.ip
#/> telnet mysql.dns.name.or.ip 3306
You should see some connection-related information that helps you to resolve your issue.
I can guess you just need to add a route to your cluster pods network on your MySQL host or its default network router.