Skip to content

Commit

Permalink
Extend Kubernetes cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
abregman committed Aug 29, 2021
1 parent 8d92c04 commit be4d16e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 3 deletions.
24 changes: 23 additions & 1 deletion resources/git.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Git

Name | Description
### Learn Git
Name | Comments
:------|:------:
[git-scm](https://git-scm.com) | The best place (imho) to learn everything about Git (through reading)
[Interactive Git Branching Learning](https://learngitbranching.js.org/) | Visual and interactive way to learn Git branching
[Learn git concepts, not commands](https://dev.to/unseenwizzard/learn-git-concepts-not-commands-4gjc) | Article on Git concepts
[Codeacademy Learn Git](https://www.codecademy.com/learn/learn-git) | Not Free
Expand All @@ -10,6 +12,26 @@ Name | Description

## CheatSheet

* Clone a repository: `git clone https://github.com/bregman-arie/devops-resources.git`
* Pull changes from remote repository: `git pull`
* Pull changes without trying to merge the changes between the local branch and the remote one: `git pull --ff-only`

#### Branches
* Switch to a branch called "main": `git checkout main`
* Create (if doesn't exists) and switch to a branch called `devel`: `git checkout -b devel`
* List branches: `git branch`
* Update based on status of remote branches: `git remote prune origin`
* Delete local branch: `git branch -d some-branch`

#### Staging

* See what the current status in the repository: `git status`
* Add changes to the staging area: `git add <FILE>` or `git add .` to add everything

#### Commits
* Create a commit: `git commit`
* List of latest commits: `git log --oneline`
* Push commits to the remote branch: `git push origin main`
* Revert to commit X

```
Expand Down
3 changes: 3 additions & 0 deletions resources/jinja2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### CheatSheet

* Split string to list of items using comma as the separator: `{% set list1 = variable1.split(',') %}`
30 changes: 29 additions & 1 deletion resources/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,36 @@ Name | Comments

* List service accounts: `kubectl get serviceaccounts`

### Kubernetes
### Cluster

* Cluster version: `kubectl version`
* Cluster information: `kubectl cluster-info`
* List nodes: `kubectl get nodes`

### Pods

* List of Pods in current namespace: `kubectl get po`
* List of Pods in all amespaces: `kubectl get po --all-namespaces`
* Get containers names: `kubectl get po <POD_NAME> -o jsonpath="{.spec.containers[*].name}"`

* Create a Pod from file: `kubectl create -f pod_definition.yaml`
* Delete a Pod using a YAML definition: `kubectl delete -f pod_definition.yaml`
* Delete a Pod using the Pod name: `kubectl delete <POD_NAME>`
* Delete a Pod instantly: `kubectl delete <POD_NAME> --grace-period=0 --force`

* Execute commands inside a container: `kubectl exec -it -c <CONTAINER_NAME> <POD_NAME> ls`

* Display logs of a Pod: `kubectl logs <POD_NAME>`
* Display logs of a specific container in a Pod: `kubectl logs <POD_NAME> -c <CONTAINER_NAME>`

### User

* Creating a new user

```
openssl genrsa -out user.key 2048 # create key
openssl req key user.key user.csr -subj "/CN=user /O=sgroup" # create csr
openssl x509 -req -in user.csr -CA ca.crt -CAkey ca.key -CAcreateseral -out user.crt -days 365
kubectl config set-credentials myuser --client-certificates=$PWD/user.crt --client-key=$PWD/user.key
kubectl config set-context myuser-context --cluster=k8s-cluster --user=user
```
5 changes: 4 additions & 1 deletion resources/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ sudo ausearch -m avc -m user_avc -m selinux_err -m user_selinux_err -i -ts today

#### Tmux

* Join session `tmux a`
* Join a session `tmux a`
* Attach to existing session: `tmux attach -t <SESSION_NAME>`
* New tab: `ctrl + B + c`
* New session called "bla": `tmux new -s bla`

#### Virsh

Expand Down
3 changes: 3 additions & 0 deletions resources/openshift.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ Name | Comments
#### Accounts

* The username of the user currently logged in: `oc whoami`

* Add to user "user1" the ability to view the project "wonderland": `oc adm policy add-role-to-user view user1 -n wonderland`
* Add a user as admin to the project "wonderland": `oc adm policy add-role-to-user admin some_user -n wonderland`

* Get a list of all context whihc have ever been created: `oc config get-contexts`
* Check what is the current context: `oc whoami --show-context`
* The OpenShift server currently used: `oc whoami --show-server`
Expand Down
30 changes: 30 additions & 0 deletions resources/virtualization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Virtualization

### Virsh CheatSheet

* List VMs: `virsh list --all`
* Shutdown VMs: `virsh shutdown <VM_NAME>`
* Delete VMs: `virsh undefine <VM_NAME>`

* List pools: `virsh pool-list`
* Delete pool content: `virsh pool-delete <POOL_NAME>`
* Deactivate pool: `virsh pool-destroy <POOL_NAME>`
* Delete the pool object: `virsh pool-undefine <POOL_NAME>`

* List networks: `virsh net-list`
* Delete network: `virsh net-undefine <NETWORK_NAME> && virsh net-destroy <NETWORK_NAME>`

### Vagrant Resources

Name | Description
:------|:------:
[Official Docs](https://www.vagrantup.com/intro/index.html) | Multi-container applications

#### Vagrant Cheatsheet

* Initialize vagrant file using Fedora image: `vagrant init fedora/33-cloud-base`
* Bring up the VM: `vagrant up`
* SSH into the machine: `vagrant ssh`
* Shutdown: `vagrant halt`
* Delete the VM: `vagrant destroy`
* Reload Vagrant configuration: `vagrant reload`

0 comments on commit be4d16e

Please sign in to comment.