25 Mart 2022 Cuma

Red Hat OpenShift oc Komutu

Giriş
OpenShift CLI (oc) anlamına gelir. Açıklaması şöyle. Yani oc komutu daha gelişmiş seçenekler sunuyor
Because OpenShift Container Platform is a certified Kubernetes distribution, you can use the supported kubectl binaries that ship with OpenShift Container Platform, or you can gain extended functionality by using the oc binary.
Bir başka açıklama şöyle
minishift oc binary si kullanıyor yani kubectl get pods yerine oc get pods olarak çalışıyor
Sıkça kullanılan seçenekler şöyle
oc status
oc logs -f <pod_name>
oc get pods 
oc get po
oc get all
oc describe pod <pod_name>
oc get services 
oc delete all -l app=<app_name>
oc delete pod <pod_name>
oc get <resource> <resource_name> -o yaml 
autoscale seçeneği
Şöyle yaparız
# autoscale looks up a deployment, replica set, stateful set, or replication controller by
# name and creates an autoscaler that uses the given resource as a reference. An
# autoscaler can automatically increase or decrease number of pods deployed within
# the system as needed.

#Auto scale a deployment, with the number of pods between 2 and 4, target CPU utilization at 80%
oc autoscale deployment <resource_name> --min=2 --max=4 --cpu-percent=80%
create config map seçeneği
Şöyle yaparız
# Create a config map file and mount it as a volume to a deployment/deployment config:
oc create configmap <name> --from-file=<file name> --from-file=<file name{If multiple files}>

# Mount the config map into the pods via the deployment controller or deployment:
oc set volume deployment/<resource_name> --add --name=<config_map_volume> -m <mount_path> -t configmap --configmap-name=<name> --default-mode='0777'
create secret seçeneği
Şöyle yaparız
# Create a secret from the CLI and mount it as a volume to a deployment config:
oc create secret generic <secret_name> --from-literal=username=myuser --from-file=<file_name> 

oc set volume dc/<resource_name> --add --name=<secret_volume> -m <mount_path> -t secret --secret-name=<secret_name> --default-mode='0755' 
get route seçeneği
Örnek
Şöyle yaparız
oc get route default-route -n openshift-image-registry
expose  seçeneği
Örnek
Şöyle yaparız
oc expose new-app
Açıklaması şöyle
The expose command creates an OpenShift route, which configures ingress for my “Hello World” all configured with the OpenShift router (an HAProxy Load Balancer by default).
login seçeneği
OpenShift cluster'a giriş içindir
Örnek - token
Şöyle yaparız
$ oc login       
You must obtain an API token by visiting https://oauth-openshift.apps.varsha.lab.upshift.rdu2.redhat.com/oauth/token/request
Bu adrese gittikten sonra şöyle yaparız
# Log in with this token
oc login --token=sha256~vNVfZ0VuFK7SkveM_nGRFTS7nrfawCQnQ9FEPNScv-0 --server=https://api.varsha.lab.upshift.rdu2.redhat.com:6443
Örnek - kullanıcı ismi ve şifre
Şöyle yaparız
oc login -u <username> -p <password> <servername>

Example : oc login -u kubeadmin -p asdfghjkliuytr https://upi-o.varsha.lab.upshift.rdu2.redhat.com:6443
new-app seçeneği
Açıklaması şöyle
On executing this command, OpenShift does the following:
  • Created a build pod to do “stuff” for building the app
  • Created an OpenShift Build config
  • Pulled the builder image into OpenShift’s internal docker registry.
  • Cloned the “Hello World” repo locally
  • Seen that there’s a maven pom, so compiled the application using maven
  • Created a new container image with the compiled java application and pushed this container image into the internal container registry
  • Created a Kubernetes Deployment with pod spec, service spec etc.
  • Kicked off a deploy of the container image.
  • Removed the build pod.
project seçeneği
Şöyle yaparız
#Switch to a specific project:
oc project <project_name>

#List existing projects:
oc project list
oc projects

#Display the currently logged-in project:
oc project
rsh seçeneği
Bir pod'a erişmek için şöyle yaparız
oc rsh <pod_name>
oc exec <mypod> -- <command_to_execute_in_pod>
oc debug <pod_name>
scale seçeneği
Şöyle yaparız
oc scale dc <resource_name> --replicas=<count>
whoami seçeneği
Açıklaması şöyle
$ oc whoami --help
Show information about the current session

 The default options for this command will return the currently authenticated user name or an empty string.  Other flags
support returning the currently used token or the user context.

Usage:
  oc whoami [flags]

Examples:
  # Display the currently authenticated user
  oc whoami

Options:
      --show-console=false: If true, print the current server's web console URL
  -c, --show-context=false: Print the current user context name
      --show-server=false: If true, print the current server's REST API URL
  -t, --show-token=false: Print the token the current session is using. This will return an error if you are using a
different form of authentication.

Use "oc options" for a list of global command-line options (applies to all commands).
Örnek - --show-console
Açıklaması şöyle
The command oc whoami --show-console displays the web console URL via CLI.
Şöyle yaparız
$ oc whoami --show-console
https://console-openshift-console.apps.varsha.lab.upshift.rdu2.redhat.com



Hiç yorum yok:

Yorum Gönder

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...