I want to apt-get install sysstat command in kubernetes yaml file
The best practice is to install packages at image build stage. You can simply add this step to your Dockerfile.
FROM postgres:9.6RUN apt-get update &&\ apt-get install sysstat -y &&\ rm -rf /var/lib/apt/lists/*COPY deploy/db/init_ddl.sh /docker-entrypoint-initdb.d/RUN chmod +x /docker-entrypoint-initdb.d/init_ddl.sh
Kube Manifest
spec: containers: - name: postgres image: harik8/sof:62298191 imagePullPolicy: Always ports: - containerPort: 5432 env: - name: POSTGRES_PASSWORD value: password volumeMounts: - name: pvc-db-volume mountPath: /var/lib/postgresql
It should run (Please ignore POSTGRES_PASSWORD
env variable)
$ kubectl get poNAME READY STATUS RESTARTS AGEsbdemo-postgres-sfs-0 1/1 Running 0 8m46s
Validation
$ kubectl exec -it sbdemo-postgres-sfs-0 bashroot@sbdemo-postgres-sfs-0:/# iostatLinux 4.19.107 (sbdemo-postgres-sfs-0) 06/10/2020 _x86_64_ (4 CPU)avg-cpu: %user %nice %system %iowait %steal %idle 10.38 0.01 6.28 0.24 0.00 83.09Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtnvda 115.53 1144.72 1320.48 1837135 2119208scd0 0.02 0.65 0.00 1048 0
If this is possible, something is wrong. Your container should not be running as root and so even if you fixed this approach, it shouldn’t work. What you need to do is put this in your container build instead (I.e. in the Dockerfile).