I want to apt-get install sysstat command in my yaml file

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: 1.18
Cloud being used: (put bare-metal if not on a public cloud) AWS EKS
Host OS: debian linux

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

When I deploy pods,I want to my pod to install sysstat automatically

this is my two yaml flies below but it doesn’t work CrashLoopBackoff when I put the command: ["/bin/sh", “-c”]、args: [“apt-get install sysstat”]」 below 「image:」

cat deploy/db/statefulset.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: 
    sbdemo-postgres-sfs
spec:
  serviceName: sbdemo-postgres-service
  replicas: 1
  selector:
    matchLabels:
      app: sbdemo-postgres-sfs
  template:
    metadata:
      labels:
        app: sbdemo-postgres-sfs
    spec:
      containers:
       - name: postgres
         image: dayan888/springdemo:postgres9.6
         ports:
          - containerPort: 5432
         **command: ["/bin/bash", "-c"]**
         **args: ["apt-get install sysstat"]**
         volumeMounts:
         - name: pvc-db-volume
           mountPath: /var/lib/postgresql
  volumeClaimTemplates:
  - metadata:
      name: pvc-db-volume
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1G

cat deploy/web/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sbdemo-nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sbdemo-nginx
  template:
    metadata:
      labels:
        app: sbdemo-nginx
    spec:
      containers:
      - name: nginx
        image: gobawoo21/springdemo:nginx
         **command: ["/bin/bash", "-c"]**
         **args: ["apt-get install sysstat"]**
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nginx-conf
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
        - name: server-conf
          mountPath: /etc/nginx/conf.d/server.conf
          subPath: server.conf
      volumes:
      - name: nginx-conf
        configMap: 
          name: nginx-conf
          items:
            - key: nginx.conf
              path: nginx.conf
      - name: server-conf
        configMap: 
          name: server-conf
          items:
            - key: server.conf
              path: server.conf

Does anyone know about how to set the repository automatically when deploy pods?

Regards

when you used this command and args in your yaml file. Basically it override your dockerimage default CMD path. That’s why you are having Crashloopback off error. If you want this repo in your Pod container then modify docker image via Dockerfile and then try it.

Thank you for your reply
You mean modify Dockerfile add CMD path like below if I want to use command and args?
here is my original Dockerfile
How to I modify my Dockerfile when I want to that commands?
I’m sorry for my pool understanding my English and Dockerfile

FROM nginx:latest

COPY deploy/web/nginx.conf /etc/nginx/nginx.conf
COPY deploy/web/server.conf /etc/nginx/conf.d/server.conf
COPY src/main/resources/static/css /usr/share/nginx/html/css
COPY src/main/resources/static/js /usr/share/nginx/html/js
COPY src/main/resources/static/img /usr/share/nginx/html/img

Best Regards

I think nginx not support apt-get install package. When i worked with this only can host web pages only

If you have no issue of image or it’s size then pick ubuntu image. other option — Docker provides multi-stagging option as well.
https://docs.docker.com/develop/develop-images/multistage-build/

Thank you
but when I deploy nginx pod and use kubectl exec it – /bin/bash into the pod
It’s a debian linux
and use command apt-get update or install works well

Because you are doing this after creation of Pod. In the backend for a general idea parent process of debian linux is on and when you enter by manually kubectl exec. You are doing or hitting child process of container.
When Pod creation time container using Parent process (CMD or ENTRYPOINT) what ever it is. After container created you are doing by kubectl exec --> Child process.
This scenario is same for Docker containers.

I really really appreciate your comment.
I understand your comments
Thankyou very much!