$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill openshiftManage Red Hat OpenShift clusters and deployments. Configure projects, routes, builds, and deploy applications using OpenShift-specific features. Use when working with OpenShift Container Platform or OKD for enterprise Kubernetes.
| 1 | # OpenShift |
| 2 | |
| 3 | Deploy and manage applications on Red Hat OpenShift Container Platform. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Deploying applications to OpenShift clusters |
| 9 | - Using OpenShift-specific features (Routes, BuildConfigs) |
| 10 | - Managing projects and RBAC in OpenShift |
| 11 | - Implementing S2I (Source-to-Image) builds |
| 12 | - Working with OpenShift Operators |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - OpenShift cluster access |
| 17 | - oc CLI installed |
| 18 | - Basic Kubernetes knowledge |
| 19 | |
| 20 | ## CLI Basics |
| 21 | |
| 22 | ### Authentication |
| 23 | |
| 24 | ```bash |
| 25 | # Login to cluster |
| 26 | oc login https://api.cluster.example.com:6443 -u admin -p password |
| 27 | |
| 28 | # Login with token |
| 29 | oc login --token=sha256~xxxx --server=https://api.cluster.example.com:6443 |
| 30 | |
| 31 | # Check current context |
| 32 | oc whoami |
| 33 | oc whoami --show-server |
| 34 | oc whoami --show-context |
| 35 | |
| 36 | # Logout |
| 37 | oc logout |
| 38 | ``` |
| 39 | |
| 40 | ### Project Management |
| 41 | |
| 42 | ```bash |
| 43 | # Create project (namespace) |
| 44 | oc new-project myapp --display-name="My App" --description="My Application" |
| 45 | |
| 46 | # Switch project |
| 47 | oc project myapp |
| 48 | |
| 49 | # List projects |
| 50 | oc projects |
| 51 | |
| 52 | # Delete project |
| 53 | oc delete project myapp |
| 54 | ``` |
| 55 | |
| 56 | ## Deploying Applications |
| 57 | |
| 58 | ### From Image |
| 59 | |
| 60 | ```bash |
| 61 | # Deploy from container image |
| 62 | oc new-app --image=nginx:latest --name=webserver |
| 63 | |
| 64 | # Deploy from Docker Hub |
| 65 | oc new-app docker.io/library/nginx:latest |
| 66 | |
| 67 | # Deploy with environment variables |
| 68 | oc new-app myimage:latest \ |
| 69 | -e DATABASE_URL=postgres://localhost/db \ |
| 70 | -e APP_ENV=production |
| 71 | ``` |
| 72 | |
| 73 | ### From Source (S2I) |
| 74 | |
| 75 | ```bash |
| 76 | # Deploy from Git repository |
| 77 | oc new-app https://github.com/org/myapp.git |
| 78 | |
| 79 | # Specify builder image |
| 80 | oc new-app nodejs:18~https://github.com/org/nodejs-app.git |
| 81 | |
| 82 | # With context directory |
| 83 | oc new-app https://github.com/org/monorepo.git \ |
| 84 | --context-dir=backend \ |
| 85 | --name=backend-api |
| 86 | ``` |
| 87 | |
| 88 | ### From Template |
| 89 | |
| 90 | ```bash |
| 91 | # List available templates |
| 92 | oc get templates -n openshift |
| 93 | |
| 94 | # Deploy from template |
| 95 | oc new-app postgresql-persistent \ |
| 96 | -p POSTGRESQL_USER=user \ |
| 97 | -p POSTGRESQL_PASSWORD=secret \ |
| 98 | -p POSTGRESQL_DATABASE=mydb |
| 99 | ``` |
| 100 | |
| 101 | ## Routes |
| 102 | |
| 103 | ### Creating Routes |
| 104 | |
| 105 | ```yaml |
| 106 | apiVersion: route.openshift.io/v1 |
| 107 | kind: Route |
| 108 | metadata: |
| 109 | name: myapp |
| 110 | spec: |
| 111 | host: myapp.apps.cluster.example.com |
| 112 | to: |
| 113 | kind: Service |
| 114 | name: myapp |
| 115 | weight: 100 |
| 116 | port: |
| 117 | targetPort: 8080 |
| 118 | tls: |
| 119 | termination: edge |
| 120 | insecureEdgeTerminationPolicy: Redirect |
| 121 | ``` |
| 122 | |
| 123 | ```bash |
| 124 | # Create route via CLI |
| 125 | oc expose svc/myapp |
| 126 | |
| 127 | # Create with custom hostname |
| 128 | oc create route edge myapp \ |
| 129 | --service=myapp \ |
| 130 | --hostname=myapp.apps.cluster.example.com |
| 131 | |
| 132 | # Create passthrough route (TLS termination at pod) |
| 133 | oc create route passthrough myapp-secure --service=myapp |
| 134 | ``` |
| 135 | |
| 136 | ### A/B Testing |
| 137 | |
| 138 | ```yaml |
| 139 | apiVersion: route.openshift.io/v1 |
| 140 | kind: Route |
| 141 | metadata: |
| 142 | name: myapp |
| 143 | spec: |
| 144 | to: |
| 145 | kind: Service |
| 146 | name: myapp-v1 |
| 147 | weight: 90 |
| 148 | alternateBackends: |
| 149 | - kind: Service |
| 150 | name: myapp-v2 |
| 151 | weight: 10 |
| 152 | ``` |
| 153 | |
| 154 | ## Build Configurations |
| 155 | |
| 156 | ### BuildConfig |
| 157 | |
| 158 | ```yaml |
| 159 | apiVersion: build.openshift.io/v1 |
| 160 | kind: BuildConfig |
| 161 | metadata: |
| 162 | name: myapp |
| 163 | spec: |
| 164 | source: |
| 165 | type: Git |
| 166 | git: |
| 167 | uri: https://github.com/org/myapp.git |
| 168 | ref: main |
| 169 | strategy: |
| 170 | type: Docker |
| 171 | dockerStrategy: |
| 172 | dockerfilePath: Dockerfile |
| 173 | output: |
| 174 | to: |
| 175 | kind: ImageStreamTag |
| 176 | name: myapp:latest |
| 177 | triggers: |
| 178 | - type: ConfigChange |
| 179 | - type: GitHub |
| 180 | github: |
| 181 | secret: webhook-secret |
| 182 | ``` |
| 183 | |
| 184 | ### S2I Build |
| 185 | |
| 186 | ```yaml |
| 187 | apiVersion: build.openshift.io/v1 |
| 188 | kind: BuildConfig |
| 189 | metadata: |
| 190 | name: myapp |
| 191 | spec: |
| 192 | source: |
| 193 | type: Git |
| 194 | git: |
| 195 | uri: https://github.com/org/myapp.git |
| 196 | strategy: |
| 197 | type: Source |
| 198 | sourceStrategy: |
| 199 | from: |
| 200 | kind: ImageStreamTag |
| 201 | namespace: openshift |
| 202 | name: nodejs:18-ubi8 |
| 203 | env: |
| 204 | - name: NPM_RUN |
| 205 | value: start |
| 206 | output: |
| 207 | to: |
| 208 | kind: ImageStreamTag |
| 209 | name: myapp:latest |
| 210 | ``` |
| 211 | |
| 212 | ### Build Commands |
| 213 | |
| 214 | ```bash |
| 215 | # Start build |
| 216 | oc start-build myapp |
| 217 | |
| 218 | # Start build from local source |
| 219 | oc start-build myapp --from-dir=. |
| 220 | |
| 221 | # Follow build logs |
| 222 | oc start-build myapp --follow |
| 223 | |
| 224 | # View build logs |
| 225 | oc logs -f bc/myapp |
| 226 | |
| 227 | # Cancel build |
| 228 | oc cancel-build myapp-1 |
| 229 | ``` |
| 230 | |
| 231 | ## Image Streams |
| 232 | |
| 233 | ```yaml |
| 234 | apiVersion: image.openshift.io/v1 |
| 235 | kind: ImageStream |
| 236 | metadata: |
| 237 | name: myapp |
| 238 | spec: |
| 239 | lookupPolicy: |
| 240 | local: true |
| 241 | tags: |
| 242 | - name: latest |
| 243 | from: |
| 244 | kind: DockerImage |
| 245 | name: registry.example.com/myapp:latest |
| 246 | importPolicy: |
| 247 | scheduled: true |
| 248 | ``` |
| 249 | |
| 250 | ```bash |
| 251 | # Create image stream |
| 252 | oc create imagestream myapp |
| 253 | |
| 254 | # Import image |
| 255 | oc import-image myapp:latest \ |
| 256 | --from=docker.io/library/nginx:latest \ |
| 257 | --confirm |
| 258 | |
| 259 | # Tag image |
| 260 | oc tag myapp:latest myapp:production |
| 261 | ``` |
| 262 | |
| 263 | ## Deployment Configs |
| 264 | |
| 265 | ```yaml |
| 266 | apiVersion: apps.openshift.io/v1 |
| 267 | kind: DeploymentConfig |
| 268 | metadata: |
| 269 | name: myapp |
| 270 | spec: |
| 271 | replicas: 3 |
| 272 | selector: |
| 273 | app: myapp |
| 274 | t |