RedHat Openshift command line

Red Hat OpenShift is a Kubernetes-based container platform for managing and orchestrating containerized applications. To interact with OpenShift from the command line, you can use the OpenShift Command-Line Interface (CLI), commonly known as oc. This tool allows you to perform various operations on your OpenShift cluster. Here are some common oc commands and their usage:

  1. Login to OpenShift Cluster:oc login https://<OpenShift Master URL> You will be prompted to provide your credentials.
  2. Project and Namespace Operations:
    • List all projects (namespaces):codeoc get projects
    • Create a new project (namespace):arduinoCopy codeoc new-project <project-name>
  3. Deploy Applications:
    • Deploy an application from a YAML file:create -f <yaml-file>
    • Deploy an application from a Git repository:arduinoCopy codeoc new-app <Git-repo-URL>
  4. Managing Deployments:
    • View deployments:oc get deployments
    • Scale a deployment:oc scale --replicas=<replica-count> deployment/<deployment-name>
  5. Expose Services:
    • Expose a service to the internet:oc expose service <service-name>
    • List routes (public URLs) for your services:arduinoCopy codeoc get routes
  6. Monitoring and Logging:
    • View cluster-wide metrics (requires the OpenShift Monitoring stack):oc get --raw /apis/custom.metrics.k8s.io/v1beta1
    • Access container logs:oc logs <pod-name>
  7. Security and User Management:
    • Create new users or manage user roles (requires appropriate permissions):sqlCopy codeoc create user <username>
    • Add a user to a project (namespace):oc adm policy add-role-to-user <role> <username> -n <project-name>
  8. Viewing Resources:
    • List pods in a project (namespace):oc get pods -n <project-name>
    • Describe a resource:phpCopy codeoc describe <resource-type> <resource-name>
  9. Accessing the Web Console:Open the OpenShift web console in a web browser by running:oc whoami --show-console
  10. Other Useful Commands:
  • Restart a pod:oc delete pod <pod-name>
  • Delete a resource (e.g., a service or deployment):oc delete <resource-type> <resource-name>

These are just some common oc commands for managing and interacting with an OpenShift cluster. The oc CLI is feature-rich and can perform a wide range of operations for application deployment, scaling, monitoring, and more. You can access the full documentation for oc by running oc --help or oc <command> --help for specific command usage information.

Linux: firewall-cmd command options

firewall-cmd is a command-line utility for managing firewalld, the dynamic firewall manager available on many Linux distributions. It allows you to configure various aspects of your firewall settings. To display the available options for firewall-cmd, you can use the --help option or explore specific subcommands and their options. Here are the general options:

  1. To display the general help and a list of available options for firewall-cmd:firewall-cmd --help
  2. To display the version of firewall-cmd:cssCopy codefirewall-cmd --version
  3. To display help for a specific subcommand, you can use:firewall-cmd --<subcommand> --help Replace <subcommand> with the specific operation you want to learn more about, such as --add-service, --add-port, --list-services, --list-ports, etc.

Here are some common firewall-cmd subcommands and their options:

  • --add-service: Add a service to the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --add-service=http firewall-cmd --add-service=http --permanent

  • --add-port: Add a port to the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --add-port=80/tcp firewall-cmd --add-port=80/tcp --permanent

  • --remove-service: Remove a service from the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --remove-service=http firewall-cmd --remove-service=http --permanent

  • --remove-port: Remove a port from the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --remove-port=80/tcp firewall-cmd --remove-port=80/tcp --permanent

  • --list-all: Show all configured rules, including services, ports, and other settings.
    • --permanent: List only the permanent rules.

Example:

firewall-cmd --list-all firewall-cmd --list-all --permanent

  • --reload: Reload the firewall configuration. Useful when you make changes to the configuration.

Example:

firewall-cmd --reload

These are just a few of the many options and subcommands available with firewall-cmd. For detailed information on specific options, you can refer to the firewall-cmd manual page or use the --help option for specific subcommands, as shown earlier.

SSH: How to copy my SSH key to a remote host

To copy your SSH key to a remote host, you can use the ssh-copy-id command, which is a convenient way to install your public key on a remote server. Here are the steps to do this:

  1. Generate SSH Key (if you haven’t already): If you don’t have an SSH key pair (public and private keys) already, you can generate one using the ssh-keygen command. Open a terminal on your local machine and run: ssh-keygen -t rsa -b 4096 -C "your_email@example.com" Replace "your_email@example.com" with your actual email address. This command will generate a new SSH key pair and store it in the default location (~/.ssh/id_rsa for the private key and ~/.ssh/id_rsa.pub for the public key).
  2. Copy the Public Key to the Remote Host: Use the ssh-copy-id command to copy your public key to the remote host. Replace your_username and remote_host with the appropriate values:bashCopy codessh-copy-id your_username@remote_host You’ll be prompted to enter your password on the remote host for authentication.Note: If you’re using a custom SSH port, you can specify it with the -p option, like this: ssh-copy-id -p custom_port your_username@remote_host
  3. Authenticate with Your SSH Key: After successfully copying the SSH key to the remote host, you can now log in without entering a password. The SSH key authentication will be used instead.Test this by trying to SSH into the remote host: ssh your_username@remote_host You should be logged in without being prompted for a password.

By following these steps, you’ve securely copied your SSH key to the remote host, allowing you to log in without needing to enter a password each time. This is a more secure and convenient way to access remote servers.

Linux: How to verify unexpected system restarts

In Linux, you can verify system restarts and view reboot history using various commands and log files. Here are some methods to check and verify system restarts:

  1. Using the last Command:The last command displays a list of system login entries and system shutdown/reboot times. To view reboot history, run:
    • last reboot The output will show a list of system reboot times, who initiated the reboot, and from which terminal or IP address it occurred.
  2. Checking System Logs:System logs contain information about system events, including reboots. The /var/log/messages or /var/log/syslog file typically contains reboot information. You can use grep to filter the relevant entries:
    • grep 'reboot' /var/log/messages orbashCopy codegrep 'reboot' /var/log/syslog This will display lines indicating system reboots along with timestamps.
  3. Using the uptime Command:The uptime command provides information about system uptime, including the current time, how long the system has been up, and the number of logged-in users. The load average values can also give you an idea if the system recently restarted:
    • uptime If the system uptime is low, it suggests a recent restart.
  4. Checking the /var/log/wtmp File:The /var/log/wtmp file contains a record of all logins and logouts, including system reboots. You can use the last command with the -f option to view this file:
    • last -f /var/log/wtmp This will display a more detailed history of logins, logouts, and reboots.
  5. Using Audit Logs (if configured):If you have the auditd service configured and running, it may log system events, including reboots, in /var/log/audit/audit.log. You can use the ausearch and aureport commands to search for and report on reboot events in the audit log.

These methods should help you verify system restarts and identify when and why they occurred. The choice of method may depend on your specific needs and the availability of logs on your system.