I want to create multiple containers and then create different pods and put containers in the pods

10/4/2019

I am trying to create kubernetes cluster in Google shell .

gcloud container clusters create hello-server 
gcloud container clusters get-credentials hello-server

kubectl create deployment hello-server \
--image=gcr.io/google-samples/hello-app:1.0

kubectl expose deployment hello-server \
--type LoadBalancer \
--port 80 \
--target-port 8080

kubectl get  nodes

shows 3 nodes

NAME                                          STATUS   ROLES    AGE   VERSION
gke-hello-server-default-pool-03b44665-5grf   Ready    <none>   48m   v1.13.7-gke.24
gke-hello-server-default-pool-03b44665-65j5   Ready    <none>   48m   v1.13.7-gke.24
gke-hello-server-default-pool-03b44665-ng8w   Ready    <none>   48m   v1.13.7-gke.24


$kubectl get pods

NAME                            READY   STATUS    RESTARTS   AGE
hello-server-64db4d4dc7-llr5t   1/1     Running   0          29m

shows one pod

Now, i want to create multiple pods and put some containers in those pods and also do some kind of interactions in those pods.

-- wiTTyMinds Technology
cloud
docker
kubernetes

2 Answers

10/4/2019

You've create one Pod (hello-server-64db4d4dc7-llr5t) as a result of creating the Deployment (hello-server). kubectl create deployment defaults to a single replica (Pod).

You may increase the number of replicas (Pods) using:

kubectl scale deployment/hello-server --replicas=3

NB Beware of incurring greater charges by increasing the number of replicas.

The Deployment you created creates Pods that contain a single container using the gcr.io/google-samples/hello-app image.

You are better placed thinking at the Deployment and Service rather than Pod level when using Kubernetes. Kubernetes introduces unique concepts and it is worth grokking these early on.

I recommend you read Kubernetes backgrounders and check out the playground. I'm biased because I know Dave but, while this book is old, Dave does a very good job explaining Kubernetes from first principles:

https://www.oreilly.com/library/view/kubernetes/9781492048718/

https://www.katacoda.com/courses/kubernetes/playground

-- DazWilkin
Source: StackOverflow

10/4/2019

Please use Deployment instead of Pod

Note: Pods aren’t intended to be treated as durable entities. They won’t survive scheduling failures, node failures, or other evictions, such as due to lack of resources, or in the case of node maintenance.

In general, users shouldn’t need to create Pods directly. They should almost always use controllers even for singletons, for example, Deployments. Controllers provide self-healing with a cluster scope, as well as replication and rollout management. Controllers like StatefulSet can also provide support to stateful Pods.

Inside your pod exist already container. You can an verify this by running kubectl get pod your_pod_name, or kubectl describe pod your_pod_name

To get more information how to build your own image please refer to Best practices for writing Dockerfile. As the second step please refer to Kubernetes Documentation to get more information how to interact with your applications inside your cluster and how to create services and expose them inside or outside the cluster.

Here you can find example how to use this image with deployment.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloweb
  labels:
    app: hello
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello
      tier: web
  template:
    metadata:
      labels:
        app: hello
        tier: web
    spec:
      containers:
      - name: hello-app
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080
-- Hanx
Source: StackOverflow