Skip to content

Openshift Frequent commands

Chakradhar Rao Jonagam edited this page Nov 5, 2016 · 7 revisions

To clear all projects for all users with specific username pattern

for i in {10..20} ; 
do 
oc login --insecure-skip-tls-verify=true https://openshift.workshop.ck.osecloud.com:8443 -u user$i -p supersecret
sleep 1
oc delete all --all
done;

Create oc web shell for users

for i in {10..20} ; 
do 
oc new-app debianmaster/ose-client:v4 --name=user$i
oc expose svc/user$i
sleep 1
done;

If you see privileges related errors

oadm policy add-scc-to-group anyuid system:authenticated oc edit scc privileged oc edit scc restricted

create persistant volumes

for i in {000001..000020}; do
oc create -f - <<EOF
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
 name: "pv${i}"
spec:
 capacity:
   storage: "1Gi"
 accessModes:
   - "ReadWriteMany"
 nfs:
   path: "/osoDev/pv${i}"
   server: “<REDUCTED>"
 persistentVolumeReclaimPolicy: "Recycle"
EOF
done

file permission on configmaps / secrets volumes

in openshift s2i based deployments, configmaps/secrets volumes are created with root:root file permissions and hence not accesible by non-root application user, to fix this use fsGroup params

following example deployment config creates file with 7777 permissions.

    spec:
      volumes:
        -
          name: config-volume
          configMap:
            name: specialconfig2
      containers:
        -
          name: springapp
          image: '172.30.240.125:5000/sample/springapp@sha256:a2c13c7f96e32e44c99e21bc51fa07086bb553d21635dd8f1b9f1b54aed148ad'
          ports:
            -
              containerPort: 8080
              protocol: TCP
          resources: {  }
          volumeMounts:
            -
              name: config-volume
              mountPath: /opt/app-root/src/src/main/resources
          terminationMessagePath: /dev/termination-log
          imagePullPolicy: Always
          securityContext: {  }
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext:
        fsGroup: 7777

config map specialconfig2 is as follows (application.properties)

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=spring-boot-heroku-example
spring.datasource.password=spring-boot-heroku-example
chown 1001:0 application.properties ## not sure if this necessary
oc create configmap specialconfig2 --from-file=/Users/jjonagam/springboot-sample-app/application.properties

Also oc edit scc privileged fsGroup : RunAsAny

OCP local

oc cluster up --public-hostname='ocp.ck.osecloud.com' --metrics=true --image=registry.access.redhat.com/openshift3/ose --version=latest --routing-suffix='ocp.ck.osecloud.com'
Clone this wiki locally