I want to print "Hello World" in k8s, but I am confused how to do it.
I am new to Kubernetes.
How do I display "Hello World" by creating an image/container when accessed via a web server on a port.
Do I need to mandatorily install npm, or others in my dockerfile ? Or is there any way to simply use bash commands to echo "hello world" and display that as output in a Web server.
Please guide.
Kubernetes is an orchestrator, it is not a language such as JavaScript, you can create a javascript app, and then create a docker image containing the said app which you can then run in a kubernetes cluster.
I must say though, that your question makes me wonder if you have any experience in how containers or orchestrators work, which makes me think I should recommend you to read up a bit more and play around a bit more with it before trying to run it on a live environment.
If you don't want to listen to the above, you will basically need the following:
There are other ways to do it, but k8s is not an "easy thing" to work with, it requires quite a bit of research and testing to allow you to know what you are doing before it is useful.
Start with learning to use Docker. Containers is mostly "a way" to run processes in an isolated environment, so to do anything in a container, you need to do that with a process, e.g. bash or a custom application.
You can run both commands and services in a Docker container.
When deploying apps to Kubernetes, it is services, e.g. a web server listening on a port. But you can also run commands on Kubernetes by using Jobs
Here is a "hello world" Job using bash:
apiVersion: batch/v1
kind: Job
metadata:
name: hello-world
spec:
template:
metadata:
name: hello-world
spec:
containers:
- name: hello-world
image: centos:7
command:
- "bin/bash"
- "-c"
- "echo hello world"
restartPolicy: Never