Merge branch 'MichaelCade:main' into main

This commit is contained in:
Tanmoy Santra 2023-05-08 08:48:14 +05:30 committed by GitHub
commit 91a354eb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
332 changed files with 23699 additions and 1096 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}

View File

@ -40,6 +40,8 @@ Next up we also need to get [Virtual Box](https://www.virtualbox.org/wiki/Downlo
Both installations are pretty straightforward and both have great communitites around them so feel free to reach out if you have issues and I can try and assist too.
> If you are using m1 macOS, I recommend to use [multiplass]([url](https://multipass.run/)) instead of Vagrant and VirtualBox. (reference : https://github.com/MichaelCade/90DaysOfDevOps/issues/365)
## Our first VAGRANTFILE
The VAGRANTFILE describes the type of machine we want to deploy. It also defines the configuration and provisioning for this machine.

View File

@ -92,7 +92,7 @@ This way when and where we use `$challenge` in our code, if we change the variab
If we now run our `sh` script you will see the printout that was added to our script.
![](Images/Day19_Linux5.png)
![](Images/Day19_Linux6.png)
We can also ask for user input that can set our variables using the following:

View File

@ -179,7 +179,7 @@ Following [Module 09a](https://microsoftlearning.github.io/AZ-104-MicrosoftAzure
- Task 6: Configure and test autoscaling of the Azure web app
This script I am using can be found in (Cloud/05Serverless)
This script I am using can be found in (Cloud/04Serverless)
![](Images/Day34_Cloud36.png)

View File

@ -71,10 +71,10 @@ I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atla
| Command | Example | Description |
| ------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| git init | `git init <directory>` | Create an empty git repository in the specified directory. |
| git clone | `git clone <repo>` | Clone repository located at <repo> onto local machine. |
| git clone | `git clone <repo>` | Clone repository located at \<repo> onto local machine. |
| git config | `git config user.name` | Define author name to be used for all commits in current repository `system`, `global`, `local` flag to set config options. |
| git add | `git add <directory>` | Stage all changes in <directory> for the next commit. We can also add <files> and <.> for everything. |
| git commit -m | `git commit -m "<message>"` | Commit the staged snapshot, use <message> to detail what is being committed. |
| git add | `git add <directory>` | Stage all changes in \<directory> for the next commit. We can also add \<files> and \<.> for everything. |
| git commit -m | `git commit -m "<message>"` | Commit the staged snapshot, use \<message> to detail what is being committed. |
| git status | `git status` | List files that are staged, unstaged and untracked. |
| git log | `git log` | Display all commit history using the default format. There are additional options with this command. |
| git diff | `git diff` | Show unstaged changes between your index and working directory. |
@ -83,8 +83,8 @@ I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atla
| Command | Example | Description |
| ---------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| git revert | `git revert <commit>` | Create a new commit that undoes all of the changes made in <commit> then apply it to the current branch. |
| git reset | `git reset <file>` | Remove <file> from the staging area, but leave the working directory unchanged. This unstaged a file without overwriting any changes. |
| git revert | `git revert <commit>` | Create a new commit that undoes all of the changes made in \<commit> then apply it to the current branch. |
| git reset | `git reset <file>` | Remove \<file> from the staging area, but leave the working directory unchanged. This unstaged a file without overwriting any changes. |
| git clean | `git clean -n` | Shows which files would be removed from the working directory. Use `-f` in place of `-n` to execute the clean. |
### Git Rewriting History
@ -92,25 +92,25 @@ I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atla
| Command | Example | Description |
| ---------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| git commit | `git commit --amend` | Replace the last commit with the staged changes and the last commit combined. Use with nothing staged to edit the last commits message. |
| git rebase | `git rebase <base>` | Rebase the current branch onto <base>. <base> can be a commit ID, branch name, a tag, or a relative reference to HEAD. |
| git rebase | `git rebase <base>` | Rebase the current branch onto \<base>. \<base> can be a commit ID, branch name, a tag, or a relative reference to HEAD. |
| git reflog | `git reflog` | Show a log of changes to the local repositorys HEAD. Add --relative-date flag to show date info or --all to show all refs. |
### Git Branches
| Command | Example | Description |
| ------------ | -------------------------- | ------------------------------------------------------------------------------------------------------------- |
| git branch | `git branch` | List all of the branches in your repo. Add a <branch> argument to create a new branch with the name <branch>. |
| git checkout | `git checkout -b <branch>` | Create and check out a new branch named <branch>. Drop the -b flag to checkout an existing branch. |
| git merge | `git merge <branch>` | Merge <branch> into the current branch. |
| git branch | `git branch` | List all of the branches in your repo. Add a \<branch> argument to create a new branch with the name \<branch>. |
| git checkout | `git checkout -b <branch>` | Create and check out a new branch named \<branch>. Drop the -b flag to checkout an existing branch. |
| git merge | `git merge <branch>` | Merge \<branch> into the current branch. |
### Git Remote Repositories
| Command | Example | Description |
| -------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| git remote add | `git remote add <name> <url>` | Create a new connection to a remote repo. After adding a remote, you can use <name> as a shortcut for <url> in other commands. |
| git fetch | `git fetch <remote> <branch>` | Fetches a specific <branch>, from the repo. Leave off <branch> to fetch all remote refs. |
| git remote add | `git remote add <name> <url>` | Create a new connection to a remote repo. After adding a remote, you can use \<name> as a shortcut for \<url> in other commands. |
| git fetch | `git fetch <remote> <branch>` | Fetches a specific \<branch>, from the repo. Leave off \<branch> to fetch all remote refs. |
| git pull | `git pull <remote>` | Fetch the specified remotes copy of current branch and immediately merge it into the local copy. |
| git push | `git push <remote> <branch>` | Push the branch to <remote>, along with necessary commits and objects. Creates named branch in the remote repo if it doesnt exist. |
| git push | `git push <remote> <branch>` | Push the branch to \<remote>, along with necessary commits and objects. Creates named branch in the remote repo if it doesnt exist. |
### Git Diff
@ -123,23 +123,23 @@ I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atla
| Command | Example | Description |
| ---------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| git config --global user.name <name> | `git config --global user.name <name>` | Define the author name to be used for all commits by the current user. |
| git config --global user.email <email> | `git config --global user.email <email>` | Define author email to be used for all commits by the current user. |
| git config --global alias <alias-name> <git-command> | `git config --global alias <alias-name> <git-command>` | Create shortcut for a git command . |
| git config --system core.editor <editor> | `git config --system core.editor <editor>` | Set the text editor to be used by commands for all users on the machine. <editor> arg should be the comamnd that launches the desired editor. |
| git config --global user.name \<name> | `git config --global user.name <name>` | Define the author name to be used for all commits by the current user. |
| git config --global user.email \<email> | `git config --global user.email <email>` | Define author email to be used for all commits by the current user. |
| git config --global alias \<alias-name> \<git-command> | `git config --global alias <alias-name> <git-command>` | Create shortcut for a git command . |
| git config --system core.editor \<editor> | `git config --system core.editor <editor>` | Set the text editor to be used by commands for all users on the machine. \<editor> arg should be the comamnd that launches the desired editor. |
| git config --global --edit | `git config --global --edit ` | Open the global configuration file in a text editor for manual editing. |
### Git Rebase
| Command | Example | Description |
| -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| git rebase -i <base> | `git rebase -i <base>` | Interactively rebase current branch onto <base>. Launches editor to enter commands for how each commit will be transferred to the new base. |
| git rebase -i \<base> | `git rebase -i <base>` | Interactively rebase current branch onto \<base>. Launches editor to enter commands for how each commit will be transferred to the new base. |
### Git Pull
| Command | Example | Description |
| -------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| git pull --rebase <remote> | `git pull --rebase <remote>` | Fetch the remotes copy of current branch and rebases it into the local copy. Uses git rebase instead of the merge to integrate the branches. |
| git pull --rebase \<remote> | `git pull --rebase <remote>` | Fetch the remotes copy of current branch and rebases it into the local copy. Uses git rebase instead of the merge to integrate the branches. |
### Git Reset
@ -147,16 +147,16 @@ I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atla
| ------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| git reset | `git reset ` | Reset the staging area to match the most recent commit but leave the working directory unchanged. |
| git reset --hard | `git reset --hard` | Reset staging area and working directory to match most recent commit and overwrites all changes in the working directory |
| git reset <commit> | `git reset <commit>` | Move the current branch tip backwards to <commit>, reset the staging area to match, but leave the working directory alone |
| git reset --hard <commit> | `git reset --hard <commit>` | Same as previous, but resets both the staging area & working directory to match. Deletes uncommitted changes, and all commits after <commit>. |
| git reset \<commit> | `git reset <commit>` | Move the current branch tip backwards to \<commit>, reset the staging area to match, but leave the working directory alone |
| git reset --hard \<commit> | `git reset --hard <commit>` | Same as previous, but resets both the staging area & working directory to match. Deletes uncommitted changes, and all commits after \<commit>. |
### Git Push
| Command | Example | Description |
| ------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| git push <remote> --force | `git push <remote> --force` | Forces the git push even if it results in a non-fast-forward merge. Do not use the --force flag unless youre sure you know what youre doing. |
| git push <remote> --all | `git push <remote> --all` | Push all of your local branches to the specified remote. |
| git push <remote> --tags | `git push <remote> --tags` | Tags arent automatically pushed when you push a branch or use the --all flag. The --tags flag sends all of your local tags to the remote repo. |
| git push \<remote> --force | `git push <remote> --force` | Forces the git push even if it results in a non-fast-forward merge. Do not use the --force flag unless youre sure you know what youre doing. |
| git push \<remote> --all | `git push <remote> --all` | Push all of your local branches to the specified remote. |
| git push \<remote> --tags | `git push <remote> --tags` | Tags arent automatically pushed when you push a branch or use the --all flag. The --tags flag sends all of your local tags to the remote repo. |
## Resources

View File

@ -102,7 +102,7 @@ We also have two other types of volumes that we will not get into detail on but
In the session yesterday we walked through creating a stateless application, here we want to do the same but we want to use our minikube cluster to deploy a stateful workload.
A recap on the minikube command we are using to have the capability and addons to use persistence is `minikube start --addons volumesnapshots,csi-hostpath-driver --apiserver-port=6443 --container-runtime=containerd -p mc-demo --Kubernetes-version=1.21.2`
A recap on the minikube command we are using to have the capability and addons to use persistence is `minikube start --addons volumesnapshots,csi-hostpath-driver --apiserver-port=6443 --container-runtime=containerd -p mc-demo --kubernetes-version=1.21.2`
This command uses the CSI-hostpath-driver which is what gives us our storageclass, something I will show later.
@ -208,7 +208,7 @@ We can then create this in our ingress namespace with `kubectl create -f Pacman-
![](Images/Day55_Kubernetes15.png)
Then if we run `kubectl get ingress -n Pacman
Then if we run `kubectl get ingress -n Pacman`
![](Images/Day55_Kubernetes16.png)

View File

@ -37,7 +37,7 @@ Before we then start to look at controlling other nodes in our environment, we c
![](Images/Day64_config2.png)
Or an actual real-life use for a module might be something like `ansible webservers --m service -a "name=httpd state=started"` this will tell us if all of our webservers have the httpd service running. I have glossed over the webservers term used in that command.
Or an actual real-life use for a module might be something like `ansible webservers -m service -a "name=httpd state=started"` this will tell us if all of our webservers have the httpd service running. I have glossed over the webservers term used in that command.
### hosts

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 KiB

View File

@ -1,138 +1,140 @@
## Installing & Configuring Git
## Instalación y configuración de Git
Git is an open source, cross-platform tool for version control. If you are like me, using Ubuntu or most Linux environments you might find that you already have git installed but we are going to run through the install and configuration.
Git es una herramienta multiplataforma de código abierto para el control de versiones. En la mayoría de entornos Linux viene instalado por defecto, pero de todas formas vamos a repasar la instalación y configuración.
Even if you already have git installed on your system it is also a good idea to make sure we are up to date.
Incluso si ya tienes git instalado en tu sistema es una buena idea asegurarse de que está actualizado.
### Installing Git
### Instalación de Git
As already mentioned Git is cross-platform, we will be running through Windows and Linux but you can find macOS also listed [here](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
Como ya se ha mencionado Git es multiplataforma, vamos a ver Windows y Linux, pero también puedes encontrar macOS en la lista de [descargas](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
For [Windows](https://git-scm.com/download/win) we can grab our installers from the official site.
Para [Windows](https://git-scm.com/download/win) podemos obtener nuestros instaladores desde el sitio oficial o también puedes usar `winget`, Windows Application Package Manager.
You could also use `winget` on your Windows machine, think of this as your Windows Application Package Manager.
Before we install anything let's see what version we have on our Windows Machine. Open a PowerShell window and run `git --version`
Antes de instalar nada vamos a ver qué versión tenemos en nuestra máquina Windows. Abre una ventana de PowerShell y ejecuta `git --version`.
![](Images/Day36_Git1.png)
We can also check our WSL Ubuntu version of Git as well.
También podemos comprobar nuestra versión en el [WSL](https://es.wikipedia.org/wiki/Subsistema_de_Windows_para_Linux) Ubuntu.
![](Images/Day36_Git2.png)
At the time of writing the latest Windows release is `2.35.1` so we have some updating to do there which I will run through. I expect the same for Linux.
En el momento de escribir esto la última versión de Windows es `2.35.1` por lo que tenemos que actualizarla. Lo mismo con Linux.
I went ahead and downloaded the latest installer and ran through the wizard and will document that here. The important thing to note is that git will uninstall previous versions before installing the latest.
Descargué el último instalador y ejecuté el asistente. Lo importante a tener en cuenta es que git desinstalará las versiones anteriores antes de instalar la última. Lo que significa que el proceso que se muestra a continuación es también el mismo proceso en su mayor parte como si estuviera instalando por primera vez.
Meaning that the process shown below is also the same process for the most part as if you were installing from no git.
It is a very simple installation. Once downloaded double click and get started. Read through the GNU license agreement. But remember this is free and open-source software.
Es una instalación muy sencilla. Una vez descargado haga doble clic y comience. Lea el acuerdo de licencia GNU. Pero recuerde que este es un software libre y de código abierto.
![](Images/Day36_Git3.png)
Now we can choose additional components that we would like to also install but also associate with git. On Windows, I always make sure I install Git Bash as this allows us to run bash scripts on Windows.
Ahora podemos elegir componentes adicionales que nos gustaría también instalar para asociar con git. En Windows, siempre me aseguro de instalar Git Bash ya que nos permite ejecutar scripts bash en Windows.
![](Images/Day36_Git4.png)
We can then choose which SSH Executable we wish to use. IN leave this as the bundled OpenSSH that you might have seen in the Linux section.
Podemos entonces elegir qué ejecutable SSH deseamos utilizar.
![](Images/Day36_Git5.png)
We then have experimental features that we may wish to enable, for me I don't need them so I don't enable them, you can always come back in through the installation and enable these later on.
Luego tenemos características experimentales que podemos habilitar, yo no las necesito así que no las habilito, siempre puedes volver a la instalación y habilitarlas más tarde.
![](Images/Day36_Git6.png)
Installation complete, we can now choose to open Git Bash and or the latest release notes.
Instalación completada, ahora podemos elegir abrir Git Bash y o las últimas notas de la versión.
![](Images/Day36_Git7.png)
The final check is to take a look in our PowerShell window at what version of git we have now.
La comprobación final es echar un vistazo en PowerShell la versión actual de git.
![](Images/Day36_Git8.png)
Super simple stuff and now we are on the latest version. On our Linux machine, we seemed to be a little behind so we can also walk through that update process.
Super simple y ahora estamos en la última versión.
I simply run the `sudo apt-get install git` command.
En nuestra máquina Linux el proceso de actualización resulta más directo ejecutando el comando `sudo apt-get install git`.
![](Images/Day36_Git9.png)
You could also run the following which will add the git repository for software installations.
También puedes añadir el repositorio git para las actualizaciones del software.
```
```shell
sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get install git -y
sudo apt-get install git -yinstalaciones
git --version
```
### Configuring Git
### Configurando Git
When we first use git we have to define some settings,
Cuando usamos git por primera vez tenemos que definir algunas configuraciones,
- Name
- Email
- Default Editor
- Line Ending
- Nombre de usuario
- Correo electrónico
- Editor por defecto
- Fin de línea
This can be done at three levels
Esto se puede hacer en tres niveles
- System = All users
- Global = All repositories of the current user
- Local = The current repository
- Sistema = Todos los usuarios
- Global = Todos los repositorios del usuario actual
- Local = El repositorio actual
Example:
`git config --global user.name "Michael Cade"`
`git config --global user.email Michael.Cade@90DaysOfDevOPs.com"`
Depending on your Operating System will determine the default text editor. In my Ubuntu machine without setting the next command is using nano. The below command will change this to visual studio code.
Ejemplo:
```shell
git config --global user.name "Michael Cade"
git config --global user.email "Michael.Cade@90DaysOfDevOPs.com"
```
Dependiendo del sistema operativo se determinará el editor de texto por defecto. En Ubuntu sin configurar el siguiente comando está utilizando nano. El siguiente comando cambiará esto a visual studio code.
`git config --global core.editor "code --wait"`
```shell
git config --global core.editor "code --wait"
```
now if we want to be able to see all git configurations then we can use the following command.
Podemos ver todas las configuraciones de git con el siguiente comando.
`git config --global -e`
```shell
git config --global -e
```
![](Images/Day36_Git10.png)
On any machine this file will be named `.gitconfig` on my Windows machine you will find this in your user account directory.
En cualquier máquina este archivo se llamará `.gitconfig`. En Windows lo encontrarás en el directorio de la cuenta de usuario.
![](Images/Day36_Git11.png)
### Git Theory
### Teoría Git
I mentioned in the post yesterday that there were other version control types and we can split these down into two different types. One is Client Server and the other is Distributed.
Mencioné en el post de ayer que había otros tipos de control de versiones y podemos dividirlos en dos tipos diferentes. Los que son Cliente-Servidor y los que son Distribuidos.
### Client-Server Version Control
### Control de versiones Cliente-Servidor
Before git was around Client-Server was the defacto method for version control. An example of this would be [Apache Subversion](https://subversion.apache.org/) which is an open source version control system founded in 2000.
Antes de que existiera git, el tipo de Cliente-Servidor era el método de facto para el control de versiones. Un ejemplo de esto sería [Apache Subversion](https://subversion.apache.org/) que es un sistema de control de versiones de código abierto fundado en el año 2000.
In this model of Client-Server version control, the first step the developer downloads the source code and the actual files from the server. This doesn't remove the conflicts but it does remove the complexity of the conflicts and how to resolve them.
En este modelo de control de versiones Cliente-Servidor, el primer paso que da el desarrollador es descargar el código fuente y los archivos reales del servidor. Esto no elimina los conflictos, pero sí la complejidad de los conflictos y cómo resolverlos.
![](Images/Day36_Git12.png)
Now for example let's say we have two developers working on the same files and one wins the race and commits or uploads their file back to the server first with their new changes. When the second developer goes to update they have a conflict.
Ahora, por ejemplo, digamos que tenemos dos desarrolladores trabajando en los mismos archivos y uno gana la carrera y confirma o sube su archivo de nuevo al servidor en primer lugar con sus nuevos cambios. Cuando el segundo desarrollador va a actualizar tiene un conflicto.
![](Images/Day36_Git13.png)
So now the Dev needs to pull down the first devs code change next to their check and then commit once those conflicts have been settled.
Así que ahora el desarrollador tiene que tirar hacia abajo el primer cambio de código junto a su cheque y luego confirmar una vez que los conflictos se han resuelto.
![](Images/Day36_Git15.png)
### Distributed Version Control
### Control de versiones distribuido
Git is not the only distributed version control system. But it is very much the defacto.
Git no es el único sistema de control de versiones distribuido. Pero es en gran medida el defacto.
Some of the major benefits of Git are:
Algunos de los principales beneficios de Git son:
- Fast
- Smart
- Rápido
- Inteligente
- Flexible
- Safe & Secure
- Seguro
Unlike the Client-Server version control model, each developer downloads the source repository meaning everything. History of commits, all the branches etc.
A diferencia del modelo de control de versiones Cliente-Servidor, cada desarrollador descarga el repositorio fuente, es decir, todo. Historial de commits, todas las ramas, etc.
![](Images/Day36_Git16.png)
## Resources
## Recursos
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
@ -140,5 +142,13 @@ Unlike the Client-Server version control model, each developer downloads the sou
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [En español] [Comandos Git](https://gitea.vergaracarmona.es/man-linux/comandos-git)
- [En español][Apuntes Curso de Git](https://vergaracarmona.es/wp-content/uploads/2022/10/Curso-git_vergaracarmona.es_.pdf) de [Juan Carlos Rubio](https://www.linkedin.com/in/juan-carlos-rubio-pineda/Curso-git_vergaracarmona-es).
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- ["Instalar git en ubuntu"](https://vergaracarmona.es/instalar-git-en-ubuntu/)
- ["Comandos de git"](https://vergaracarmona.es/comandos-de-git/)
- ["Estrategias de fusión en git: Ship / Show / Ask"](https://vergaracarmona.es/estrategias-bifurcacion-git-ship-show-ask/)
- ["Resolver conflictos en Git. Merge, Squash, Rebase o Pull"](https://vergaracarmona.es/merge-squash-rebase-pull/)
- ["Borrar commits de git: reset, rebase y cherry-pick"](https://vergaracarmona.es/reset-rebase-cherry-pick/)
See you on [Day 37](day37.md)
Nos vemos en el [Día 37](day37.md)

View File

@ -1,154 +1,161 @@
## Gitting to know Git
## Conociendo a Git
Apologies for the terrible puns in the title and throughout. I am surely not the first person to turn Git into a dad joke!
Pido disculpas por los terribles juegos de palabras del título (Título original: *Gitting to know Git*). Seguro que no soy la primera persona que convierte Git en un chiste de padres.
In the last two posts we learnt about version control systems, and some of the fundamental workflows of git as a version control system [Day 35](day35.md) Then we got git installed on our system, updated and configured. We also went a little deeper into the theory between the Client-Server version control system and Git which is a distributed version control system [Day 36](day36.md).
En los dos últimos posts aprendimos acerca de los sistemas de control de versiones, y algunos de los flujos de trabajo fundamentales de git ([Día 35](day35.md)). Luego conseguimos instalar git en nuestro sistema, actualizarlo y configurarlo. También vimos algo de la teoría entre los tipos de sistema de control de versiones Cliente-Servidor y los distribuidos en el [Día 36](day36.md).
Now we are going to run through some of the commands and use cases that we will all commonly see with git.
Ahora vamos a repasar algunos de los comandos y casos de uso habituales con git.
### Where to git help with git?
### Git ayuda con git
There are going to be times when you just cannot remember or just don't know the command you need to get things done with git. You are going to need help.
Habrá momentos en los que simplemente no recuerdes o no sepas el comando que necesitas para hacer algo con git. Necesitarás ayuda. Google o cualquier motor de búsqueda será probablemente tu primer puerto de escala cuando busques ayuda. (También las IAs)
Google or any search engine is likely to be your first port of call when searching for help.
Secondly, the next place is going to be the official git site and the documentation. [git-scm.com/docs](http://git-scm.com/docs) Here you will find not only a solid reference to all the commands available but also lots of different resources.
El siguiente lugar, sobretodo a modo de confirmación, va a ser el sitio oficial de git y la documentación: [git-scm.com/docs](http://git-scm.com/docs). Aquí no sólo encontrarás una referencia sólida de todos los comandos disponibles, sino también un montón de recursos diferentes.
![](Images/Day37_Git1.png)
We can also access this same documentation which is super useful if you are without connectivity from the terminal. If we chose the `git add` command for example we can run `git add --help` and we see below the manual.
También podemos acceder a esta misma documentación desde la terminal, lo cual es muy útil si trabajas sin conexión. Si elegimos el comando `git add` por ejemplo podemos ejecutar `git add --help` y veremos el manual concreto del subcomando.
![](Images/Day37_Git2.png)
We can also in the shell use `git add -h` which is going to give us a summary of the options we have available.
También podemos usar en la shell `git add -h` que nos va a dar un resumen de las opciones que tenemos disponibles.
![](Images/Day37_Git3.png)
### Myths surrounding Git
### Mitos en torno a Git
"Git has no access control" - You can empower a leader to maintain source code.
"Git no tiene control de acceso" - Puedes autorizar a quien quieras a mantener el código fuente.
"Git is too heavy" - Git can provide shallow repositories which means a reduced amount of history if you have large projects.
"Git es demasiado pesado" - Git puede proporcionar repositorios poco profundos, lo que significa una cantidad reducida de historial si tienes proyectos grandes.
### Real shortcomings
### Deficiencias reales
Not ideal for Binary files. Great for source code but not great for executable files or videos for example.
No es ideal para archivos binarios. Es ideal para código fuente, pero no para archivos ejecutables o vídeos, por ejemplo.
Git is not user-friendly, the fact that we have to spend time talking about commands and functions of the tool is probably a key sign of that.
Git no es fácil de aprender, el hecho de que tengamos que pasar tiempo hablando de comandos y funciones de la herramienta es probablemente una señal de ello. Sin embargo, en general, git es difícil de aprender pero fácil de usar.
Overall though, git is hard to learn but easy to use.
### El ecosistema git
### The git ecosystem
Quiero cubrir brevemente el ecosistema alrededor de git pero no profundizar en estas áreas, pero creo que es importante señalarlas aquí a un alto nivel.
I want to briefly cover the ecosystem around git but not deep dive into some of these areas but I think it's important to note these here at a high level.
Casi todas las herramientas de desarrollo modernas soportan Git.
Almost all modern development tools support Git.
- Developer tools - We have already mentioned visual studio code but you will find git plugins and integrations into sublime text and other text editors and IDEs.
- Team tools - Also mentioned around tools like Jenkins from a CI/CD point of view, Slack from a messaging framework and Jira for project management and issue tracking.
- Cloud Providers - All the large cloud providers support git, Microsoft Azure, Amazon AWS, and Google Cloud Platform.
- Git-Based services - Then we have GitHub, GitLab and BitBucket which we will cover in more detail later on. I have heard of these services as the social network for code!
- **Herramientas para desarrolladores** - Ya hemos mencionado visual studio code pero encontrarás plugins de git e integraciones en sublime text y otros editores de texto e IDEs.
- **Herramientas de equipo** - También se han mencionado herramientas como Jenkins desde un punto de vista de CI/CD, Slack desde un marco de mensajería y Jira para la gestión de proyectos y seguimiento de incidencias.
- **Proveedores de nube** - Todos los grandes proveedores de nube soportan git: Microsoft Azure, Amazon AWS y Google Cloud Platform.
- **Servicios basados en Git** - Luego tenemos GitHub, GitLab y BitBucket que cubriremos en más detalle más adelante. Estos servicios se conocen como las redes sociales del código.
### The Git Cheatsheet
We have not covered most of these commands but having looked at some cheat sheets available online I wanted to document some of the git commands and what their purpose is. We don't need to remember these all, and with more hands-on practice and use you will pick at least the git basics.
No hemos cubierto la mayoría de comandos de git, ya que tiene un amplio abanico de posibilidades, pero después de haber mirado algunas hojas de trucos disponibles en línea vamos a documentar algunos de ellos y su propósito. No necesitamos recordarlos todos, ya que a través de la práctica y el uso aprenderás al menos mucho más de git.
I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet) but writing them down and reading the description is a good way to get to know what the commands are as well as getting hands-on in everyday tasks.
Estos comandos se han sacado de [atlassian](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet), escribirlos y leer la descripción es una buena forma de conocer su uso, así que manos a la obra en las tareas diarias:
### Git Basics
- [Conceptos básicos de Git](#conceptos-básicos-de-git)
- [Deshacer cambios Git](#deshacer-cambios-git)
- [Historial de reescritura de Git](#historial-de-reescritura-de-git)
- [Git Branches](#git-branches)
- [Repositorios remotos Git](#repositorios-remotos-git)
- [Git Diff](#git-diff)
- [Git Config](#git-config)
- [Git Rebase](#git-rebase)
- [Git Pull](#git-pull)
- [Git Reset](#git-reset)
- [Git Push](#git-push)
| Command | Example | Description |
| ------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| git init | `git init <directory>` | Create an empty git repository in the specified directory. |
| git clone | `git clone <repo>` | Clone repository located at <repo> onto local machine. |
| git config | `git config user.name` | Define author name to be used for all commits in current repository `system`, `global`, `local` flag to set config options. |
| git add | `git add <directory>` | Stage all changes in <directory> for the next commit. We can also add <files> and <.> for everything. |
| git commit -m | `git commit -m "<message>"` | Commit the staged snapshot, use <message> to detail what is being committed. |
| git status | `git status` | List files that are staged, unstaged and untracked. |
| git log | `git log` | Display all commit history using the default format. There are additional options with this command. |
| git diff | `git diff` | Show unstaged changes between your index and working directory. |
### Conceptos básicos de Git
### Git Undoing Changes
| Comando | Ejemplo | Descripción |
| ------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| git init | `git init <directory>` | Crea un repositorio git vacío en el directorio especificado. |
| git clone | `git clone <repo>` | Clona el repositorio ubicado en <repo> en la máquina local. |
| git config | `git config user.name` | Definir opciones que se usará para todos los commits según el entorno `system`, `global` o `local`. |
| git add | `git add <directory>` | Prepara los cambios en <directorio> para la próxima confirmación. También podemos añadir <ficheros> y <.> para todo. |
| git commit -m | `git commit -m "<message>"` | Confirmar la instantánea preparada, usando <mensaje> para detallar lo que se está confirmando. |
| git status | `git status` | Lista los archivos que están organizados, no organizados y sin seguimiento. |
| git log | `git log` | Muestra todo el historial de confirmaciones usando el formato por defecto. Hay opciones adicionales con este comando. |
| git diff | `git diff` | Muestra los cambios no organizados entre tu índice y el directorio de trabajo. |
| Command | Example | Description |
| ---------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| git revert | `git revert <commit>` | Create a new commit that undoes all of the changes made in <commit> then apply it to the current branch. |
| git reset | `git reset <file>` | Remove <file> from the staging area, but leave the working directory unchanged. This unstaged a file without overwriting any changes. |
| git clean | `git clean -n` | Shows which files would be removed from the working directory. Use `-f` in place of `-n` to execute the clean. |
### Deshacer cambios Git
### Git Rewriting History
| Comando | Ejemplo | Descripción |
| ---------- | --------------------- | ------------------------------------------------------------------------------------------------------------------ |
| git revert | `git revert <commit>` | Crear un nuevo commit que deshaga todos los cambios realizados en <commit> y aplicarlo a la rama actual. |
| git reset | `git reset <file>` | Elimina <fichero> del área de preparación dejando el directorio de trabajo sin cambios. |
| git clean | `git clean -n` | Muestra qué archivos se eliminarán del directorio de trabajo. Usa `-f` en lugar de `-n` para ejecutar la limpieza. |
| Command | Example | Description |
| ---------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| git commit | `git commit --amend` | Replace the last commit with the staged changes and the last commit combined. Use with nothing staged to edit the last commits message. |
| git rebase | `git rebase <base>` | Rebase the current branch onto <base>. <base> can be a commit ID, branch name, a tag, or a relative reference to HEAD. |
| git reflog | `git reflog` | Show a log of changes to the local repositorys HEAD. Add --relative-date flag to show date info or --all to show all refs. |
### Historial de reescritura de Git
| Comando | Ejemplo | Descripción |
| ---------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| git commit | `git commit --amend` | Reemplazar el último commit con los cambios en staged y el último commit combinados. Editas el mensaje del último commit. |
| git rebase | `git rebase <base>` | Rebase la rama actual en <base> que puede ser un commit ID, un nombre de rama, una etiqueta o una referencia relativa a HEAD. |
| git reflog | `git reflog` | Muestra registro de cambios en el HEAD del repositorio local. Con --relative-date muestra información de fechas y --all para mostrar todas las referencias. |
### Git Branches
| Command | Example | Description |
| ------------ | -------------------------- | ------------------------------------------------------------------------------------------------------------- |
| git branch | `git branch` | List all of the branches in your repo. Add a <branch> argument to create a new branch with the name <branch>. |
| git checkout | `git checkout -b <branch>` | Create and check out a new branch named <branch>. Drop the -b flag to checkout an existing branch. |
| git merge | `git merge <branch>` | Merge <branch> into the current branch. |
| Comando | Ejemplo | Descripción |
| ------------ | -------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| git branch | `git branch` | Lista todas las ramas de tu repositorio. Añade un argumento <branch> para crear una nueva rama con el nombre <branch>. |
| git checkout | `git checkout -b <branch>` | Crea y comprueba una nueva rama con el nombre <branch>. Elimina la opción -b para obtener una rama existent |
| git merge | `git merge <branch>` | Fusiona <branch> en la rama actual. |
### Git Remote Repositories
### Repositorios remotos Git
| Command | Example | Description |
| -------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| git remote add | `git remote add <name> <url>` | Create a new connection to a remote repo. After adding a remote, you can use <name> as a shortcut for <url> in other commands. |
| git fetch | `git fetch <remote> <branch>` | Fetches a specific <branch>, from the repo. Leave off <branch> to fetch all remote refs. |
| git pull | `git pull <remote>` | Fetch the specified remotes copy of current branch and immediately merge it into the local copy. |
| git push | `git push <remote> <branch>` | Push the branch to <remote>, along with necessary commits and objects. Creates named branch in the remote repo if it doesnt exist. |
| Comando | Ejemplo | Descripción |
| -------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| git remote add | `git remote add <name> <url>` | Crea una nueva conexión a un repositorio remoto. Después de añadir un remoto, puedes usar <nombre> como atajo para <url> en otros comandos. |
| git fetch | `git fetch <remote> <branch>` | Obtiene un <branch> específico del repositorio. Deja <branch> para obtener todas las referencias remotas. |
| git pull | `git pull <remote>` | Obtiene la copia remota especificada de la rama actual e inmediatamente la fusiona con la copia local. |
| git push | `git push <remote> <branch>` | Empuja la rama a <remote>, junto con los commits y objetos necesarios. Crea la rama con el nombre en el repositorio remoto si no existe. |
### Git Diff
| Command | Example | Description |
| ----------------- | ------------------- | ---------------------------------------------------------------------- |
| git diff HEAD | `git diff HEAD` | Show the difference between the working directory and the last commit. |
| git diff --cached | `git diff --cached` | Show difference between staged changes and last commit |
| Comando | Ejemplo | Descripción |
| ----------------- | ------------------- | ------------------------------------------------------------------------ |
| git diff HEAD | `git diff HEAD` | Muestra la diferencia entre el directorio de trabajo y el último commit. |
| git diff --cached | `git diff --cached` | Muestra la diferencia entre los cambios realizados y el último commit. |
### Git Config
| Command | Example | Description |
| ---------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
| git config --global user.name <name> | `git config --global user.name <name>` | Define the author name to be used for all commits by the current user. |
| git config --global user.email <email> | `git config --global user.email <email>` | Define author email to be used for all commits by the current user. |
| git config --global alias <alias-name> <git-command> | `git config --global alias <alias-name> <git-command>` | Create shortcut for a git command . |
| git config --system core.editor <editor> | `git config --system core.editor <editor>` | Set the text editor to be used by commands for all users on the machine. <editor> arg should be the comamnd that launches the desired editor. |
| git config --global --edit | `git config --global --edit ` | Open the global configuration file in a text editor for manual editing. |
| Comando | Ejemplo | Descripción |
| ---------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| git config --global user.name <name> | `git config --global user.name <name>` | Define el nombre de autor que se usará para todos los commits del usuario actual. |
| git config --global user.email <email> | `git config --global user.email <email>` | Define el email del autor que se usará para todas las confirmaciones del usuario actual. |
| git config --global alias <alias-name> <git-command> | `git config --global alias <alias-name> <git-command>` | Crear un acceso directo para un comando git. |
| git config --system core.editor <editor> | `git config --system core.editor <editor>` | Establece el editor de texto que usarán todos los usuarios de la máquina. <editor> arg debe ser el comando que lanza el editor deseado. |
| git config --global --edit | `git config --global --edit ` | Abrir el archivo de configuración global en un editor de texto para su edición manual. |
### Git Rebase
| Command | Example | Description |
| -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| git rebase -i <base> | `git rebase -i <base>` | Interactively rebase current branch onto <base>. Launches editor to enter commands for how each commit will be transferred to the new base. |
| Comando | Ejemplo | Descripción |
| -------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| git rebase -i <base> | `git rebase -i <base>` | Rebase interactivamente la rama actual en <base>. Inicia el editor para introducir comandos sobre cómo se transferirá cada confirmación a la nueva base. |
### Git Pull
| Command | Example | Description |
| -------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| git pull --rebase <remote> | `git pull --rebase <remote>` | Fetch the remotes copy of current branch and rebases it into the local copy. Uses git rebase instead of the merge to integrate the branches. |
| Comando | Ejemplo | Descripción |
| -------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| git pull --rebase <remote> | `git pull --rebase <remote>` | Obtiene la copia remota de la rama actual y la vuelve a basar en la copia local. Utiliza git rebase en lugar de merge para integrar las ramas. |
### Git Reset
| Command | Example | Description |
| ------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| git reset | `git reset ` | Reset the staging area to match the most recent commit but leave the working directory unchanged. |
| git reset --hard | `git reset --hard` | Reset staging area and working directory to match most recent commit and overwrites all changes in the working directory |
| git reset <commit> | `git reset <commit>` | Move the current branch tip backwards to <commit>, reset the staging area to match, but leave the working directory alone |
| git reset --hard <commit> | `git reset --hard <commit>` | Same as previous, but resets both the staging area & working directory to match. Deletes uncommitted changes, and all commits after <commit>. |
| Comando | Ejemplo | Descripción |
| ------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| git reset | `git reset ` | Restablece el área de preparación para que coincida con la confirmación más reciente, pero deja el directorio de trabajo sin cambios. |
| git reset --hard | `git reset --hard` | Restablece el área de preparación y el directorio de trabajo para que coincidan con la confirmación más reciente y sobreescribe todos los cambios en el directorio de trabajo. |
| git reset <commit> | `git reset <commit>` | Mueve la punta de la rama actual hacia atrás hasta <commit>, resetea el área de preparación para que coincida, pero deja el directorio de trabajo solo |
| git reset --hard <commit> | `git reset --hard <commit>` | Igual que el anterior, pero reinicia tanto el área de preparación como el directorio de trabajo para que coincidan. Borra los cambios no comprometidos, y todos los commits posteriores a <commit>. |
### Git Push
| Command | Example | Description |
| ------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| git push <remote> --force | `git push <remote> --force` | Forces the git push even if it results in a non-fast-forward merge. Do not use the --force flag unless youre sure you know what youre doing. |
| git push <remote> --all | `git push <remote> --all` | Push all of your local branches to the specified remote. |
| git push <remote> --tags | `git push <remote> --tags` | Tags arent automatically pushed when you push a branch or use the --all flag. The --tags flag sends all of your local tags to the remote repo. |
| Comando | Ejemplo | Descripción |
| ------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| git push <remote> --force | `git push <remote> --force` | Fuerza el git push incluso si resulta en una fusión no rápida. No uses la opción --force a menos que estés seguro de lo que haces. |
| git push <remote> --all | `git push <remote> --all` | Envía todas tus ramas locales a la remota especificada. |
| git push <remote> --tags | `git push <remote> --tags` | Las etiquetas no se envían automáticamente cuando envías una rama o usas la opción --all. La opción --tags envía todas tus etiquetas locales al repositorio remoto. |
## Resources
## Recursos
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
@ -157,5 +164,13 @@ I have taken these from [atlassian](https://www.atlassian.com/git/tutorials/atla
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
- [En español] [Comandos Git](https://gitea.vergaracarmona.es/man-linux/comandos-git)
- [En español][Apuntes Curso de Git](https://vergaracarmona.es/wp-content/uploads/2022/10/Curso-git_vergaracarmona.es_.pdf) de [Juan Carlos Rubio](https://www.linkedin.com/in/juan-carlos-rubio-pineda/Curso-git_vergaracarmona-es).
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- ["Instalar git en ubuntu"](https://vergaracarmona.es/instalar-git-en-ubuntu/)
- ["Comandos de git"](https://vergaracarmona.es/comandos-de-git/)
- ["Estrategias de fusión en git: Ship / Show / Ask"](https://vergaracarmona.es/estrategias-bifurcacion-git-ship-show-ask/)
- ["Resolver conflictos en Git. Merge, Squash, Rebase o Pull"](https://vergaracarmona.es/merge-squash-rebase-pull/)
- ["Borrar commits de git: reset, rebase y cherry-pick"](https://vergaracarmona.es/reset-rebase-cherry-pick/)
See you on [Day 38](day38.md)
Nos vemos en el [Día 38](day38.md)

View File

@ -1,110 +1,110 @@
## Staging & Changing
## Puesta en marcha (Staging) y cambios de git
We have already covered some of the basics but putting things into a walkthrough makes it better for me to learn and understand how and why we are doing it this way. Before we get into any git-based services such as GitHub, git has its powers that we can take advantage of on our local workstation.
Ya hemos cubierto algunos de los conceptos básicos, pero poner las cosas en un tutorial hace que sea mejor para aprender y entender cómo y por qué lo estamos haciendo de esta manera en concreto. Antes de entrar en cualquier servicio basado en git como GitHub, git tiene superpoderes para aprovechar en local.
We are going to take the project folder we created at the start of the git session and we are going to walk through some of the simple steps we can do with git. We created a folder on our local machine and we initialised it with the `git init` command
Vamos a verlos seleccionando la carpeta del proyecto que creamos al inicio de la sesión de git y veremos algunos de los sencillos y potentes pasos que podemos hacer con git. Creamos una carpeta en nuestra máquina local y la inicializamos con el comando `git init`.
![](Images/Day38_Git1.png)
We can also see now that we have initialised the folder we have a hidden folder in our directory.
También podemos ver que después de inicializar tenemos una carpeta oculta en nuestro directorio: `.git`.
![](Images/Day38_Git2.png)
This is where the details of the git repository are stored as well as the information regarding our branches and commits.
Aquí es donde se almacenan los detalles del repositorio git así como la información relativa a nuestras ramas y commits. ¡Donde habita toda la magía de git!
### Staging Files
### Ficheros Staging
We then start working on our empty folder and maybe we add some source code on the first days of work. We create our readme.mdfile and we can see that file in the directory, next we check our `git status` and it knows about the new readme.mdfile but we have not committed the file yet.
A continuación, empezamos a trabajar en nuestra carpeta vacía. Podemos añadir algo de código fuente de los primeros días de trabajo. Creamos nuestro fichero `readme.md` y comprobamos nuestro `git status`. Veremos el nuevo fichero `readme.md` pero sin confirmar todavía.
![](Images/Day38_Git3.png)
We can stage our readme.mdfile with the `git add README.md` command then we can see changes to be committed that we did not have before and a green new file.
Con el comando `git add README.md` podremos ver en `git status` que el fichero está en verde, esto indica que tenemos los cambios preparados para confirmar.
![](Images/Day38_Git4.png)
Next up we want to commit this, our first commit or our first snapshot of our project. We can do this by using the `git commit -m "Meaningful message"` command so that we can easily see what has changed for each commit. Also, notice the yellow cross changes now to a green tick. This is something I have within my terminal with the theme I use, something we covered in the Linux section.
A continuación vamos confirmar esto, que no quede pendiente, haremos nuestro primer commit o, visto de otra manera, la primera instantánea de nuestro proyecto. Esto lo hacemos con el comando `git commit -m "<Mensaje significativo>"` dejando un mensaje esclarecedor y conciso que describa los cambios que se incluyen a la rama. Además, observe que la cruz amarilla cambia ahora a una marca verde. Esto es algo que tengo dentro de mi terminal con el tema que uso, lo vimos en la sección de Linux.
![](Images/Day38_Git5.png)
### Committing Changes
### Confirmando cambios
We are going to most likely want to add more files or even change the files we have in our directory. We have already done our first commit above. But now we are going to add more details and more files.
O como maldecimos algunos en español "comiteando que es gerundio". Lo más probable es que queramos añadir más archivos o incluso cambiar los archivos que tenemos en nuestro directorio. Ya hemos hecho nuestro primer commit, pero ahora vamos a añadir más y más y más.
We could repeat our process from before, create or edit our file > `git add .` to add all files to the staging area then `git commit -m "meaningful message"` and this would work just fine. But to be able to offer a meaningful message on commit of what has changed you might not want to write something out like `git commit -m "Well, I changed some code because it did not work and when I fixed that I also added something new to the readme.mdto ensure everyone knew about the user experience and then I made a tea."` I mean this would work as well although probably make it descriptive but the preferred way here is to add this with a text editor.
Podríamos repetir nuestro proceso de antes, crear o editar nuestro archivo con `git add .` para añadir todos los archivos a la zona de preparación y luego `git commit -m "mensaje significativo"` y esto funcionaría sin problemas. Pero para ser capaz de ofrecer un mensaje significativo en el commit de lo que ha cambiado puede que no quieras escribir algo como `git commit -m "Bueno, he cambiado algo de código porque no funcionaba y cuando lo arreglé también añadí algo nuevo al readme.mdpara asegurarme de que todo el mundo conocía la experiencia de usuario y luego hice un té."` Quiero decir que esto funcionaría también aunque probablemente lo haría descriptivo pero la forma preferida aquí es añadir esto con un editor de texto.
If we run `git commit` after running `git add` it will open our default text editor which in my case here is nano. Here are the steps I took to add some changes to the file, ran `git status` to show what is and what is not staged. Then I used `git add` to add the file to the staging area, then ran `git commit` which opened nano.
Si ejecutamos `git commit` después de ejecutar `git add` se abrirá nuestro editor de texto por defecto que en mi caso es nano. Estos son los pasos que seguí para añadir algunos cambios al archivo, ejecuté `git status` para mostrar lo que está y lo que no está preparado. Luego usé `git add` para agregar el archivo al área de staging, luego ejecuté `git commit` que abrió nano.
![](Images/Day38_Git6.png)
When nano opens you can then add your short and long description and then save the file.
Cuando se abra nano puedes añadir tu descripción corta y larga y luego guardar el archivo.
![](Images/Day38_Git7.png)
### Committing Best Practices
### Mejores prácticas para el commit
There is a balance here between when to commit and commit often. We do not want to be waiting to be finished the project before committing, each commit should be meaningful and they also should not be coupled with non-relevant tasks with each other. If you have a bug fix and a typo make sure they are two separate commits as a best practice.
Hay un equilibrio entre confirmar empaquetando cambios relacionados y confirmar a menudo. No queremos esperar a terminar un proyecto para nuestro primer commit y cada confirmación debe ser significativa. Tampoco debe estar asociada con tareas no relevantes entre sí. Si tienes una corrección de errores y un error tipográfico la mejor práctica es asegurarse de incluirlos en dos commits distintos. Así puedes abreviar y darle significado al mensaje del commit.
Make the commit message mean something.
En términos de redacción, el equipo o tú mismo deberíais ceñiros a la misma redacción para cada confirmación. Por ejemplo, recomiendan que los mensajes comiencen con un verbo en infinitivo, como "añadir" o "eliminar". Esto ayuda a mantener la consistencia y a que los mensajes sean más fáciles de leer. En muchos proyectos se decide que sean en inglés. También se agradece la brevedad cuando repasas los logs de git 😅
In terms of wording, the team or yourself should be sticking to the same wording for each commit.
### Saltarse la zona de preparación
### Skipping the Staging Area
¿Tenemos que preparar siempre nuestros cambios antes de confirmarlos?
Do we always have to stage our changes before committing them?
La respuesta es sí. Pero no lo veas como un handicap, es la manera de estar 100% seguro de que no vas a errar. Además, la práctica recomendada es evitar utilizar 'git add .' y en su lugar utilizar 'git add <file>' para añadir los cambios del archivo o archivos en concreto para ser más específico y asegurarte de que no estás añadiendo cambios que no quieres. ¿Conoces el dicho "Más vale prevenir que curar"? Pues eso.
The answer is yes but don't see this as a shortcut, you have to be sure 100% that you are not needing that snapshot to roll back to, it is a risky thing to do.
También hay una forma de saltarse la zona de preparación y confirmar directamente con el comando `git commit -a -m "<Mensaje significativo>"`. Es útil cuando tienes un cambio pequeño y no quieres tener que pasar por el proceso de preparación y confirmación. Pero cuidadito, si tienes muchos cambios y no los has preparado, esto podría añadirlos todos a la confirmación.
![](Images/Day38_Git8.png)
### Removing Files
### Eliminación de archivos
What about removing files from our project, maybe we have another file in our directory that we have committed but now the project no longer needs or using it, as a best practice we should remove it.
Qué pasa con la eliminación de archivos de nuestro proyecto, tal vez tenemos otro archivo en nuestro directorio que hemos confirmado, pero ahora el proyecto ya no lo necesita o utiliza, como una mejor práctica debemos eliminarlo.
Just because we remove the file from the directory, git is still aware of this file and we also need to remove it from the repository. You can see the workflow for this below.
Sólo porque eliminamos el archivo del directorio, git todavía es consciente de este archivo y también tenemos que eliminarlo del repositorio. Puedes ver el flujo de trabajo para esto a continuación.
![](Images/Day38_Git9.png)
That could be a bit of a pain to either remember or have to deal with if you have a large project which has many moving files and folders. We can do this with one command with `git rm oldcode.ps1`
Esto podría ser un poco molesto de recordar o tener que lidiar con ello si tienes un proyecto grande que tiene muchos archivos y carpetas en movimiento. Podemos hacer esto con un comando con `git rm oldcode.ps1`.
![](Images/Day38_Git10.png)
### Renaming or Moving Files
### Renombrar o Mover Archivos
Within our operating system, we can rename and move our files. We will no doubt need to do this from time to time with our projects. Similar to removing though there is a two-step process, we change our files on our OS and then we have to modify and make sure that the staging area or that the files are added correctly. Steps as follows:
Dentro de nuestro sistema operativo podemos renombrar y mover nuestros archivos. Sin duda necesitaremos hacer esto de vez en cuando con nuestros proyectos. Similar a eliminar aunque hay un proceso de dos pasos, cambiamos nuestros archivos en nuestro sistema operativo y luego tenemos que modificar y asegurarnos de que la zona de montaje o que los archivos se añaden correctamente. Los pasos son los siguientes:
![](Images/Day38_Git11.png)
However, like removing files from the operating system and then the git repository we can perform this rename using a git command too.
Sin embargo, al igual que eliminamos archivos del sistema operativo y luego del repositorio git podemos realizar este renombrado utilizando también un comando git.
![](Images/Day38_Git12.png)
### Ignoring Files
### Ignorando Archivos
We may have the requirement to ignore files or folders within our project that we might be using locally or that will be just wasted space if we were to share with the overall project, a good example of this could be logs. I also think using this for secrets that you do not want to be shared out in public or across teams.
Podemos tener la necesidad de ignorar los archivos o carpetas dentro de nuestro proyecto que podríamos estar utilizando a nivel local o que sólo sería un desperdicio de espacio si tuviéramos que compartir con el proyecto en general, un buen ejemplo de esto podría ser registros. También creo que el uso de este para los secretos que no quieren ser compartidos en público o entre los equipos.
We can ignore files by adding folders or files to the `.gitignore` file in our project directory.
Podemos ignorar archivos añadiendo carpetas o archivos al archivo `.gitignore` en el directorio de nuestro proyecto.
![](Images/Day38_Git13.png)
You can then open the `.gitignore` file and see that we have the logs/ directory present. But we could also add additional files and folders here to ignore.
Podemos abrir el archivo `.gitignore` y ver que tenemos el directorio logs/ presente. Pero también podríamos añadir aquí archivos y carpetas adicionales para ignorar.
![](Images/Day38_Git14.png)
We can then see `git status` and then see what has happened.
A continuación podemos ver `git status` y ver qué ha pasado.
![](Images/Day38_Git15.png)
There are also ways in which you might need to go back and ignore files and folders, maybe you did want to share the logs folder but then later realised that you didn't want to. You will have to use `git rm --cached ` to remove files and folders from the staging area if you have a previously tracked folder that you now want to ignore.
También hay formas en las que podrías necesitar volver atrás e ignorar archivos y carpetas, quizás querías compartir la carpeta de logs pero luego te diste cuenta de que no querías hacerlo. Tendrás que usar `git rm --cached ` para eliminar archivos y carpetas del área de preparación si tienes una carpeta previamente rastreada que ahora quieres ignorar.
### Short Status
### Estado breve
We have been using `git status` a lot to understand what we have in our staging area and what we do not, it's a very comprehensive command with lots of detail. Most of the time you will just want to know what has been modified or what is new? We can use `git status -s` for a short status of this detail. I would usually set an alias on my system to just use `git status -s` vs the more detailed command.
Hemos estado usando mucho `git status` para entender lo que tenemos en nuestra área de preparación y lo que no, es un comando muy completo con muchos detalles. La mayoría de las veces sólo querrás saber qué ha sido modificado o qué hay de nuevo. Podemos usar `git status -s` para un breve estado de este detalle. Yo normalmente establecería un alias en mi sistema para usar `git status -s` en lugar del comando más detallado.
![](Images/Day38_Git16.png)
In the post tomorrow we will continue to look through these short examples of these common git commands.
En el post de mañana seguiremos viendo estos breves ejemplos de estos comandos comunes de git.
## Resources
## Recursos
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
@ -113,5 +113,14 @@ In the post tomorrow we will continue to look through these short examples of th
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
- [En español] [Comandos Git](https://gitea.vergaracarmona.es/man-linux/comandos-git)
- [En español][Apuntes Curso de Git](https://vergaracarmona.es/wp-content/uploads/2022/10/Curso-git_vergaracarmona.es_.pdf) de [Juan Carlos Rubio](https://www.linkedin.com/in/juan-carlos-rubio-pineda/Curso-git_vergaracarmona-es).
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- ["Instalar git en ubuntu"](https://vergaracarmona.es/instalar-git-en-ubuntu/)
- ["Comandos de git"](https://vergaracarmona.es/comandos-de-git/)
- ["Estrategias de fusión en git: Ship / Show / Ask"](https://vergaracarmona.es/estrategias-bifurcacion-git-ship-show-ask/)
- ["Resolver conflictos en Git. Merge, Squash, Rebase o Pull"](https://vergaracarmona.es/merge-squash-rebase-pull/)
- ["Borrar commits de git: reset, rebase y cherry-pick"](https://vergaracarmona.es/reset-rebase-cherry-pick/)
- [Ejemplos README.md para tus proyectos](https://gitea.vergaracarmona.es/manuelver/plantillas-README)
See you on [Day 39](day39.md)
Nos vemos en el [Día 39](day39.md).

View File

@ -1,194 +1,190 @@
## Viewing, unstaging, discarding & restoring
## Visualización, desescalado, descarte y restauración
Continuing from where we finished yesterday around some of the commands that we have with git and how to leverage git with your projects. Remember we have not touched GitHub or any other git-based services yet this is all to help you keep control of your projects locally at the moment, but they will all become useful when we start to integrate into those tools.
Vamos a continuar donde lo dejamos ayer en torno a algunos de los comandos que tenemos con git y cómo aprovechar git con sus proyectos. Recuerde que no hemos tocado GitHub o cualquier otro servicio basado en git todavía, estamos viendo como mantener el control de los proyectos a nivel local por el momento, pero todos ellos serán útiles cuando empezamos a integrar esas herramientas.
### Viewing the Staged and Unstaged Changes
### Viendo los Cambios Staged y Unstaged
It is good practice to make sure you view the staged and unstaged code before committing. We can do this by running the `git diff --staged` command
Es una buena práctica asegurarse de ver el código preparado y no preparado antes de confirmar. Podemos hacerlo ejecutando el comando `git diff --staged`
![](Images/Day39_Git1.png)
This then shows us all the changes we have made and all new files we have added or deleted.
Esto nos muestra todos los cambios que hemos hecho y todos los archivos nuevos que hemos añadido o borrado.
changes in the modified files are indicated with `---` or `+++` you can see below that we just added +add some text below which means they are new lines.
Los cambios en los archivos modificados se indican con `---` o `+++` puedes ver abajo que acabamos de añadir +añadir algo de texto debajo lo que significa que son nuevas líneas.
![](Images/Day39_Git2.png)
We can also run `git diff` to compare our staging area with our working directory. If we make some changes to our newly added file code.txt and add some lines of text.
También podemos ejecutar `git diff` para comparar nuestra área de staging con nuestro directorio de trabajo. Si hacemos algunos cambios en nuestro archivo recién añadido code.txt y añadimos algunas líneas de texto.
![](Images/Day39_Git3.png)
If we then run `git diff` we compare and see the output below.
Si luego ejecutamos `git diff` comparamos y vemos la salida de abajo.
![](Images/Day39_Git4.png)
### Visual Diff Tools
### Herramientas visuales Diff
For me, the above is more confusing so I would much rather use a visual tool,
To name a few visual diff tools:
Para mí, lo anterior es algo confuso, así que prefiero utilizar una herramienta visual. Por nombrar algunas de ellas:
- KDiff3
- P4Merge
- WinMerge (Windows Only)
- WinMerge (Sólo Windows)
- VSCode
To set this in git we run the following command `git config --global diff.tool vscode`
Para configurar esto en git ejecutamos el siguiente comando `git config --global diff.tool vscode`.
We are going to run the above and we are going to set some parameters when we launch VScode.
Vamos a ejecutar lo anterior y vamos a establecer algunos parámetros cuando lancemos VScode.
![](Images/Day39_Git5.png)
We can also check our configuration with `git config --global -e`
También podemos comprobar nuestra configuración con `git config --global -e`.
![](Images/Day39_Git6.png)
We can then use `git difftool` to now open our diff visual tool.
Podemos usar `git difftool` para abrir nuestra herramienta visual diff.
![](Images/Day39_Git7.png)
Which then opens our VScode editor on the diff page and compares the two, we have only modified one file from nothing to now adding a line of code on the right side.
Esto abre nuestro editor VScode en la página diff y compara los dos. Veremos que sólo hemos modificado un archivo añadiendo una línea de código en el lado derecho.
![](Images/Day39_Git8.png)
I find this method much easier to track changes and this is something similar to what we will see when we look into git-based services such as GitHub.
Encuentro este método mucho más fácil para rastrear cambios y es algo similar a lo que veremos cuando busquemos en servicios basados en git como GitHub.
We can also use `git difftool --staged` to compare stage with committed files.
También podemos usar `git difftool --staged` para comparar el stage con los archivos confirmados.
![](Images/Day39_Git9.png)
Then we can cycle through our changed files before we commit.
Entonces podemos ver el ciclo a través de nuestros archivos cambiados antes de confirmar.
![](Images/Day39_Git10.png)
I am using VScode as my IDE and like most IDEs they have this functionality built in it is very rare you would need to run these commands from the terminal, although helpful if you don't have an IDE installed for some reason.
Estoy usando VScode como mi IDE y como la mayoría de los IDEs tienen esta funcionalidad incorporada. Es muy raro que necesites ejecutar estos comandos desde la terminal, aunque es útil si no tienes un IDE instalado por alguna razón.
### Viewing the History
### Viendo el Historial
We previously touched on `git log` which will provide us with a comprehensive view of all commits we have made in our repository.
Anteriormente hemos tocado `git log` que nos proporcionará una visión completa de todos los commits que hemos hecho en nuestro repositorio.
![](Images/Day39_Git11.png)
Each commit has its hexadecimal string, unique to the repository. Here you can see which branch we are working on and then also the author, date and commit message.
Cada commit tiene su cadena hexadecimal, única para el repositorio. Aquí puedes ver en qué rama estamos trabajando y también el autor, la fecha y el mensaje de confirmación.
We also have `git log --oneline` and this gives us a much smaller version of the hexadecimal string which we can use in other `diff` commands. We also only have the one-line description or commit message.
También tenemos `git log --oneline` que nos devuelve una versión mucho más pequeña de la cadena hexadecimal que podemos usar en otros comandos `diff`. También tenemos sólo la descripción de una línea o el mensaje de commit.
![](Images/Day39_Git12.png)
We can reverse this into a start with the first commit by running `git log --oneline --reverse` and now we see our first commit at the top of our page.
Podemos revertir esto en un inicio con el primer commit ejecutando `git log --oneline --reverse` y ahora vemos nuestro primer commit en la parte superior de nuestra página.
![](Images/Day39_Git13.png)
### Viewing a Commit
### Ver un commit
Being able to look at the commit message is great if you have been conscious about following best practices and you have added a meaningful commit message, however, there is also `git show` command which allows us to inspect and view a commit.
We can use `git log --oneline --reverse` to get a list of our commits. and then we can take those and run `git show <commit ID>`
Ser capaz de mirar el mensaje de confirmación es genial si has sido consciente de seguir las mejores prácticas y has añadido un mensaje de confirmación significativo, sin embargo, también existe el comando `git show` si queremos inspeccionar un commit concreto. Podemos utilizar `git log --oneline --reverse` para obtener una lista de nuestros commits. y luego podemos tomarlos y ejecutar `git show <commit ID>`.
![](Images/Day39_Git14.png)
The output of that command will look like below with the detail of the commit, author and what changed.
La salida de ese comando se verá como abajo con el detalle del commit, autor y lo que cambió.
![](Images/Day39_Git15.png)
We can also use `git show HEAD~1` where 1 is how many steps back from the current version we want to get back to.
También podemos usar `git show HEAD~1` donde 1 es el número de pasos hacia atrás desde la versión actual a la que queremos volver.
This is great if you want some detail on your files, but if we want to list all the files in a tree for the whole snapshot directory. We can achieve this by using the `git ls-tree HEAD~1` command, again going back one snapshot from the last commit. We can see below we have two blobs, these indicate files whereas the tree would indicate a directory. You can also see commits and tags in this information.
Esto es genial si queremos algún detalle de nuestros archivos, pero si queremos listar todos los archivos de un árbol para todo el directorio de la instantánea. Podemos conseguirlo usando el comando `git ls-tree HEAD~1`, de nuevo retrocediendo una instantánea desde el último commit. Podemos ver abajo que tenemos dos blobs, estos indican archivos mientras que el árbol indicaría un directorio. También puedes ver commits y tags en esta información.
![](Images/Day39_Git16.png)
We can then use the above to drill in and see the contents of our file (blobs) using the `git show` command.
Podemos usar lo anterior para ver el contenido de nuestro archivo (blobs) usando el comando `git show`.
![](Images/Day39_Git17.png)
Then the contents of that specific version of the file will be shown.
Entonces se mostrará el contenido de esa versión específica del archivo.
![](Images/Day39_Git18.png)
### Unstaging Files
### Unstaging archivos
There will be a time when you have maybe used `git add .` but there are files you do not wish to commit to that snapshot just yet. In this example below I have added newfile.txt to my staging area but I am not ready to commit this file so I am going to use the `git restore --staged newfile.txt` to undo the `git add` step.
Habrá un momento en el que quizás haya usado `git add .` pero hay archivos que no desea confirmar en esa instantánea todavía. En este ejemplo he añadido newfile.txt a mi área de staging pero no estoy listo para confirmar este archivo así que voy a usar `git restore --staged newfile.txt` para deshacer el paso `git add`.
![](Images/Day39_Git19.png)
We can also do the same to modified files such as main.js and unstage the commit, see above we have a greem M for modified and then below we are unstaging those changes.
También podemos hacer lo mismo con archivos modificados como main.js y deshacer el commit, mira arriba tenemos una M en verde y abajo hemos deshecho esos cambios.
![](Images/Day39_Git20.png)
I have found this command quite useful during the 90DaysOfDevOps as I sometimes work ahead of the days where I feel I want to make notes for the following day but I don't want to commit and push to the public GitHub repository.
He encontrado este comando bastante útil durante los 90DaysOfDevOps ya que a veces trabajo antes de los días en los que siento que quiero hacer anotaciones para el día siguiente pero no quiero hacer commit y push al repositorio público de GitHub.
### Discarding Local Changes
### Descartando Cambios Locales
Sometimes we might make changes but we are not happy with those changes and we want to throw them away. We are going to use the `git restore` command again and we are going to be able to restore files from our snapshots or previous versions. We can run `git restore .` against our directory and we will restore everything from our snapshot but notice that our untracked file is still present. There is no previous file being tracked called newfile.txt.
A veces podemos hacer cambios pero no estamos contentos con esos cambios y queremos desecharlos. Vamos a utilizar el comando `git restore` de nuevo y vamos a poder restaurar archivos de nuestras snapshots o versiones anteriores. Podemos ejecutar `git restore .` contra nuestro directorio y restauraremos todo desde nuestra instantánea, pero observa que nuestro archivo no rastreado sigue presente. No hay ningún archivo anterior siendo rastreado llamado newfile.txt.
![](Images/Day39_Git21.png)
Now to remove newfile.txt or any untracked files. We can use `git clean` we will get a warning alone.
Ahora para eliminar newfile.txt o cualquier archivo no rastreado. Podemos usar `git clean` solo obtendremos una advertencia.
![](Images/Day39_Git22.png)
Or if we know the consequences then we might want to run `git clean -fd` to force and remove all directories.
O si conocemos las consecuencias podemos ejecutar `git clean -fd` para forzar y eliminar todos los directorios.
![](Images/Day39_Git23.png)
### Restoring a File to an Earlier Version
### Restaurar un archivo a una versión anterior
As we have alluded to throughout a big portion of what Git can help with is being able to restore copies of your files from your snapshots (this is not a backup but it is a very fast restore point) My advice is that you also save copies of your code in other locations using a backup solution for this.
Como hemos aludido, lo que Git nos puede ayudar es a restaurar copias de tus archivos desde tus instantáneas (esto no es una copia de seguridad, pero es un punto de restauración muy rápido). Es recomendable que también guardes copias de tu código en otros lugares utilizando una solución de copia de seguridad expresamente para esto.
As an example let's go and delete our most important file in our directory, notice we are using Unix-based commands to remove this from the directory, not git commands.
Como ejemplo vamos a borrar nuestro archivo más importante en nuestro directorio, pero utilizando comandos basados en Unix para eliminar el directorio, no comandos de git.
![](Images/Day39_Git24.png)
Now we have no readme.mdin our working directory. We could have used `git rm readme.md` and this would then be reflected in our git database. Let's also delete it from here to simulate it being removed completely.
Ahora no tenemos readme.md en nuestro directorio de trabajo. Podríamos haber usado `git rm readme.md` y esto se reflejaría en nuestra base de datos de git. Así que lo borramos también así para simular la eliminación por completo.
![](Images/Day39_Git25.png)
Let's now commit this with a message and prove that we no longer have anything in our working directory or staging area.
Ahora confirmemos esto con un mensaje y probemos que ya no tenemos nada en nuestro directorio de trabajo o área de preparación.
![](Images/Day39_Git26.png)
Mistakes were made and we now need this file back!
¡Se cometieron errores y ahora necesitamos recuperar ese archivo! 😱
We could use the `git undo` command which will undo the last commit, but what if it was a while back? We can use our `git log` command to find our commits and then we find that our file is in the last commit but we don't all of those commits to be undone so we can then use this command `git restore --source=HEAD~1 README.md` to specifically find the file and restore it from our snapshot.
Podríamos usar el comando `git undo` que deshará el último commit, pero ¿qué pasa si fue hace tiempo? Podemos usar nuestro comando `git log` para encontrar el commit concreto pero no queremos que todos los commits que haya por el medio se deshagan, así que vamos a especificar el fichero con el comando `git restore --source=HEAD~1 README.md` y restaurarlo desde nuestro snapshot.
You can see using this process we now have the file back in our working directory.
Puedes ver que usando este proceso ahora tenemos el archivo de vuelta en nuestro directorio de trabajo 😅
![](Images/Day39_Git27.png)
We now have a new untracked file and we can use our commands previously mentioned to track, stage and commit our files and changes.
Ahora tenemos un nuevo archivo no rastreado y podemos usar los comandos mencionados anteriormente para rastrear, preparar y comitear nuestros cambios.
### Rebase vs Merge
This seems to be the biggest headache when it comes to Git and when to use rebase vs using merge on your git repositories.
Este parece ser el mayor dolor de cabeza cuando se trata de Git, cuando usar rebase o merge en tus repositorios git.
The first thing to know is that both `git rebase` and `git merge` solve the same problem. Both are to integrate changes from one branch into another branch. However, they do this in different ways.
Lo primero que hay que saber es que tanto `git rebase` como `git merge` resuelven el mismo problema. Ambos sirven para integrar cambios de una rama en otra rama. Sin embargo, lo hacen de formas diferentes.
Let's start with a new feature in a new dedicated branch. The Main branch continues with new commits.
Empecemos con una nueva característica en una nueva rama dedicada. La rama principal continúa con nuevos commits.
![](Images/Day39_Git28.png)
The easy option here is to use `git merge feature main` which will merge the main branch into the feature branch.
La opción fácil es usar `git merge feature main` que fusionará la rama principal en la rama feature.
![](Images/Day39_Git29.png)
Merging is easy because it is non-destructive. The existing branches are not changed in any way. However, this also means that the feature branch will have an irrelevant merge commit every time you need to incorporate upstream changes. If the main is very busy or active this will or can pollute the feature branch history.
La fusión es fácil porque no es destructiva. Las ramas existentes no se modifican. Sin embargo, esto también significa que la rama principal tendrá un commit de fusión irrelevante cada vez que necesites incorporar cambios de la rama principal. Si la main está muy ocupada o activa esto podría contaminar el historial de la rama feature.
As an alternate option, we can rebase the feature branch onto the main branch using
Como opción alternativa, podemos volver a basar la rama de características en la rama principal utilizando:
```
git checkout feature
git rebase main
```
This moves the feature branch (the entire feature branch) effectively incorporating all of the new commits in the main. But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.
Esto mueve la rama feature (toda la rama feature) incorporando efectivamente todos los nuevos commits en la main. Pero, en lugar de usar un commit merge, rebasing reescribe la historia del proyecto creando nuevos commits para cada commit en la rama original.
![](Images/Day39_Git30.png)
The biggest benefit of rebasing is a much cleaner project history. It also eliminates unnecessary merge commits. and as you compare the last two images, you can follow arguably a much cleaner linear project history.
El mayor beneficio de rebase es un historial del proyecto mucho más limpio. También elimina commits de fusión innecesarios. Si comparas las dos últimas imágenes, puedes seguir una historia del proyecto lineal mucho más limpia.
Although it's still not a foregone conclusion, choosing the cleaner history also comes with tradeoffs, If you do not follow the [The Golden rule of rebasing](https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing) re-writing project history can be potentially catastrophic for your collaboration workflow. And, less importantly, rebasing loses the context provided by a merge commit—you cant see when upstream changes were incorporated into the feature.
Aunque todavía no es una conclusión inevitable, la elección del historial más limpio también viene con desventajas, si no sigues [La regla de oro de rebasing](hhttps://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing) y vuelves a escribir el historial del proyecto puede ser potencialmente catastrófico para su flujo de trabajo de colaboración. Y por otro lado, con menos importancia pero también presente, al realizar rebase se pierde el contexto proporcionado por un commit de fusión: no puedes ver cuándo se incorporaron realmente los cambios de la línea ascendente en la feature.
## Resources
## Recursos
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
@ -198,5 +194,13 @@ Although it's still not a foregone conclusion, choosing the cleaner history also
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
- [Exploring the Git command line A getting started guide](https://veducate.co.uk/exploring-the-git-command-line/)
- [En español] [Comandos Git](https://gitea.vergaracarmona.es/man-linux/comandos-git)
- [En español][Apuntes Curso de Git](https://vergaracarmona.es/wp-content/uploads/2022/10/Curso-git_vergaracarmona.es_.pdf) de [Juan Carlos Rubio](https://www.linkedin.com/in/juan-carlos-rubio-pineda/Curso-git_vergaracarmona-es).
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- ["Instalar git en ubuntu"](https://vergaracarmona.es/instalar-git-en-ubuntu/)
- ["Comandos de git"](https://vergaracarmona.es/comandos-de-git/)
- ["Estrategias de fusión en git: Ship / Show / Ask"](https://vergaracarmona.es/estrategias-bifurcacion-git-ship-show-ask/)
- ["Resolver conflictos en Git. Merge, Squash, Rebase o Pull"](https://vergaracarmona.es/merge-squash-rebase-pull/)
- ["Borrar commits de git: reset, rebase y cherry-pick"](https://vergaracarmona.es/reset-rebase-cherry-pick/)
See you on [Day40](day40.md)
Nos vemos en el [Día 40](day40.md)

View File

@ -1,191 +1,195 @@
## Social Network for code
## Red social para el código
Exploring GitHub | GitLab | BitBucket
Explorando GitHub | GitLab | BitBucket 🚀
Today I want to cover some of the git-based services that we have likely all heard of and expect we also use daily.
Hoy veremos algunos de los servicios basados en git de los que probablemente hemos oído hablar. Utilizaremos algunos de nuestros conocimientos adquiridos para mover copias de nuestros datos a cada uno de los principales servicios.
We will then use some of our prior session knowledge to move copies of our data to each of the main services.
I called this section "Social Network for Code" let me explain why?
He llamado a esta sección "Red Social para el Código", ya verás por qué...
### GitHub
Most common at least for me is GitHub, GitHub is a web-based hosting service for git. It is most commonly used by software developers to store their code. Source Code Management with the git version control features as well as a lot of additional features. It allows for teams or open contributors to easily communicate and provides a social aspect to coding. (hence the social networking title) Since 2018 GitHub is part of Microsoft.
El más común es GitHub, un servicio de alojamiento basado en web para git. Es muy utilizado por los desarrolladores de software para almacenar código. Tienes la gestión del código fuente centralizada en un repositorio remoto y distribuida gracias a las características de control de versiones git, así como un montón de características adicionales. Permite a los equipos y colaboradores comunicarse fácilmente y proporciona un aspecto social a la codificación. Desde 2018 GitHub forma parte de Microsoft (A golpe de talonario).
GitHub has been around for quite some time and was founded in 2007/2008. With Over 40 million users on the platform today.
GitHub fue fundada en 2007/2008. Con Más de 40 millones de usuarios en la plataforma a día de hoy.
GitHub Main Features
Características principales de GitHub
- Code Repository
- Pull Requests
- Project Management toolset - Issues
- CI / CD Pipeline - GitHub Actions
- Repositorio de código
- Solicitudes de Pull
- Herramientas de gestión de proyectos - Issues
- Canalización CI / CD - Acciones GitHub
In terms of pricing, GitHub has different levels of pricing for its users. More can be found on [Pricing](https://github.com/pricing)
En términos de precios, GitHub tiene diferentes niveles de precios para sus usuarios. Puedes encontrar más información en [Pricing](https://github.com/pricing)
For this, we will cover the free tier.
Aquí veremos tan solo el nivel gratuito.
I am going to be using my already created GitHub account during this walkthrough, if you do not have an account then on the opening GitHub page there is a sign-up option and some easy steps to get set up.
Voy a utilizar mi cuenta de GitHub ya creada durante este tutorial, si no tienes una cuenta, en la página de apertura de GitHub hay una opción de registro y algunos pasos sencillos para configurarla.
### GitHub opening page
### Página de inicio de GitHub
When you first log in to your GitHub account you get a page containing a lot of widgets giving you options of where and what you would like to see or do. First up we have the "All Activity" this is going to give you a look into what is happening with your repositories or activity in general associated with your organisation or account.
La primera vez que accedes a tu cuenta de GitHub aparece una página que contiene un montón de widgets que te dan opciones de dónde y qué te gustaría ver o hacer. En primer lugar tenemos "Toda la actividad", que te dará una visión de lo que está sucediendo con tus repositorios o actividad en general asociada a tu organización o cuenta.
![](Images/Day40_Git1.png)
Next, we have our Code Repositories, either our own or repositories that we have interacted with recently. We can also quickly create new repositories or search repositories.
A continuación, tenemos nuestros repositorios de código, ya sean propios o repositorios con los que hemos interactuado recientemente. También podemos crear rápidamente nuevos repositorios o buscar repositorios.
![](Images/Day40_Git2.png)
We then have our recent activity, these for me are issues and pull requests that I have created or contributed to recently.
Luego tenemos nuestra actividad reciente, que para mí son temas y pull requests que he creado o contribuido recientemente.
![](Images/Day40_Git3.png)
Over on the right side of the page, we have some referrals for repositories that we might be interested in, most likely based on your recent activity or own projects.
En la parte derecha tenemos algunas referencias de repositorios en los que podríamos estar interesados, probablemente basados en tu actividad reciente o en tus propios proyectos.
![](Images/Day40_Git4.png)
To be honest I am very rarely on my home page that we just saw and described, although I now see that the feed could be really useful to help interact with the community a little better on certain projects.
Para ser honesto no suelo entrar en mi propia página de inicio, veo que el feed podría ser realmente útil para ayudar a interactuar mejor con la comunidad en ciertos proyectos.
Next up if we want to head into our GitHub Profile we can navigate to the top right corner and on your image, there is a drop-down which allows you to navigate through your account. From here to access your Profile select "Your Profile"
A continuación, si queremos entrar en nuestro perfil de GitHub podemos navegar a la esquina superior derecha y en tu imagen, hay un desplegable que te permite navegar a través de tu cuenta. Desde aquí para acceder a tu Perfil selecciona "Tu Perfil"
![](Images/Day40_Git5.png)
Next, your profile page will appear, by default, unless you change your configuration you are not going to see what I have, I have added some functionality that shows my recent blog posts over on [vZilla](https://vzilla.co.uk) and then also my latest videos on my [YouTube](https://m.youtube.com/c/MichaelCade1) Channel.
A continuación, aparecerá tu página de perfil, por defecto, a menos que cambies tu configuración no vas a ver lo que yo tengo, he añadido alguna funcionalidad que muestra mis últimas entradas de blog en [vZilla](https://vzilla.co.uk) y también mis últimos vídeos en mi canal de [YouTube](https://m.youtube.com/c/MichaelCade1) Channel.
You are not going to be spending much time looking at your profile, but this is a good profile page to share around your network so they can see the cool projects you are working on.
No vas a pasar mucho tiempo mirando tu perfil, pero esta es una buena página de perfil para compartir en tu red para que puedan ver los proyectos interesantes en los que estás trabajando.
Si quieres ver algunos ejemplos de páginas de inicio:
- Página del autor [Michael Cade](https://github.com/MichaelCade/MichaelCade)
- Página del traductor [manuelver](https://github.com/manuelver/manuelver)
![](Images/Day40_Git6.png)
We can then drill down into the building block of GitHub, the repositories. Here you are going to see your repositories and if you have private repositories they are also going to be shown in this long list.
A continuación, podemos profundizar en el bloque de construcción de GitHub, los repositorios. Aquí vas a ver tus repositorios y si tienes repositorios privados también se mostrarán en esta larga lista.
![](Images/Day40_Git7.png)
As the repository is so important to GitHub let me choose a pretty busy one of late and run through some of the core functionality that we can use here on top of everything I am already using when it comes to editing our "code" in git on my local system.
El repositorio es muy importante en GitHub, así que elijo uno bastante movido últimamente para ejecutar algunas de las funciones básicas que podemos utilizar.
First of all, from the previous window, I have selected the 90DaysOfDevOps repository and we get to see this view. You can see from this view we have a lot of information, we have our main code structure in the middle showing our files and folders that are stored in our repository. We have our readme. mdbeing displayed down at the bottom. Over to the right of the page, we have an about section where the repository has a description and purpose. Then we have a lot of information underneath this showing how many people have starred in the project, forked, and watched.
Desde la ventana anterior, he seleccionado el repositorio 90DaysOfDevOps. Se puede ver en esta vista que tenemos una gran cantidad de información, tenemos nuestra estructura de código principal en el centro mostrando nuestros archivos y carpetas que se almacenan en nuestro repositorio. Tenemos nuestro readme.md que se muestra en la parte inferior y le da más importancia al fichero, ya que es nuestra presentación del proyecto. A la derecha de la página, tenemos una sección con una descripción y propósito del proyecto. Luego tenemos un montón de información debajo de esto que muestra cuántas personas han destacado en el proyecto con una star, cuántas lo han visto y cuántas lo han bifurcado.
![](Images/Day40_Git8.png)
If we scroll down a little further you will also see that we have Released, these are from the golang part of the challenge. We do not have any packages in our project, we have our contributors listed here. (Thank you community for assisting in my spelling and fact checking) We then have languages used again these are from different sections in the challenge.
Si nos desplazamos un poco más abajo también veremos que tenemos Releases, estos son de la parte golang del desafío. No tenemos ningún paquete en nuestro proyecto en este momento, y también vemos a nuestros colaboradores listados. (Gracias comunidad por ayudar en mi ortografía y otras correcciones) Luego tenemos lenguajes utilizados.
![](Images/Day40_Git9.png)
A the top of the page you are going to see a list of tabs. These may vary and these can be modified to only show the ones you require. You will see here that I am not using all of these and I should remove them to make sure my whole repository is tidy.
En la parte superior de la página verás una lista de pestañas. Éstas pueden variar y pueden modificarse para mostrar sólo las que necesites. Aquí verás que no estoy usando todas y que debería quitarlas para asegurarme de que todo mi repositorio está ordenado y limpio.
First up we had the code tab which we just discussed but these tabs are always available when navigating through a repository which is super useful so we can jump between sections quickly and easily. Next, we have the issues tab.
En primer lugar tenemos la pestaña de código, de la que acabamos de hablar, pero estas pestañas están siempre disponibles cuando se navega a través de un repositorio, lo que es muy útil para que podamos saltar entre las secciones de forma rápida y sencilla. A continuación, tenemos la pestaña de problemas.
Issues let you track your work on GitHub, where development happens. In this specific repository you can see I have some issues focused on adding diagrams or typos but also we have an issue stating a need or requirement for a Chinese version of the repository.
Las incidencias te permiten hacer un seguimiento de tu trabajo en GitHub, donde tiene lugar el desarrollo. En este repositorio específico se puede ver que tengo algunas cuestiones centradas en la adición de diagramas o errores tipográficos, pero también tenemos una cuestión que indica una necesidad o requisito para una versión china del repositorio.
If this was a code repository then this is a great place to raise concerns or issues with the maintainers, but remember to be mindful and detailed about what you are reporting, and give as much detail as possible.
Si esto fuera un repositorio de código, entonces este es un gran lugar para plantear inquietudes o problemas con los mantenedores, pero recuerde que debe ser consciente y detallado acerca de lo que está informando, y dar tantos detalles como sea posible.
![](Images/Day40_Git10.png)
The next tab is Pull Requests, Pull requests let you tell others about changes you've pushed to a branch in a repository. This is where someone may have forked your repository, made changes such as bug fixes or feature enhancements or just typos in a lot of the cases in this repository.
La siguiente pestaña es Pull Requests. Permite informar a otros sobre los cambios que ha empujado a una rama en un repositorio. Aquí es donde alguien puede haber bifurcado el repositorio en otra rama, sea del mismo proyecto o de un fork, ha hecho cambios como correcciones de errores o mejoras de características o simplemente errores tipográficos, y luego ha solicitado que se fusionen esos cambios en la rama principal del proyecto.
We will cover forking later on.
Cubriremos el forking con más detalle más adelante.
![](Images/Day40_Git11.png)
I believe the next tab is quite new? But I thought for a project like #90DaysOfDevOps this could help guide the content journey but also help the community as they walk through their learning journey. I have created some discussion groups for each section of the challenge so people can jump in and discuss.
La siguiente pestaña es bastante nueva, pero se ha creado para #90DaysOfDevOps porque no solo puede ayudar a guiar en el viaje por el contenido, sino que también ayuda a la comunidad a medida que caminan a través de su aprendizaje. Dentro hay grupos de discusión para cada sección del desafío para que quien quiera pueda entrar y comentar, a modo de foro.
![](Images/Day40_Git12.png)
The Actions tab is going to enable you to build, test and deploy code and a lot more right from within GitHub. GitHub Actions will be something we cover in the CI/CD section of the challenge but this is where we can set some configuration here to automate steps for us.
La pestaña de Actions te permitirá construir, probar, desplegar código y mucho más. GitHub Actions lo veremos en la sección de CI/CD del desafío. Como info previa, es aquí donde podemos establecer automatizaciones de tareas repetitivas para que se hagan por si solas con un disparador.
On my main GitHub Profile, I am using GitHub Actions to fetch the latest blog posts and YouTube videos to keep things up to date on that home screen.
Por ejemplo, en mi perfil principal de GitHub utilizo las Actions para obtener las últimas entradas del blog y vídeos de YouTube y mantener al día mi página de perfil Github.
![](Images/Day40_Git13.png)
I mentioned above how GitHub is not just a source code repository but is also a project management tool, The Project tab enables us to build out project tables kanban type boards so that we can link issues and PRs to better collaborate on the project and have visibility of those tasks.
Ya he mencionado que GitHub no es sólo un repositorio de código fuente, sino también una herramienta de gestión de proyectos. La pestaña Projects nos permite crear tablas de proyecto tipo kanban para que podamos vincular las incidencias y PRs para colaborar mejor en el proyecto y tener visibilidad/transparencia de las tareas.
![](Images/Day40_Git14.png)
I know that issues to me seem like a good place to log feature requests and they are but the wiki page allows for a comprehensive roadmap for the project to be outlined with the current status and in general better document your project is it troubleshooting or how-to type content.
La página wiki permite una hoja de ruta completa para el proyecto que se describe con el estado actual y, en general, documentar mejor el proyecto.
![](Images/Day40_Git15.png)
Not so applicable to this project but the Security tab is there to make sure that contributors know how to deal with certain tasks, we can define a policy here but also code scanning add-ons to make sure your code for example does not contain secret environment variables.
No es tan aplicable a este proyecto, pero la pestaña de Security está ahí para asegurarse de que los contribuyentes saben cómo hacer frente a ciertas tareas, podemos definir una política aquí, pero también complementos de escaneo de código para asegurarse de que su código, por ejemplo, no contiene variables de entorno con contraseñas.
![](Images/Day40_Git16.png)
For me the insights tab is great, it provides so much information about the repository from how much activity has been going on down to commits and issues, but it also reports on traffic to the repository. You can see a list on the left side that allows you to go into great detail about metrics on the repository.
Para mí la pestaña de Insights es genial ya que proporciona mucha información sobre el repositorio. Desde cuantificar la actividad que ha habido hasta los commits e issues, pasando también por informes sobre el tráfico del repositorio. Puedes ver una lista en el lado izquierdo que te permite entrar en gran detalle sobre las métricas del repositorio.
![](Images/Day40_Git17.png)
Finally, we have the Settings tab, this is where we can get into the details of how we run our repository, I am currently the only maintainer of the repository but we could share this responsibility here. We can define integrations and other such tasks here.
Por último, tenemos la pestaña Configuración donde podemos entrar en los detalles de cómo personalizar nuestro repositorio. Actualmente soy el único mantenedor del repositorio pero podríamos compartir esta responsabilidad aquí. Podemos definir integraciones, políticas de ramas y otras tareas.
![](Images/Day40_Git18.png)
This was a super quick overview of GitHub, I think there are some other areas that I might have mentioned that need explaining in a little more detail. As mentioned GitHub houses millions of repositories mostly these are holding source code and these can be public or privately accessible.
Como se mencionó GitHub alberga millones de repositorios, en su mayoría son código fuente y estos pueden ser de acceso público o privado.
Hemos echado un vistazo súper rápido de GitHub, creo que se podría detallar mucho más, pero por ahora no somos comerciales de la herramienta, así que vamos a la parte técnica.
### Forking
I am going to get more into Open-Source in the session tomorrow but a big part of any code repository is the ability to collaborate with the community. Let's think of the scenario I want a copy of a repository because I want to make some changes to it, maybe I want to fix a bug or maybe I want to change something to use it for a use case that I have that was maybe not the intended use case for the original maintainer of the code. This is what we would call forking a repository. A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
Voy a entrar más en Open-Source en la sesión de mañana, pero una gran parte de cualquier repositorio de código es la capacidad de colaborar con la comunidad. Pensemos en el escenario que quiero una copia de un repositorio porque quiero hacer algunos cambios en él, tal vez quiero corregir un error o tal vez quiero cambiar algo para utilizarlo para un caso de uso que tengo que tal vez no era el caso de uso previsto para el mantenedor original del código. Esto es lo que llamaríamos bifurcar un repositorio. Un fork es una copia de un repositorio. La bifurcación de un repositorio permite experimentar libremente con los cambios sin afectar al proyecto original.
Let me head back to the opening page after login and see one of those suggested repositories.
Permíteme volver a la página de inicio después de iniciar sesión y ver uno de esos repositorios sugeridos.
![](Images/Day40_Git19.png)
If we click on that repository we are going to get the same look as we have just walked through on the 90DaysOfDevOps repository.
Si hacemos click en ese repositorio vamos a obtener el mismo aspecto que acabamos de ver en el repositorio 90DaysOfDevOps.
![](Images/Day40_Git20.png)
If we notice below we have 3 options, we have watch, fork and star.
Si nos fijamos a continuación tenemos 3 opciones:
- Watch - Updates when things happen to the repository.
- Fork - a copy of a repository.
- Star - "I think your project is cool"
- Watch - Se actualiza con los visitante al repositorio.
- Fork - Las copias del repositorio.
- Star - "Creo que tu proyecto es genial".
![](Images/Day40_Git21.png)
Given our scenario of wanting a copy of this repository to work on we are going to hit the fork option. If you are a member of multiple organisations then you will have to choose where the fork will take place, I am going to choose my profile.
Vamos a darle a la opción fork para hacer una copia en la que trabajar. Si eres miembro de varias organizaciones entonces tendrás que elegir donde se realizará el fork, yo voy a elegir mi perfil.
![](Images/Day40_Git22.png)
Now we have our copy of the repository that we can freely work on and change as we see fit. This would be the start of the pull request process that we mentioned briefly before but we will cover it in more detail tomorrow.
Ahora ya tenemos nuestra copia del repositorio sobre la que podemos trabajar libremente y modificarla a nuestro antojo. Este sería el comienzo del proceso de pull request que mencionamos brevemente antes pero que cubriremos con más detalle mañana.
![](Images/Day40_Git23.png)
Ok, I hear you say, but how do I make changes to this repository and code if it's on a website, well you can go through and edit on the website but it's not going to be the same as using your favourite IDE on your local system with your favourite colour theme. For us to get a copy of this repository on our local machine we will perform a clone of the repository. This will allow us to work on things locally and then push our changes back into our forked copy of the repository.
Ok, te oigo decir, pero ¿cómo puedo hacer cambios en este repositorio y el código si está en un sitio web? Bueno, puedes editarlo directamente en el página Github, pero no va a ser lo mismo que usar tu IDE favorito en local. Para obtener una copia de este repositorio en local vamos a realizar un clon del repositorio. Esto nos permitirá trabajar localmente y luego empujar/pushear nuestros cambios de nuevo en nuestra copia bifurcada en el repositorio remoto.
We have several options when it comes to getting a copy of this code as you can see below.
Tenemos varias opciones cuando se trata de obtener una copia de este código como se puede ver a continuación.
There is a local version available of GitHub Desktop which gives you a visual desktop application to track changes and push and pull changes between local and GitHub.
Hay una versión local disponible de GitHub Desktop que le da una aplicación de escritorio visual para realizar un seguimiento de los cambios y empujar/pushear y tirar/pullear los cambios entre el local y GitHub.
For this little demo, I am going to use the HTTPS URL we see on there.
Para esta pequeña demostración, voy a utilizar la URL HTTPS.
![](Images/Day40_Git24.png)
Now on our local machine, I am going to navigate to a directory I am happy to download this repository to and then run `git clone url`
Ahora, en nuestra máquina local, voy a navegar al directorio donde quiero descargar el repositorio y luego ejecutar `git clone url`.
![](Images/Day40_Git25.png)
Now we could take it to VScode to make some changes to this.
Podemos llevarlo a VScode para hacer algunos cambios.
![](Images/Day40_Git26.png)
Let's now make some changes, I want to make a change to all those links and replace that with something else.
Vamos a hacer algunos cambios, quiero hacer un cambio en todos esos enlaces y sustituirlos por otra cosa.
![](Images/Day40_Git27.png)
Now if we check back on GitHub and we find our readme.mdin that repository, you should be able to see a few changes that I made to the file.
Si nos fijamos de nuevo en GitHub y encontramos nuestro readme.md, deberías ser capaz de ver algunos cambios que he hecho en el archivo.
![](Images/Day40_Git28.png)
At this stage, this might be complete and we might be happy with our change as we are the only people going to use our new change but maybe it was a bug change and if that is the case then we will want to contribute via a Pull Request to notify the original repository maintainers of our change and see if they accept our changes.
En esta etapa, esto podría estar completo y podríamos estar contentos con nuestro cambio, ya que somos las únicas personas que van a utilizar nuestro nuevo cambio, pero tal vez fue un cambio de error y si ese es el caso, entonces vamos a querer contribuir a través de un Pull Request para notificar a los mantenedores del repositorio original de nuestro cambio y ver si aceptan nuestros cambios.
We can do this by using the contribute button highlighted below. I will cover more on this tomorrow when we look into Open-Source workflows.
Podemos hacer esto utilizando el botón de contribución que se muestra a continuación. Mañana con los flujos de trabajo Open-Source veremos más sobre esto.
![](Images/Day40_Git29.png)
I have spent a long time looking through GitHub and I hear some of you cry but what about other options!
Me han dicho muchos: ¿qué pasa con las otras opciones de repositorios remotos?
Well, there are and I am going to find some resources that cover the basics for some of those as well. You are going to come across GitLab and BitBucket amongst others in your travels and whilst they are git-based services they have their differences.
Bueno, voy a dejar algunos recursos que cubren los conceptos básicos para el resto de opciones. En tus viajes te encontrarás con GitLab y BitBucket, entre otros, y aunque son servicios basados en Git, tienen sus diferencias.
You will also come across hosted options. Most commonly here I have seen GitLab as a hosted version vs GitHub Enterprise (Don't believe there is a free hosted GitHub?)
También encontrarás opciones alojadas, la más común es GitLab frente a GitHub Enterprise. El traductor recomienda la opcíon de código libre gitea.io.
## Resources
## Recursos
- [Learn GitLab in 3 Hours | GitLab Complete Tutorial For Beginners](https://www.youtube.com/watch?v=8aV5AxJrHDg)
- [BitBucket Tutorials Playlist](https://www.youtube.com/watch?v=OMLh-5O6Ub8&list=PLaD4FvsFdarSyyGl3ooAm-ZyAllgw_AM5)
@ -196,5 +200,14 @@ You will also come across hosted options. Most commonly here I have seen GitLab
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
- [En español] [Comandos Git](https://gitea.vergaracarmona.es/man-linux/comandos-git)
- [En español][Apuntes Curso de Git](https://vergaracarmona.es/wp-content/uploads/2022/10/Curso-git_vergaracarmona.es_.pdf) de [Juan Carlos Rubio](https://www.linkedin.com/in/juan-carlos-rubio-pineda/Curso-git_vergaracarmona-es).
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- ["Instalar git en ubuntu"](https://vergaracarmona.es/instalar-git-en-ubuntu/)
- ["Comandos de git"](https://vergaracarmona.es/comandos-de-git/)
- ["Estrategias de fusión en git: Ship / Show / Ask"](https://vergaracarmona.es/estrategias-bifurcacion-git-ship-show-ask/)
- ["Resolver conflictos en Git. Merge, Squash, Rebase o Pull"](https://vergaracarmona.es/merge-squash-rebase-pull/)
- ["Borrar commits de git: reset, rebase y cherry-pick"](https://vergaracarmona.es/reset-rebase-cherry-pick/)
- [GitHub Profile README Generator](https://github.com/rahuldkjain/github-profile-readme-generator)
See you on [Day 41](day41.md)
Nos vemos en el [Día 41](day41.md)

View File

@ -1,118 +1,106 @@
---
title: '#90DaysOfDevOps - The Open Source Workflow - Day 41'
published: false
description: 90DaysOfDevOps - The Open Source Workflow
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048806
---
## El flujo de trabajo del Open Source
## The Open Source Workflow
Esperemos que a través de las últimas 7 secciones de Git tengamos una mejor comprensión de lo que es git. También en GitHub cómo un servicio online que se integra con git para proporcionar un repositorio de código fuente, además de una forma en que la comunidad en general puede colaborar en el código y los proyectos abiertos.
Hopefully, through the last 7 sections of Git, we have a better understanding of what git is and then how a git-based service such as GitHub integrates with git to provide a source code repository but also a way in which the wider community can collaborate on code and projects together.
Cuando pasamos a través de los fundamentos de GitHub fuimos a través del proceso de bifurcación de un proyecto al azar y hacer un cambio en nuestro repositorio local. Aquí queremos ir un paso más allá y contribuir a un proyecto de código abierto.
When we went through the GitHub fundamentals we went through the process of forking a random project and making a change to our local repository. Here we want to go one step further and contribute to an open-source project. Remember that contributing doesn't need to be bug fixes or coding features but it could also be documentation. Every little helps and it also allows you to get hands-on with some of the git functionality we have covered.
Recuerda que contribuir no tiene por qué ser corregir errores o codificar características, sino que también puede ser documentación, traducción, propuestas de mejoras, etc. Todo ayuda a mejorar los proyectos comunitarios. Además permite ponerte manos a la obra con algunas de las funcionalidades de git que hemos cubierto o con las tecnologías que contienen los repositorios.
## Fork a Project
## Bifurcar un proyecto
The first thing we have to do is find a project we can contribute to. I have recently been presenting on the [Kanister Project](https://github.com/kanisterio/kanister) and I would like to share my presentations that are now on YouTube to the main readme.mdfile in the project.
Lo primero que tenemos que hacer es encontrar un proyecto en el que podamos contribuir. Recientemente he estado presentando en el [Proyecto Kanister](https://github.com/kanisterio/kanister) y me gustaría compartir mis presentaciones que ahora están en YouTube al fichero readme.md principal del proyecto.
First of all, we need to fork the project. Let's run through that process. I am going to navigate to the link shared above and fork the repository.
En primer lugar, tenemos que bifurcar el proyecto como vimos en el día de ayer. Voy a navegar hasta el enlace mencionado y hacer un fork del repositorio.
![](Images/Day41_Git1.png)
We now have our copy of the whole repository.
Ahora tenemos nuestra copia de todo el repositorio.
![](Images/Day41_Git2.png)
For reference on the Readme.mdfile the original Presentations listed are just these two so we need to fix this with our process.
En el archivo Readme.md las presentaciones originales listadas son solo estas dos por lo que vamos a aportar más.
![](Images/Day41_Git3.png)
## Clones to a local machine
## Clona a una máquina local
Now we have our fork we can bring that down to our local and we can then start making our edits to the files. Using the code button on our repo we can grab the URL and then use `git clone url` in a directory we wish to place the repository.
Ahora que tenemos nuestro fork podemos bajarlo a nuestra máquina local y empezar a editar los archivos. Usando el botón de código en nuestro repositorio podemos coger la URL y luego usar `git clone url` en un directorio en el que queramos colocar el repositorio. Personalmente, me gusta llamar al directorio con el mismo nombre del proyecto.
![](Images/Day41_Git4.png)
## Make our changes
## Realizamos nuestros cambios
We have our project local so we can open VSCode or an IDE or text editor of your choice to add your modifications.
Tenemos nuestro proyecto en local así que podemos abrir VSCode o un IDE o editor de texto de nuestra elección para añadir las modificaciones.
![](Images/Day41_Git5.png)
The readme.mdfile is written in markdown language and because I am modifying someone else's project I am going to follow the existing project formatting to add our content.
El archivo readme.md está escrito en lenguaje markdown y como estoy modificando el proyecto de otra persona voy a seguir el formato del proyecto existente para añadir nuestro contenido. Quiero decir con esto que es importante seguir la línea editorial de un proyecto y hacer cambios que encajen con el proyecto para no dificurtar su futura lectura y la comprobación de cambios por el autor.
![](Images/Day41_Git6.png)
## Test your changes
## Prueba tus cambios
We must as a best practice test our changes, this makes total sense if this was a code change to an application you would want to ensure that the application still functions after a code change, well we also must make sure that documentation is formatted and looks correct.
Como buena práctica debemos probar nuestros cambios, esto tiene sentido total si se tratara de un cambio de código a una aplicación que desea asegurarse de que la aplicación sigue funcionando después de un cambio de código, así que también debemos asegurarnos de que la documentación tiene el formato y el aspecto correcto. Ni se te ocurra pedir cambios en una pull request con errores porque no se te aceptará y puede que en muchos casos simplemente seas ignorado.
In vscode we can add a lot of plugins one of these is the ability to preview markdown pages.
En vscode podemos añadir un montón de plugins para previsualizar páginas markdown.
![](Images/Day41_Git7.png)
## Push changes back to our forked repository
Personalmente utilizo [markdown](https://marketplace.visualstudio.com/items?itemName=starkwang.markdown) y [markdown all in one](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one), que me permite previsualizar el archivo markdown y mucho más.
We do not have the authentication to push our changes directly back to the Kanister repository so we have to take this route. Now that I am happy with our changes we can run through some of those now well-known git commands.
## Enviar los cambios a nuestro repositorio fork
No tenemos la autenticación para pushear cambios directamente al repositorio Kanister así que tenemos que tomar otra ruta. En el momento que estoy satisfecho con los cambios y lo he comprobado las veces necesarias para estar seguro que no tiene errores, podemos ejecutar los comandos git que ya tenemos en nuestro haber.
![](Images/Day41_Git8.png)
Now we go back to GitHub to check the changes once more and then contribute back to the master project.
Ahora volvemos a GitHub para comprobar los cambios una vez más, no dejes de comprobarlo, los errores no vendrán por hacer las cosas mal, eso es normal, los errores vendrán por no comprobar las suficientes veces. En este punto, ya podemos contribuir al proyecto original.
Looks good.
Tiene buena pinta.
![](Images/Day41_Git9.png)
Now we can go back to the top of our forked repository for Kanister and we can see that we are 1 commit ahead of the kanisterio:master branch.
Ahora podemos volver a la parte superior de nuestro repositorio bifurcado para Kanister y podemos ver que estamos 1 commit por delante de la rama kanisterio:master.
![](Images/Day41_Git10.png)
Next, we hit that contribute button highlighted above. We see the option to "Open Pull Request"
A continuación, pulsamos el botón de contribuir resaltado arriba, la opción "Open Pull Request".
![](Images/Day41_Git11.png)
## Open a pull request
## Abrir un pull request
There is quite a bit going on in this next image, top left you can now see we are in the original or the master repository. then you can see what we are comparing and that is the original master and our forked repository. We then have a create pull request button which we will come back to shortly. We have our single commit but if this was more changes you might have multiple commits here. then we have the changes we have made in the readme.mdfile.
Atento, en la siguiente imagen hay bastantes cosas sucediendo, arriba a la izquierda puedes ver que estamos en el repositorio original master. Luego puedes ver lo que estamos comparando y que es el repositorio original y nuestro repositorio bifurcado. A continuación, tenemos un botón de crear pull request al que vamos a volver en breve. Tenemos nuestra único commit, pero si se tratara de más cambios se podrían ver todos los commits aquí. Vemos los cambios realizados en readme.md.
![](Images/Day41_Git12.png)
We have reviewed the above changes and we are ready to create a pull request by hitting the green button.
Hemos revisado los cambios anteriores y estamos listos para crear un pull request dándole al botón verde.
Then depending on how the maintainer of a project has set out their Pull Request functionality on their repository you may or may not have a template that gives you pointers on what the maintainer wants to see.
Entonces, dependiendo de cómo el mantenedor de un proyecto ha establecido su funcionalidad Pull Request, puede o no tener una plantilla que le da indicaciones sobre lo que el mantenedor quiere ver.
This is again where you want to make a meaningful description of what you have done, clear and concise but with enough detail. You can see I have made a simple change overview and I have ticked documentation.
Aquí es donde puedes hacer una descripción significativa de lo que has hecho, clara y concisa, pero con suficiente detalle. Puedes ver que he hecho un simple resumen de cambios y he marcado documentación.
![](Images/Day41_Git13.png)
## Create a pull request
## Crear un pull request
We are now ready to create our pull request. After hitting the "Create Pull Request" at the top of the page you will get a summary of your pull request.
Ya estamos listos para crear nuestro pull request. Después de pulsar "Create Pull Request" en la parte superior de la página obtendrás un resumen de tu pull request.
![](Images/Day41_Git14.png)
Scrolling down you are likely to see some automation taking place, in this instance, we require a review and some checks are taking place. We can see that Travis CI is in progress and a build has started and this will check our update, making sure that before anything is merged we are not breaking things with our additions.
Desplazándote hacia abajo es probable que veas que sucede alguna automatización, en este caso, requerimos una revisión y algunas comprobaciones que se están llevando a cabo. Podemos ver que Travis CI está en progreso y una construcción ha comenzado y esto comprobará nuestra actualización, asegurándose de que no estamos rompiendo nada con nuestras adiciones antes de que se fusione.
![](Images/Day41_Git15.png)
Another thing to note here is that the red in the screenshot above, can look a little daunting and look as if you have made mistakes! Don't worry you have not broken anything, my biggest tip here is this process is there to help you and the maintainers of the project. If you have made a mistake at least from my experience the maintainer will contact and advise on what to do next.
Otra cosa a tener en cuenta aquí es que el rojo en la captura de pantalla anterior, puede parecer un poco desalentador, parece como si hubieras cometido errores. Nada más lejos, no te preocupes, no has roto nada, mi mayor consejo aquí es que este proceso está ahí para ayudarte a ti y a los mantenedores del proyecto. Si usted ha cometido un error, al menos desde mi experiencia, el mantenedor se pondrá en contacto y le aconsejará sobre qué hacer a continuación.
This pull request is now public for everyone to see [added Kanister presentation/resource #1237](https://github.com/kanisterio/kanister/pull/1237)
![](Images/Day41_Git16.png)
I am going to publish this before the merge and pull requests are accepted so maybe we can get a little prize for anyone that is still following along and can add a picture of the successful PR?
Este pull request es ahora público para que todo el mundo lo vea: [added Kanister presentation/resource #1237](https://github.com/kanisterio/kanister/pull/1237)
1. Fork this repository to your own GitHub account
2. Add your picture and possibly text
3. Push the changes to your forked repository
4. Create a PR that I will see and approve.
5. I will think of some sort of prize
Con esto terminamos nuestro repaso a Git y GitHub. A continuación nos sumergiremos en los contenedores, que comienza con una visión general de cómo y por qué contenedores y también una mirada a la virtualización y cómo hemos llegado hasta aquí.
This then wraps up our look into Git and GitHub, next we are diving into containers which starts with a big picture look into how, and why containers and also a look into virtualisation and how we got here.
## Resources
## Recursos
- [Learn GitLab in 3 Hours | GitLab Complete Tutorial For Beginners](https://www.youtube.com/watch?v=8aV5AxJrHDg)
- [BitBucket Tutorials Playlist](https://www.youtube.com/watch?v=OMLh-5O6Ub8&list=PLaD4FvsFdarSyyGl3ooAm-ZyAllgw_AM5)
@ -123,5 +111,13 @@ This then wraps up our look into Git and GitHub, next we are diving into contain
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
- [En español] [Comandos Git](https://gitea.vergaracarmona.es/man-linux/comandos-git)
- [En español][Apuntes Curso de Git](https://vergaracarmona.es/wp-content/uploads/2022/10/Curso-git_vergaracarmona.es_.pdf) de [Juan Carlos Rubio](https://www.linkedin.com/in/juan-carlos-rubio-pineda/Curso-git_vergaracarmona-es).
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- ["Instalar git en ubuntu"](https://vergaracarmona.es/instalar-git-en-ubuntu/)
- ["Comandos de git"](https://vergaracarmona.es/comandos-de-git/)
- ["Estrategias de fusión en git: Ship / Show / Ask"](https://vergaracarmona.es/estrategias-bifurcacion-git-ship-show-ask/)
- ["Resolver conflictos en Git. Merge, Squash, Rebase o Pull"](https://vergaracarmona.es/merge-squash-rebase-pull/)
- ["Borrar commits de git: reset, rebase y cherry-pick"](https://vergaracarmona.es/reset-rebase-cherry-pick/)
See you on [Day 42](day42.md)
Nos vemos en el [Día 42](day42.md)

View File

@ -1,128 +1,129 @@
## The Big Picture: Containers
## El panorama: Contenedores
We are now starting the next section and this section is going to be focused on containers in particular we are going to be looking into Docker getting into some of the key areas to understand more about Containers.
Empezamos nueva sección en la que nos centraremos en los contenedores. En particular vamos a mirar Docker para entender algunas claves de los contenedores.
I will also be trying to get some hands-on here to create the container that we can use during this section but also in future sections later on in the challenge.
Pasaremos por un poco de práctica para crear el contenedor que utilizaremos durante esta sección y en futuras secciones del desafío.
As always this first post is going to be focused on the big picture of how we got here and what it all means.
Como siempre, este primer post se va a centrar en el panorama general de cómo hemos llegado hasta aquí y lo que todo esto significa.
#History of platforms and application development
#do we want to talk about Virtualisation & Containerisation
### ¿Por qué otra forma de ejecutar aplicaciones?
### Why another way to run applications?
Lo primero que tenemos que plantearnos es por qué necesitamos otra forma de ejecutar software o aplicaciones. La elección es grande, podemos ejecutar nuestras aplicaciones de muchas formas diferentes, por ejemplo, podríamos ver las aplicaciones desplegadas en hardware físico con un sistema operativo y una sola aplicación desplegada allí, y podríamos verlas en máquina virtual o instancias IaaS basadas en la nube ejecutando nuestra aplicación, que luego se integran en una base de datos de nuevo en una MV o como PaaS ofreciendo en la nube pública. O, como vamos a ver, podemos ver nuestras aplicaciones ejecutándose en contenedores.
The first thing we have to take a look at is why do we need another way to run our software or applications? Well it is just that choice is great, we can run our applications in many different forms, we might see applications deployed on physical hardware with an operating system and a single application deployed there, and we might see the virtual machine or cloud-based IaaS instances running our application which then integrate into a database again in a VM or as PaaS offering in the public cloud. Or we might see our applications running in containers.
Ninguna de las opciones anteriores es incorrecta o correcta, pero cada una tiene sus razones para escogerla y seguramente ninguna de ellas desaparecezca. He visto una gran cantidad de contenido sobre Contenedores vs Máquinas Virtuales y realmente no debería haber un argumento, ya que son como argumentos de manzanas vs peras en el que ambos son frutas (formas de ejecutar nuestras aplicaciones), pero no son lo mismo.
None of the above options is wrong or right, but they each have their reasons to exist and I also strongly believe that none of these is going away. I have seen a lot of content that walks into Containers vs Virtual Machines and there really should not be an argument as that is more like apples vs pears argument where they are both fruit (ways to run our applications) but they are not the same.
También diría que si estás empezando y estás desarrollando una aplicación deberías inclinarte hacia los contenedores, más adelante lo veremos en detalle pero en resumen se trata de eficiencia, velocidad y tamaño. Pero esto tiene un precio, si no tienes ni idea de contenedores va a ser una curva de aprendizaje demasiado inclinada, te obligará a entender el por qué y entrar en esta mentalidad. Si has desarrollado tus aplicaciones de una forma particular o no estás en un entorno totalmente nuevo, puede que tengas que enfrentarte a más problemas incluso antes de considerar los contenedores.
I would also say that if you were starting and you were developing an application you should lean towards containers simply because we will get into some of these areas later, but it's about efficiency, speed and size. But that also comes with a price, if you have no idea about containers then it's going to be a learning curve to force yourself to understand the why and get into that mindset. If you have developed your applications a particular way or you are not in a greenfield environment then you might have more pain points to deal with before even considering containers.
We have many different choices then when it comes to downloading a given piece of software, there are a variety of different operating systems that we might be using. And specific instructions for what we need to do to install our applications.
Tenemos muchas opciones diferentes a la hora de descargar un determinado software, hay una variedad de sistemas operativos diferentes que podríamos utilizar. E instrucciones específicas sobre lo que tenemos que hacer para instalar nuestras aplicaciones.
![](Images/Day42_Containers1.png)
More and more recently I am finding that the applications we might have once needed a full server OS, A VM, Physical or cloud instance are now releasing container-based versions of their software. I find this interesting as this opens the world of containers and then Kubernetes to everyone and not just a focus on application developers.
Cada vez nos encontramos más que las aplicaciones que una vez podrían haber necesitado un sistema operativo de servidor completo (una MV, instancia física o en la nube), ahora están lanzando versiones su software basadas en contenedores. Es interesante ya que esto abre las posibilidades de los contenedores y de Kubernetes a todo el mundo, y no sólo un enfoque en los desarrolladores de aplicaciones.
![](Images/Day42_Containers2.png)
As you can probably tell as I have said before, I am not going to advocate that the answer is containers, what's the question! But I would like to discuss how this is another option for us to be aware of when we deploy our applications.
Podrás deducir por lo que se ha dicho antes que no se va defender los contenedores como el mejor sistema para desplegar aplicaciones, pero desde luego existe el espacio para el debate.
![](Images/Day42_Containers4.png)
We have had container technology for a long time, so why now over the last say 10 years has this become popular, I would say even more popular in the last 5. We have had containers for decades. It comes down to the challenge of containers or should I say images as well, to how we distribute our software, because if we just have container technology, then we still will have many of the same problems we've had with software management.
Hemos tenido la tecnología de contenedores durante mucho tiempo, así que ¿por qué en los últimos 10 años se ha hecho tan popular? Diría que incluso mucho más populares en los últimos 5.
If we think about Docker as a tool, the reason that it took off, is because of the ecosystem of images that are easy to find and use. Simple to get on your systems and get up and running. A major part of this is consistency across the entire space, of all these different challenges that we face with software. It doesn't matter if it's MongoDB or nodeJS, the process to get either of those up and running will be the same. The process to stop either of those is the same. All of these issues will still exist, but the nice thing is, when we bring good container and image technology together, we now have a single set of tools to help us tackle all of these different problems. Some of those issues are listed below:
Hemos tenido contenedores durante décadas. ¿Se reduce al desafío de los contenedores o debería decir imágenes también? Porque si sólo tenemos la tecnología de contenedores, entonces todavía tendremos muchos de los mismos problemas que hemos tenido con la gestión de software.
- We first have to find software on the internet.
- We then have to download this software.
- Do we trust the source?
- Do we then need a license? Which License?
- Is it compatible with different platforms?
- What is the package? binary? Executable? Package manager?
- How do we configure the software?
- Dependencies? Did the overall download have us covered or do we need them as well?
- Dependencies of Dependencies?
- How do we start the application?
- How do we stop the application?
- Will it auto-restart?
- Start on boot?
- Resource conflicts?
- Conflicting libraries?
- Port Conflicts
- Security for the software?
- Software updates?
- How can I remove the software?
Si pensamos en Docker como una herramienta, la razón por la que despegó es al ecosistema de imágenes que son fáciles de conseguir y de poner en marcha. Una parte importante de esto es la coherencia en todo el espacio, de todos estos diferentes desafíos que enfrentamos con el software. No importa si es MongoDB o nodeJS, el proceso para poner en marcha cualquiera de ellos será el mismo. El proceso para detener cualquiera de ellos es el mismo. Todos estos problemas seguirán existiendo, pero lo bueno es que, cuando unimos una buena tecnología de contenedores e imágenes conseguiremos un único conjunto de herramientas para ayudarnos a abordar todos estos problemas diferentes. Algunos de esos problemas son:
We can split the above into 3 areas of the complexity of the software that containers and images do help with these.
- Primero tenemos que encontrar software en Internet.
- Luego tenemos que descargarlo.
- ¿Confiamos en la fuente?
- ¿Necesitamos una licencia? ¿Qué licencia?
- ¿Es compatible con diferentes plataformas?
- ¿Cuál es el paquete? ¿Binario? ¿Ejecutable? ¿Gestor de paquetes?
- ¿Cómo se configura el software?
- ¿Dependencias? ¿La descarga general nos ha cubierto o también las necesitamos?
- ¿Dependencias de dependencias?
- ¿Cómo iniciamos la aplicación?
- ¿Cómo detenemos la aplicación?
- ¿Se reiniciará automáticamente?
- ¿Se iniciará al arrancar?
- ¿Conflictos de recursos?
- ¿Conflictos de librerías?
- Conflictos de puertos
- ¿Seguridad del software?
- ¿Actualizaciones del software?
- ¿Cómo puedo eliminar el software?
| Distribution | Installation | Operation |
| ------------ | ------------- | ------------------ |
| Find | Install | Start |
| Download | Configuration | Security |
| License | Uninstall | Ports |
| Package | Dependencies | Resource Conflicts |
| Trust | Platform | Auto-Restart |
| Find | Libraries | Updates |
Podemos dividir lo anterior en 3 áreas de la complejidad del software que los contenedores y las imágenes ayudan con estos.
Containers and images are going to help us remove some of these challenges that we have with possibly other software and applications.
| Distribución | Instalación | Funcionamiento |
| ------------ | -------------- | ------------------- |
| Buscar | Instalar | Iniciar |
| Descargar | Configuración | Seguridad |
| Licencia | Desinstalación | Puertos |
| Paquete | Dependencias | Conflictos Recursos |
| Confianza | Plataforma | Reinicio automático |
| Buscar | Bibliotecas | Actualizaciones |
At a high level we could move installation and operation into the same list, Images are going to help us from a distribution point of view and containers help with the installation and operations.
Los contenedores y las imágenes nos van a ayudar a eliminar algunos de estos retos que tenemos posiblemente con otro software y aplicaciones.
Ok, probably sounds great and exciting but we still need to understand what is a container and now I have mentioned images so let's cover those areas next.
En un alto nivel podríamos mover la instalación y el funcionamiento en la misma lista, las imágenes nos van a ayudar desde el punto de vista de la distribución y los contenedores ayudan con la instalación y las operaciones.
Another thing you might have seen a lot when we talk about Containers for software development is the analogy used alongside shipping containers, shipping containers are used to ship various goods across the seas using large vessels.
Ok, probablemente suena muy bien y emocionante, pero todavía tenemos que entender lo que es un contenedor y ahora he mencionado imágenes así que vamos a verlo a continuación.
Otra cosa que habrás visto a menudo cuando hablamos de contenedores para el desarrollo de software es la analogía utilizada con los contenedores marítimos, los contenedores marítimos se utilizan para transportar diversas mercancías a través de los mares utilizando grandes buques.
![](Images/Day42_Containers5.png)
What does this have to do with our topic of containers? Think about the code that software developers write, how can we ship that particular code from one machine to another machine?
¿Qué tiene que ver con nuestro tema de los contenedores? Piensa en el código que escriben los desarrolladores de software, ¿cómo podemos enviar ese código concreto de una máquina a otra?
If we think about what we touched on before about software distribution, installation and operations but now we start to build this out into an environment visual. We have hardware and an operating system where you will run multiple applications. For example, nodejs has certain dependencies and needs certain libraries. If you then want to install MySQL then it needs its required libraries and dependencies. Each software application will have its library and dependency. We might be massively lucky and not have any conflicts between any of our applications where specific libraries and dependencies are clashing causing issues but the more applications the more chance or risk of conflicts. However, this is not about that one deployment when everything fixes your software applications are going to be updated and then we can also introduce these conflicts.
Si pensamos en lo que hemos tocado antes sobre la distribución de software, instalación y operaciones, pero ahora empezamos a construir esto en un entorno visual. Tenemos hardware y un sistema operativo donde se ejecutarán múltiples aplicaciones. Por ejemplo, nodejs tiene ciertas dependencias y necesita ciertas bibliotecas. Si a continuación, desea instalar MySQL entonces necesita sus bibliotecas y sus dependencias propias. Cada aplicación de software tendrá sus bibliotecas y dependencias. Podríamos tener mucha suerte y no tener ningún conflicto entre cualquiera de nuestras aplicaciones donde las bibliotecas y dependencias específicas están chocando causando problemas, pero cuantas más aplicaciones más posibilidades o riesgo de conflictos. Sin embargo, se trata de que un despliegue se producirá muchas veces, y no puede esperar a que todo este arreglado, porque en cada actualización se podrían introducir estos conflictos.
![](Images/Day42_Containers6.png)
Containers can help solve this problem. Containers help **build** your application, **ship** the application, **deploy** and **scale** these applications with ease independently. let's look at the architecture, you will have hardware and operating system then on top of it you will have a container engine like docker which we will cover later. The container engine software helps create containers that package the libraries and dependencies along with it so that you can move this container seamlessly from one machine to another machine without worrying about the libraries and dependencies since they come as a part of a package which is nothing but the container so you can have different containers this container can be moved across the systems without worrying about the underlying dependencies that the application
needs to run because everything the application needs to run is packaged as
a container that you can move.
Los contenedores pueden ayudar a resolver este problema. Los contenedores ayudan a **construir**, a **enviar**, a **desplegar** y a **escalar** estas aplicaciones con facilidad de forma independiente. echemos un vistazo a la arquitectura, tendrás hardware y sistema operativo y luego encima tendrás un motor de contenedores como docker que veremos en breve. El software de motor de contenedores ayuda a crear contenedores que empaquetan las bibliotecas y dependencias junto con él para que pueda mover este contenedor sin problemas de una máquina a otra sin preocuparse por las bibliotecas y dependencias, ya que vienen como parte de un paquete en el contenedor. Con lo cual, se puede mover a través de los sistemas sin preocuparse por las dependencias subyacentes que la aplicación necesita para funcionar.
![](Images/Day42_Containers7.png)
### The advantages of these containers
### Las ventajas de estos contenedores
- Containers help package all the dependencies within the container and
isolate it.
- Los contenedores ayudan a empaquetar todas las dependencias dentro del contenedor y aislarlas.
- It is easy to manage the containers
- Es fácil gestionar.
- The ability to move from one system to another.
- Se puede pasar de un sistema a otro.
- Containers help package the software and you can easily ship it without any duplicate efforts
- Los contenedores ayudan a empaquetar el software y se puede enviar fácilmente sin duplicar esfuerzos.
- Containers are easily scalable.
- Los contenedores son fácilmente escalables.
Using containers you can scale independent containers and use a load balancer
or a service which helps split the traffic and you can scale the applications horizontally. Containers offer a lot of flexibility and ease in how you manage your applications
Usando contenedores puedes escalar contenedores independientes y usar un equilibrador de carga
o un servicio que ayude a dividir el tráfico y puedas escalar las aplicaciones horizontalmente. Los contenedores ofrecen mucha flexibilidad y facilidad a la hora de gestionar las aplicaciones.
### What is a container?
### ¿Qué es un contenedor?
When we run applications on our computer, this could be the web browser or VScode that you are using to read this post. That application is running as a process or what is known as a process. On our laptops or systems, we tend to run multiple applications or as we said processes. When we open a new application or click on the application icon this is an application we would like to run, sometimes this application might be a service that we just want to run in the background, our operating system is full of services that are running in the background providing you with the user experience you get with your system.
Cuando ejecutamos aplicaciones en nuestro ordenador, podría ser en el navegador o en el VScode que quizá estés utilizando para leer este post, esa aplicación se ejecuta como un proceso. En nuestros portátiles o sistemas tendemos a ejecutar múltiples aplicaciones o, como hemos dicho, procesos. Cuando abrimos una nueva aplicación o hacemos clic en el icono de la aplicación, a veces podría ser un servicio que sólo queremos ejecutar en segundo plano, nuestro sistema operativo está lleno de servicios que se ejecutan en segundo plano y que proporcionan la experiencia de usuario final.
That application icon represents a link to an executable somewhere on your file system, the operating system then loads that executable into memory. Interestingly, that executable is sometimes referred to as an image when we're talking about a process.
Ese icono de aplicación representa un enlace a un ejecutable en algún lugar de tu sistema de archivos, el sistema operativo entonces carga ese ejecutable en la memoria. Curiosamente, a veces nos referimos a ese ejecutable como una imagen cuando hablamos de un proceso.
Containers are processes, A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
Un contenedor es una unidad estándar de software que empaqueta el código y todas sus dependencias para que la aplicación se ejecute de forma rápida y fiable de un entorno informático a otro como lo hacen las aplicaciones.
Containerised software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.
El software en contenedores siempre se ejecutará igual, independientemente de la infraestructura. Los contenedores aíslan el software en su entorno mínimo viable y garantizan que funcione de manera uniforme a pesar de las diferencias, por ejemplo, entre el desarrollo y la puesta en escena.
I mentioned images in the last section when it comes to how and why containers and images combined made containers popular in our ecosystem.
He mencionado las imágenes en la última sección cuando se trata de cómo y por qué la combinación de contenedores e imágenes ha hecho que los contenedores sean populares en nuestro ecosistema.
### What is an Image?
### ¿Qué es una imagen?
A container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings. Container images become containers at runtime.
Una imagen de contenedor es un paquete de software ligero, independiente y ejecutable que incluye todo lo necesario para ejecutar una aplicación: código, tiempo de ejecución, herramientas del sistema, bibliotecas del sistema y configuraciones. Las imágenes de contenedor se convierten en contenedores en tiempo de ejecución.
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [Introduction to Container By Red Hat](https://www.redhat.com/en/topics/containers)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
See you on [Day 43](day43.md)
Nos vemos en el [Día 43](day43.md)

View File

@ -1,62 +1,67 @@
## What is Docker & Getting installed
## Qué es Docker y cómo instalarlo
In the previous post, I mentioned Docker at least once and that is because Docker is innovative in making containers popular even though they have been around for such a long time.
En el post anterior, he mencionado Docker al menos una vez y eso es porque Docker es el culpable en gran parte de la popularización de los contenedores, a pesar de que han existido desde hace mucho tiempo.
We are going to be using and explaining docker here but we should also mention the [Open Container Initiative (OCI)](https://www.opencontainers.org/) which is an industry standards organization that encourages innovation while avoiding the danger of vendor lock-in. Thanks to the OCI, we have a choice when choosing a container toolchain, including Docker, [CRI-O](https://cri-o.io/), [Podman](http://podman.io/), [LXC](https://linuxcontainers.org/), and others.
Vamos a utilizar y explicar un poco Docker, pero también debemos mencionar la [Open Container Initiative (OCI)](https://www.opencontainers.org/), que es una organización de estándares de la industria que fomenta la innovación, evitando el peligro de la dependencia del proveedor. Gracias a la OCI, tenemos donde elegir entre las herramientas de contenedores, incluyendo Docker, [CRI-O](https://cri-o.io/), [Podman](http://podman.io/), [LXC](https://linuxcontainers.org/), entre otros.
Docker is a software framework for building, running, and managing containers. The term "docker" may refer to either the tools (the commands and a daemon) or the Dockerfile file format.
Docker es un framework de software para construir, ejecutar y gestionar contenedores. El término "docker" puede referirse tanto a las herramientas (los comandos y un daemon) como al formato de archivo Dockerfile.
We are going to be using Docker Personal here which is free (for education and learning). This includes all the essentials that we need to cover to get a good foundation of knowledge of containers and tooling.
Utilizaremos Docker Personal, que es gratuito (para la educación y el aprendizaje). Esto incluye todo lo esencial que necesitamos para obtener una buena base de conocimientos de los contenedores y herramientas.
It is probably worth breaking down some of the "docker" tools that we will be using and what they are used for. The term docker can be referring to the docker project overall, which is a platform for devs and admins to develop, ship and run applications. It might also be a reference to the docker daemon process running on the host which manages images and containers also called Docker Engine.
Probablemente vale la pena desglosar algunas de las herramientas "docker" para saber por qué se utilizan. El término docker puede referirse al proyecto docker en general, que es una plataforma para que los desarrolladores y administradores desarrollen, envíen y ejecuten aplicaciones. También puede ser una referencia al daemon Docker que se ejecuta en el host que gestiona las imágenes y contenedores también llamado Docker Engine.
### Docker Engine
Docker Engine is an open-source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with:
Docker Engine es una tecnología de contenerización de código abierto para construir y contenerizar tus aplicaciones. Docker Engine actúa como una aplicación cliente-servidor con:
- A server with a long-running daemon process dockerd.
- APIs specify interfaces that programs can use to talk to and instruct the Docker daemon.
- A command line interface (CLI) client docker.
- Un servidor con un proceso demonio de larga ejecución dockerd.
- Las API especifican interfaces que los programas pueden utilizar para hablar con el demonio Docker y darle instrucciones.
- Una interfaz de línea de comandos (CLI) docker cliente.
The above was taken from the official Docker documentation and the specific [Docker Engine Overview](https://docs.docker.com/engine/)
Lo anterior fue tomado de la documentación oficial de Docker y el específico [Docker Engine Overview](https://docs.docker.com/engine/)
### Docker Desktop
We have a docker desktop for both Windows and macOS systems. An easy-to-install, lightweight docker development environment. A native OS application that leverages virtualisation capabilities on the host operating system.
Disponemos de un Docker Desktop para sistemas Windows y macOS. Un entorno de desarrollo docker ligero y fácil de instalar. Una aplicación nativa del sistema operativo que aprovecha las capacidades de virtualización en el sistema operativo anfitrión. Nadie lo utiliza, pero es una buena opción para comenzar.
Its the best solution if you want to build, debug, test, package, and ship Dockerized applications on Windows or macOS.
Puedes construir, depurar, probar, empaquetar y enviar aplicaciones Dockerizadas en Windows o macOS.
On Windows, we can also take advantage of WSL2 and Microsoft Hyper-V. We will cover some of the WSL2 benefits as we go through.
En Windows, también podemos aprovechar WSL2 y Microsoft Hyper-V. Veremos algunas de las ventajas de WSL2 a medida que avancemos, ya que como Windows no llega lo mejor es utilizar las opciones Linux.
Because of the integration with hypervisor capabilities on the host operating system docker provides the ability to run your containers with Linux Operating systems.
Debido a la difícil integración con las capacidades del hipervisor en el sistema operativo anfitrión, docker proporciona la capacidad de ejecutar sus contenedores con sistemas operativos Linux que no dan tantos problemas.
### Docker Compose
Docker compose is a tool that allows you to run more complex apps over multiple containers. With the benefit of being able to use a single file and command to spin up your application.
Docker compose es una herramienta que te permite ejecutar aplicaciones más complejas sobre múltiples contenedores. Con la ventaja de ser capaz de utilizar un único archivo y comando para hacer girar su aplicación. Es el principio de la orquestación de contenedores, un concepto que tendremos que interiorizar para dejar de tratar a nuestras máquinas como mascotas y comenzar a verlas como ganado.
### Docker Hub
A centralised resource for working with Docker and its components. Most commonly known as a registry to host docker images. But there are a lot of additional services here which can be used in part with automation or integrated into GitHub as well as security scanning.
Un recurso centralizado para trabajar con Docker y sus componentes, un registro de imágenes que nos facilitará mucho la existencia. Hay un montón de servicios adicionales que pueden ser utilizados en parte con la automatización o integrados en GitHub, así como el escaneo de seguridad.
### Dockerfile
A dockerfile is a text file that contains commands you would normally execute manually to build a docker image. Docker can build images automatically by reading the instructions we have in our dockerfile.
Un dockerfile es un archivo de texto que contiene comandos que también se pueden ejecutar manualmente para construir una imagen docker. Docker puede construir imágenes automáticamente leyendo las instrucciones que tenemos en nuestro dockerfile gracias al lenguaje declarativo.
## Installing Docker Desktop
## Instalando Docker Desktop
The [docker documenation](https://docs.docker.com/engine/install/) is amazing and if you are only just diving in then you should take a look and have a read-through. We will be using Docker Desktop on Windows with WSL2. I had already run through the installation on the machine we are using here.
La [documenación de Docker](https://docs.docker.com/engine/install/) es asombrosa y si quieres aprender de verdad deberías echarle un vistazo y tenerla como referencia. Vamos a utilizar Docker Desktop en Windows con WSL2. Ya he ejecutado la instalación en la máquina que estamos utilizando.
![](Images/Day43_Containers1.png)
Take note before you go ahead and install at the system requirements, [Install Docker Desktop on Windows](https://docs.docker.com/desktop/windows/install/) if you are using macOS including the M1-based CPU architecture you can also take a look at [Install Docker Desktop on macOS](https://docs.docker.com/desktop/mac/install/)
Toma nota antes de seguir adelante en los requisitos del sistema antes de [Instalar Docker Desktop en Windows](https://docs.docker.com/desktop/windows/install/). Si estás usando macOS, inclusive para la arquitectura de CPU basada en M1, puedes echar un vistazo a [Instalar Docker Desktop en macOS](https://docs.docker.com/desktop/mac/install/). Linux también puede ejecutar Docker Desktop virtualizado: https://docs.docker.com/desktop/install/linux-install/
I will run through the Docker Desktop installation for Windows on another Windows Machine and log the process down below.
Voy a ejecutar a través de la instalación de Docker Desktop para Windows en otra máquina Windows y registrar el proceso de abajo.
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
See you on [Day 44](day44.md)
Nos vemos en el [Día 44](day44.md)

View File

@ -1,132 +1,145 @@
## Docker Images & Hands-On with Docker Desktop
## Imágenes Docker y Manos a la Obra con Docker Desktop
We now have Docker Desktop installed on our system. (If you are running Linux then you still have options but no GUI but docker does work on Linux.)[Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/) (Other distributions also available.)
Ahora tenemos Docker Desktop instalado en nuestro sistema. (Si estás ejecutando Linux, tienes más opciones pero no el GUI.)[Instalar Docker Engine en Ubuntu](https://docs.docker.com/engine/install/ubuntu/) (También está disponible para otras distribuciones.)
In this post, we are going to get started with deploying some images into our environment. A recap on what a Docker Image is - A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker.
En este post, vamos a empezar con el despliegue de algunas imágenes en nuestro entorno. Una imagen Docker es un archivo utilizado para ejecutar código en un contenedor Docker. Las imágenes Docker actúan como un conjunto de instrucciones para construir un contenedor Docker, como una plantilla. Las imágenes Docker también actúan como el punto de partida cuando se utiliza Docker.
Now is a good time to go and create your account on [DockerHub](https://hub.docker.com/)
Ahora es un buen momento para crear tu cuenta en [DockerHub](https://hub.docker.com/)
![](Images/Day44_Containers1.png)
DockerHub is a centralised resource for working with Docker and its components. Most commonly known as a registry to host docker images. But there are a lot of additional services here which can be used in part with automation or integrated into GitHub as well as security scanning.
DockerHub es un recurso centralizado para trabajar con Docker y sus componentes. Más comúnmente conocido como un registro para alojar imágenes Docker. Pero hay un montón de servicios adicionales que se pueden utilizar en parte con la automatización o integración en GitHub, así como el escaneo de seguridad.
If you scroll down once logged in you are going to see a list of container images, You might see database images for MySQL, hello-world etc. Think of these as great baseline images or you might just need a database image and you are best to use the official one which means you don't need to create your own.
Desplazándote hacia abajo una vez logueado verás una lista de imágenes de contenedores, es posible que veas imágenes de bases de datos MySQL, hello-world, etc. Piensa en estas como las imágenes de referencia, puede que sólo necesites una imagen de BBDD MySQL y la mejor sea utilizar la oficial, lo que significa que no es necesario crear una propia personalizada.
![](Images/Day44_Containers2.png)
We can drill deeper into the view of available images and search across categories, operating systems and architectures. The one thing I highlight below is the Official Image, this should give you peace of mind about the origin of this container image.
Podemos profundizar en la vista de imágenes disponibles y buscar por categorías, sistemas operativos y arquitecturas. Hay que destacar la Imagen Oficial, porque esta debería darte tranquilidad sobre su origen. Para nada recomiendo utilizar imágenes no oficiales, sobretodo en producción. En caso de que lo hagas, asegúrate al menos de que son de un editor verificado.
![](Images/Day44_Containers3.png)
We can also search for a specific image, for example, WordPress might be a good base image that we want we can do that at the top and find all container images related to WordPress. Below are notices that we also have verified publisher.
- Official Image - Docker Official images are a curated set of Docker open source and "drop-in" solution repositories.
- Verified Publisher - High-quality Docker content from verified publishers. These products are published and maintained directly by a commercial entity.
Por otra parte, podemos buscar una imagen específica, por ejemplo, WordPress podría ser una buena imagen de base que incluye todas las imágenes de contenedores relacionados que necesite la aplicación. Ten en cuenta que existe diferencias entre imagen oficial y editor verificado.
- **Imagen Oficial** - Las imágenes Oficiales de Docker son un conjunto curado de código abierto de Docker y repositorios de soluciones "drop-in".
- **Editor verificado** - Contenido Docker de alta calidad de editores verificados. Estos productos son publicados y mantenidos directamente por una entidad comercial.
![](Images/Day44_Containers4.png)
### Exploring Docker Desktop
### Explorando Docker Desktop
We have Docker Desktop installed on our system and if you open this I expect unless you had this already installed you will see something similar to the image below. As you can see we have no containers running and our docker engine is running.
Tenemos Docker Desktop instalado en nuestro equipo windows. Si lo abres por primera vez verás algo similar a la imagen de abajo. Como puedes ver no tenemos ningún contenedor ejecutándose y nuestro motor docker está funcionando.
![](Images/Day44_Containers5.png)
Because this was not a fresh install for me, I do have some images already downloaded and available on my system. You will likely see nothing in here.
Debido a que esta no fue la primera instalación, tengo algunas imágenes ya descargadas y disponibles en mi sistema. Es probable que lo veas diferente.
![](Images/Day44_Containers6.png)
Under remote repositories, this is where you will find any container images you have stored in your docker hub. You can see from the below I do not have any images.
En los repositorios remotos es donde encontrarás cualquier imagen de contenedor que hayas almacenado en tu docker hub. Puedes ver en la imagen de abajo que no tengo ninguna imagen.
![](Images/Day44_Containers7.png)
We can also clarify this on our dockerhub site and confirm that we have no repositories there.
Hay que confirmarlo en nuestro sitio dockerhub y confirmar que no tenemos repositorios allí.
![](Images/Day44_Containers8.png)
Next, we have the Volumes tab, If you have containers that require persistence then this is where we can add these volumes to your local file system or a shared file system.
A continuación, tenemos la pestaña Volumes. Si tienes contenedores que requieren persistencia será aquí donde podemos añadir estos volúmenes al sistema de archivos local o a un sistema de archivos compartido.
![](Images/Day44_Containers9.png)
At the time of writing, there is also a Dev Environments tab, this is going to help you collaborate with your team instead of moving between different git branches. We won't be covering this.
En el momento de escribir esto, también hay una pestaña de Entornos de Desarrollo, esto va a ayudarte a colaborar con tu equipo en lugar de moverte entre diferentes ramas de git. No vamos a cubrir esto.
![](Images/Day44_Containers10.png)
Going back to the first tab you can see that there is a command we can run which is a getting started container. Let's run `docker run -d -p 80:80 docker/getting-started` in our terminal.
Volviendo a la primera pestaña puedes ver que hay un comando que podemos ejecutar para iniciar el contenedor. Ejecutamos en nuestro terminal:
```shell
docker run -d -p 80:80 docker/getting-started
```
![](Images/Day44_Containers11.png)
If we go and check our docker desktop window again, we are going to see that we have a running container.
Si comprobamos nuestro docker desktop veremos que ya tenemos un contenedor en ejecución.
![](Images/Day44_Containers12.png)
You might have noticed that I am using WSL2 and for you to be able to use that you will need to make sure this is enabled in the settings.
Te habrás dado cuenta de que estoy usando WSL2. Para usarlo tendrás que asegurarte de que está activado en la configuración.
![](Images/Day44_Containers13.png)
If we now go and check our Images tab again, you should now see an in-use image called docker/getting-started.
Si ahora comprobamos nuestra pestaña Imágenes deberías ver una imagen en uso llamada docker/getting-started.
![](Images/Day44_Containers14.png)
Back to the Containers/Apps tab, click on your running container. You are going to see the logs by default and along the top, you have some options to choose from, in our case I am pretty confident that this is going to be a web page running in this container so we are going to choose the open in the browser.
De vuelta a la pestaña Contenedores/Apps, haz click en tu contenedor en ejecución. Verás los registros por defecto y en la parte superior tiene algunas opciones para elegir. En nuestro caso no va a ser una web que se ejecute en este contenedor por lo que vamos a elegir la apertura en el navegador.
![](Images/Day44_Containers15.png)
When we hit that button above sure enough a web page should open hitting your localhost and display something similar to below.
Cuando pulsemos el botón de arriba, se abrirá una web que mostrará algo similar a lo que se muestra a continuación.
This container also has some more detail on our containers and images.
Este contenedor también tiene algunos detalles más sobre nuestros contenedores e imágenes.
![](Images/Day44_Containers16.png)
We have now run our first container. Nothing too scary just yet. What about if we wanted to pull one of the container images down from DockerHub? Maybe there is a `hello world` docker container we could use.
Ya hemos ejecutado nuestro primer contenedor. Nada demasiado aterrador todavía. ¿Y si quisiéramos bajar una de las imágenes de contenedor de DockerHub? Podemos usar un contenedor docker llamado `hello world` para comprobarlo.
I went ahead and stopped the getting started container not that it's taking up any mass amount of resources but for tidiness, as we walk through some more steps.
Me adelanté y detuve el contenedor de inicio, no es que esté ocupando una cantidad masiva de recursos, sino para mantener un orden mientras vemos algunos pasos más.
Back in our terminal let's go ahead and run `docker run hello-world` and see what happens.
De vuelta en nuestro terminal vamos a seguir adelante y ejecutar `docker run hello-world` y a ver qué pasa.
You can see we did not have the image locally so we pulled that down and then we got a message that is written into the container image with some information on what it did to get up and running and some links to reference points.
Puedes ver que no teníamos la imagen localmente así que la bajamos y entonces tenemos un mensaje que está escrito en la imagen del contenedor con alguna información sobre lo que hizo para ponerse en marcha y algunos enlaces a puntos de referencia.
![](Images/Day44_Containers17.png)
However, if we go and look in Docker Desktop now we have no running containers but we do have an exited container that used the hello-world message, meaning it came up, delivered the message and then is terminated.
Sin embargo, si vamos y miramos en Docker Desktop ahora no tenemos ningún contenedor en ejecución, pero sí tenemos un contenedor que utilizó el mensaje hola-mundo, lo que significa que apareció, entregó el mensaje y luego se terminó.
![](Images/Day44_Containers18.png)
And for the last time, let's just go and check the images tab and see that we have a new hello-world image locally on our system, meaning that if we run the `docker run hello-world` command again in our terminal we would not have to pull anything unless a version changes.
Y para terminar vamos a comprobar la pestaña images de nuevo en la que tendremos una nueva imagen hello-world localmente, lo que significa que si ejecutamos de nuevo el comando `docker run hello-world` en nuestro terminal no tendríamos que descargar nada a menos de que cambie la versión.
![](Images/Day44_Containers19.png)
The message from the hello-world container set down the challenge of running something a little more ambitious.
El mensaje del contenedor hello-world nos planteó el reto de ejecutar algo un poco más ambicioso.
Challenge Accepted!
¡Reto aceptado!
![](Images/Day44_Containers20.png)
In running `docker run -it ubuntu bash` in our terminal we are going to run a containerised version of Ubuntu well not a full copy of the Operating system. You can find out more about this particular image on [DockerHub](https://hub.docker.com/_/ubuntu)
Al ejecutar `docker run -it ubuntu bash` en nuestro terminal vamos a ejecutar una versión en un contenedor de Ubuntu, que no es una copia completa del sistema operativo. Puedes encontrar más información sobre esta imagen en particular en [DockerHub](https://hub.docker.com/_/ubuntu)
You can see below when we run the command we now have an interactive prompt (`-it`) and we have a bash shell into our container.
Puedes ver a continuación cuando ejecutamos el comando que ahora tenemos un símbolo del sistema interactivo (`-it`) y tenemos un shell bash en nuestro contenedor.
![](Images/Day44_Containers21.png)
We have a bash shell but we don't have much more which is why this container image is less than 30MB.
Tenemos una shell bash pero no tenemos mucho más, piensa que la imagen de este contenedor pesa menos de 30MB.
![](Images/Day44_Containers22.png)
But we can still use this image and we can still install software using our apt package manager, we can update our container image and upgrade also.
Pero con esta imagen podemos, por ejemplo:
- Instalar todo el software que necesitemos usando nuestro gestor de paquetes apt.
- Actualizar nuestra imagen de contenedor
- Crear un nuevo contenedor a partir de esta imagen
- Utilizar el contenedor interactivo para pruebas.
Y todo lo que imaginemos.
![](Images/Day44_Containers23.png)
Or maybe we want to install some software into our container, I have chosen a really bad example here as pinta is an image editor and it's over 200MB but hopefully you get where I am going with this. This would increase the size of our container considerably but still, we are going to be in the MB and not in the GB.
He instalado algún software en el contenedor, he elegido un ejemplo muy malo aquí ya que `pinta` es un editor de imágenes de más de 200 MB, pero espero que entiendas a dónde voy con esto. Esto aumentaría el tamaño de nuestro contenedor considerablemente pero aún así, vamos a estar en unos MB sin llegar al GB.
![](Images/Day44_Containers24.png)
I wanted that to hopefully give you an overview of Docker Desktop and the not-so-scary world of containers when you break it down with simple use cases, we do need to cover some networking, security and other options we have vs just downloading container images and using them like this. By the end of the section, we want to have made something and uploaded it to our DockerHub repository and be able to deploy it.
Quería que esto te diera una visión general de Docker Desktop y el mundo no tan aterrador de los contenedores cuando lo desglosas con casos de uso simples. Ahora tenemos que ver algo de redes, de seguridad y otras opciones mínimas que necesitamos de base.
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
See you on [Day 45](day45.md)
Nos vemos en el [Día 45](day45.md)

View File

@ -1,66 +1,67 @@
## The anatomy of a Docker Image
## La anatomía de una imagen Docker
In the last session, we covered some basics of how we can use Docker Desktop combined with DockerHub to deploy and run some verified images. A recap on what an image is, you won't forget things if I keep mentioning them.
En la última sesión, vimos algunos aspectos básicos de cómo podemos utilizar Docker Desktop combinado con DockerHub para desplegar y ejecutar algunas imágenes verificadas. Una recapitulación sobre lo que es una imagen, no olvidarás cosas si sigo mencionándolas.
A Docker image is a read-only template that contains a set of instructions for creating a container that can run on the Docker platform. It provides a convenient way to package up applications and preconfigured server environments, which you can use for your private use or share publicly with other Docker users. Docker images are also the starting point for anyone using Docker for the first time.
Una imagen Docker es una plantilla de sólo lectura que contiene un conjunto de instrucciones para crear un contenedor que se puede ejecutar en la plataforma Docker. Proporciona una forma práctica de empaquetar aplicaciones y entornos de servidor preconfigurados, que puedes utilizar para tu uso privado o compartir públicamente con otros usuarios de Docker. Las imágenes Docker son también el punto de partida para cualquiera que utilice Docker por primera vez.
What happens if we want to create our own Docker image? For us to do this we would create a Dockerfile. You saw how we could take that Ubuntu container image and we could add our software and we would have our container image with the software that we wanted and everything is good, however, if that container is shut down or thrown away then all those software updates and installations go away there is no repeatable version of what we had done. So that is great for showing off the capabilities but it doesn't help with the transport of images across multiple environments with the same set of software installed each time the container is run.
¿Qué ocurre si queremos crear nuestra propia imagen Docker? Para ello crearíamos un Dockerfile. Ya viste cómo podríamos tomar esa imagen de contenedor Ubuntu y añadir nuestro software. Con lo que tendríamos nuestra imagen de contenedor con el software que queremos, sin embargo, si ese contenedor se apaga o se destruye todas esas actualizaciones de software y las instalaciones desaparecen, perdemos los cambios sin una versión repetible. Así que eso es genial para mostrar las capacidades, pero no ayuda con el transporte de imágenes a través de múltiples entornos con el mismo conjunto de software instalado cada vez que se ejecuta el contenedor, que es la potencia de docker.
### What is a Dockerfile
### ¿Qué es un Dockerfile?
A dockerfile is a text file that contains commands you would normally execute manually to build a docker image. Docker can build images automatically by reading the instructions we have in our dockerfile.
Un dockerfile es un archivo de texto que contiene comandos que normalmente ejecutarías manualmente para construir una imagen docker. Docker puede construir imágenes automáticamente leyendo las instrucciones que tenemos en nuestro dockerfile.
Each of the files that make up a docker image is known as a layer. these layers form a series of images, built on top of each other in stages. Each layer is dependent on the layer immediately below it. The order of your layers is key to the efficiency of the lifecycle management of your docker images.
Cada uno de los archivos que componen una imagen docker se conoce como una capa. Estas capas forman una serie de imágenes, construidas unas sobre otras por etapas. Cada capa depende de la capa inmediatamente inferior. El orden de tus capas es clave para la eficiencia de la gestión del ciclo de vida de tus imágenes docker.
We should organise our layers that change most often as high in the stack as possible, this is because when you make changes to a layer in your image, Docker not only rebuilds that particular layer but all layers built from it. Therefore a change to a layer at the top involves the least amount of work to rebuild the entire image.
Debemos organizar nuestras capas que cambian más a menudo lo más alto posible en la pila, esto se debe a que cuando se realizan cambios en una capa de la imagen, Docker no sólo reconstruye esa capa en particular, sino todas las capas construidas a partir de ella. Por lo tanto, un cambio en una capa en la parte superior implica la menor cantidad de trabajo para reconstruir toda la imagen.
Each time docker launches a container from an image (like we ran yesterday) it adds a writeable layer, known as the container layer. This stores all changes to the container throughout its runtime. This layer is the only difference between a live operational container and the source image itself. Any number of like-for-like containers can share access to the same underlying image while maintaining their state.
Cada vez que docker lanza un contenedor desde una imagen (como hicimos ayer) añade una capa escribible, conocida como la capa del contenedor. Esto almacena todos los cambios en el contenedor a lo largo de su tiempo de ejecución. Esta capa es la única diferencia entre un contenedor operativo en vivo y la propia imagen de origen. Cualquier número de contenedores similares pueden compartir el acceso a la misma imagen subyacente, manteniendo su estado.
Back to the example, we used yesterday with the Ubuntu image. We could run that same command multiple times and on the first container we could go and install pinta and on the second we could install figlet with two different applications, different purposes, different sizes etc. Each container that we deployed shares the same image but not the same state and then that state is then gone when we remove the container.
Volviendo al ejemplo que utilizamos ayer con la imagen de Ubuntu. Podríamos ejecutar ese mismo comando múltiples veces y en el primer contenedor podríamos instalar pinta y en el segundo podríamos instalar figlet con dos aplicaciones diferentes, diferentes propósitos, diferentes tamaños, etc. Cada contenedor que desplegamos comparte la misma imagen pero no el mismo estado y luego ese estado desaparece cuando eliminamos el contenedor.
![](Images/Day45_Containers1.png)
Following the example above with the Ubuntu image, but also many other ready-built container images available on DockerHub and other third-party repositories. These images are generally known as the parent image. It is the foundation upon which all other layers are built and provides the basic building blocks for our container environments.
Estas imágenes se conocen generalmente como la imagen padre. Es la base sobre la que se construyen todas las demás capas y proporciona los bloques de construcción básicos para nuestros entornos de contenedores.
Together with a set of individual layer files, a Docker image also includes an additional file known as a manifest. This is essentially a description of the image in JSON format and comprises information such as image tags, a digital signature, and details on how to configure the container for different types of host platforms.
Junto con un conjunto de archivos de capas individuales, una imagen Docker también incluye un archivo adicional conocido como manifiesto. Se trata básicamente de una descripción de la imagen en formato JSON y contiene información como las etiquetas de la imagen, una firma digital y detalles sobre cómo configurar el contenedor para distintos tipos de plataformas host.
![](Images/Day45_Containers2.png)
### How to create a docker image
### Cómo crear una imagen docker
There are two ways we can create a docker image. We can do it a little on the fly with the process that we started yesterday, we pick our base image spin up that container, and install all of the software and dependencies that we wish to have on our container.
Hay dos maneras en que podemos crear una imagen docker. Podemos hacerlo un poco sobre la marcha con el proceso que empezamos ayer, elegimos nuestra imagen base, giramos ese contenedor e instalamos todo el software y las dependencias que deseamos tener en nuestro contenedor.
Then we can use the `docker commit container name` then we have a local copy of this image under docker images and in our docker desktop images tab.
Luego podemos usar el `docker commit container name` entonces tenemos una copia local de esta imagen bajo docker images y en nuestra pestaña docker desktop images.
Super simple, I would not recommend this method unless you want to understand the process, it is going to be very difficult to manage lifecycle management this way and a lot of manual configuration/reconfiguration. But it is the quickest and most simple way to build a docker image. Great for testing, troubleshooting, validating dependencies etc.
Con este método no entenderás el proceso y será muy difícil manejar la gestión del ciclo de vida, además de tener un montón de configuraciones manuales/reconfiguraciones. Pero se entiende que es la forma más rápida y sencilla de construir una imagen docker. Aunque no sea recomendable puede resultar ideal para pruebas, resolución de problemas, validación de dependencias, etc.
The way we intend to build our image is through a dockerfile. Which gives us a clean, compact and repeatable way to create our images. Much easier lifecycle management and easy integration into Continous Integration and Continuous delivery processes. But as you might gather it is a little more difficult than the first mentioned process.
La mejor práctica de construir imágenes es a través de un dockerfile. Lo que nos da una forma limpia, compacta y repetible para crear nuestras imágenes con unas pocas líneas. La gestión del ciclo de vida es mucho más fácil, así como la integración en procesos de CI/CD. Pero como se puede deducir, implica un aprendizaje. El saber no ocupa lugar.
Using the dockerfile method is much more in tune with real-world, enterprise-grade container deployments.
El uso del método dockerfile está mucho más en sintonía con el mundo real, los despliegues de contenedores de nivel empresarial.
A dockerfile is a three-step process whereby you create the dockerfile and add the commands you need to assemble the image.
Un dockerfile es un proceso de tres pasos mediante el cual se crea el dockerfile y se añaden los comandos necesarios para montar la imagen.
The following table shows some of the dockerfile statements we will be using or that you will most likely be using.
La siguiente tabla muestra algunas de las sentencias dockerfile que utilizaremos o que probablemente necesitarás.
| Command | Purpose |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| FROM | To specify the parent image. |
| WORKDIR | To set the working directory for any commands that follow in the Dockerfile. |
| RUN | To install any applications and packages required for your container. |
| COPY | To copy over files or directories from a specific location. |
| ADD | As COPY, but also able to handle remote URLs and unpack compressed files. |
| ENTRYPOINT | Command that will always be executed when the container starts. If not specified, the default is /bin/sh -c |
| CMD | Arguments passed to the entrypoint. If ENTRYPOINT is not set (defaults to /bin/sh -c), the CMD will be the commands the container executes. |
| EXPOSE | To define which port through which to access your container application. |
| LABEL | To add metadata to the image. |
| Comando | Propósito |
| ---------- | --------------------------------------------------------------------------------------------------------------------------- |
| FROM | Para especificar la imagen base. |
| WORKDIR | Para establecer el directorio de trabajo para cualquier comando que siga en el Dockerfile. |
| RUN | Para instalar las aplicaciones y paquetes necesarios para su contenedor. |
| COPY | Para copiar archivos o directorios desde una ubicación específica. |
| ADD | Como COPY, pero también capaz de manejar URLs remotas y desempaquetar archivos comprimidos. |
| ENTRYPOINT | Comando que se ejecutará siempre cuando se inicie el contenedor. Si no se especifica, el valor por defecto es `/bin/sh -c` |
| CMD | Argumentos pasados al punto de entrada. Si no se establece ENTRYPOINT, el CMD serán los comandos que ejecute el contenedor. |
| EXPOSE | Para definir el puerto a través del cual acceder a su aplicación contenedora. |
| LABEL | Para añadir metadatos a la imagen. |
Now we have the detail on how to build our first dockerfile we can create a working directory and create our dockerfile. I have created a working directory within this repository where you can see the files and folders I have to walk through. [Containers](Containers)
Con estos detalles ya podemos crear un directorio de trabajo para construir el primer dockerfile. En este repositorio puedes encontrar el directorio de trabajo con los archivos y carpetas que veremos: [Containers](Containers)
In this directory, I am going to create a .dockerignore file similar to the .gitignore we used in the last section. This file will list any files that would otherwise be created during the Docker build process, which you want to exclude from the final build.
En este directorio tendré el archivo `.dockerignore` que es similar al `.gitignore`, ¿Lo recuerdas?. Este archivo enumerará todos los archivos que se desean excluir en el proceso de construcción de Docker, para evitarlos en la construcción final.
Remember everything about containers is about being compact, as fast as possible with no bloat.
Recuerda, en la creación de los contenedores es importante ser compacto, tan rápido como sea posible sin bloat (código hinchado).
Así que haremos un Dockerfile muy simple con el siguiente diseño:
I want to create a very simple Dockerfile with the below layout also can be found in the folder linked above.
```
# Use the official Ubuntu 18.04 as base
@ -71,33 +72,33 @@ RUN apt-get install -y nginx curl
RUN rm -rf /var/lib/apt/lists/*
```
Navigate to this directory in your terminal, and then run `docker build -t 90daysofdevops:0.1 .` we are using the `-t` and then setting an image name and tag.
Es importante que le fichero se llame `Dockerfile` para que docker lo pueda reconocer. Cuando lo tengas ejecuta `docker build -t 90daysofdevops:0.1 .`. Fíjate que usamos el punto para que busque el Dockerfile en el directorio donde estamos ubicados. Con el anterior comando estamos usando la `-t` y luego estableciendo un nombre de imagen y una etiqueta.
![](Images/Day45_Containers3.png)
Now we have created our image we can then go and run our image using Docker Desktop or we could use the docker command line. I have used Docker Desktop I have fired up a container and you can see that we have `curl` available to us in the cli of the container.
Ahora que hemos creado nuestra imagen podemos ir y ejecutar nuestra imagen utilizando Docker Desktop o podríamos utilizar la línea de comandos docker. He utilizado Docker Desktop, he lanzado un contenedor y puedes ver que tenemos `curl` disponible para nosotros en el cli del contenedor.
![](Images/Day45_Containers4.png)
Whilst in Docker Desktop there is also the ability to leverage the UI to do some more tasks with this new image.
Mientras que en Docker Desktop también existe la posibilidad de aprovechar la interfaz de usuario para hacer algunas tareas más con esta nueva imagen.
![](Images/Day45_Containers5.png)
We can inspect our image, in doing so you see very much of the dockerfile and the lines of code that we wanted to run within our container.
Podemos inspeccionar nuestra imagen, al hacerlo se ve gran parte del dockerfile y las líneas de código que queríamos ejecutar dentro de nuestro contenedor.
![](Images/Day45_Containers6.png)
We have a pull option, now this would fail for us because this image is not hosted anywhere so we would get that as an error. However, we do have a Push to hub which would enable us to push our image to DockerHub.
Tenemos una opción pull, ahora esto fallaría porque la imagen no está alojada en ningún lugar por lo que obtendríamos un error. Sin embargo, tenemos una opción Push al hub que nos permitiría enviar nuestra imagen a nuestro registro DockerHub.
If you are using the same `docker build` we ran earlier then this would not work either, you would need the build command to be `docker build -t {{username}}/{{imagename}}:{{version}}`
Si estás usando el mismo `docker build` que ejecutamos antes, esto tampoco funcionaría, necesitarías que el comando de compilación fuera `docker build -t {{username}}/{{imagename}}:{{version}}`.
![](Images/Day45_Containers7.png)
Then if we go and take a look in our DockerHub repository you can see that we just pushed a new image. Now in Docker Desktop, we would be able to use that pull tab.
A continuación, si echamos un vistazo a nuestro repositorio DockerHub se puede ver que acabamos de subir una nueva imagen. Ahora en Docker Desktop, seríamos capaces de utilizar la pestaña pull.
![](Images/Day45_Containers8.png)
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
@ -105,5 +106,10 @@ Then if we go and take a look in our DockerHub repository you can see that we ju
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [Blog on gettng started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
See you on [Day 46](day46.md)
Nos vemos en el [Día 46](day46.md)

View File

@ -1,42 +1,40 @@
## Docker Compose
The ability to run one container could be great if you have a self-contained image that has everything you need for your single use case, where things get interesting is when you are looking to build multiple applications between different container images. For example, if I had a website front end but required a backend database I could put everything in one container but better and more efficient would be to have its container for the database.
La capacidad de ejecutar un contenedor puede ser muy grande si tienes una imagen auto-contenida que tiene todo lo que necesita para su caso de uso único. Donde las cosas se ponen interesantes es cuando estás buscando construir múltiples aplicaciones entre diferentes imágenes de contenedores. Por ejemplo, si tuvieras un sitio web front-end, pero requiere una base de datos back-end podría poner todo en un contenedor, aunque lo más eficiente es tener un contenedor propio para la base de datos.
This is where Docker compose comes in which is a tool that allows you to run more complex apps over multiple containers. With the benefit of being able to use a single file and command to spin up your application. The example I am going to the walkthrough in this post is from the [Docker QuickStart sample apps (Quickstart: Compose and WordPress)](https://docs.docker.com/samples/wordpress/).
Aquí es donde entra en juego Docker compose, una herramienta que permite ejecutar aplicaciones más complejas en varios contenedores. Con el beneficio de ser capaz de utilizar un único archivo y comando para hacer girar su aplicación. El ejemplo que voy a mostrar en este día es de [Docker QuickStart sample apps (Quickstart: Compose and WordPress)](https://docs.docker.com/samples/wordpress/).
In this first example we are going to:
Veremos cómo:
- Use Docker compose to bring up WordPress and a separate MySQL instance.
- Use a YAML file which will be called `docker-compose.yml`
- Build the project
- Configure WordPress via a Browser
- Shutdown and Clean up
- Usar Docker Compose para traer WordPress y una instancia separada de MySQL.
- Utilizar un archivo YAML que se llamará `docker-compose.yml`.
- Construir el proyecto
- Configurar WordPress a través de un navegador
- Apagar y limpiar
### Install Docker Compose
### Instalar Docker Compose
As mentioned Docker Compose is a tool, If you are on macOS or Windows then compose is included in your Docker Desktop installation. However, you might be wanting to run your containers on a Windows server host or Linux server and in which case you can install using these instructions [Install Docker Compose](https://docs.docker.com/compose/install/)
Como se ha mencionado Docker Compose es una herramienta, si estás en macOS o Windows entonces compose está incluido en tu instalación de Docker Desktop, así como en las últimas versiones de docker para linux. Sin embargo, es posible que desees ejecutar tus contenedores con una versión de docker más antigua, en cuyo caso puedes instalarlo siguiendo estas instrucciones [Install Docker Compose](https://docs.docker.com/compose/install/)
To confirm we have `docker-compose` installed on our system we can open a terminal and simply type the above command.
Para confirmar que tenemos `docker-compose` instalado en nuestro sistema podemos abrir un terminal y simplemente escribir el comando anterior. En la últimas versiones se está dejando de usar el guión medio: `docker compose`.
![](Images/Day46_Containers1.png)
### Docker-Compose.yml (YAML)
The next thing to talk about is the docker-compose.yml which you can find in the container folder of the repository. But more importantly, we need to discuss YAML, in general, a little.
Lo siguiente de lo que hablar es de como construir el fichero docker-compose.yml, pero realmente es más importante de que hablemos un poco de YAML, en general.
YAML could almost have its session as you are going to find it in so many different places. But for the most part
YAML casi podría tener su propio día en #90DaysOfDevOps, ya que lo vas a encontrar en muchos lugares diferentes. Pero en general "YAML es un lenguaje de serialización de datos amigable para todos los lenguajes de programación", al igual que JSON o TOML.
"YAML is a human-friendly data serialization language for all programming languages."
Se utiliza habitualmente para archivos de configuración y en algunas aplicaciones en las que se almacenan o transmiten datos. Sin duda te habrás encontrado con archivos XML que suelen ofrecer ese mismo archivo de configuración. YAML proporciona una sintaxis mínima pero está orientado a esos mismos casos de uso.
It is commonly used for configuration files and in some applications where data is being stored or transmitted. You have no doubt come across XML files that tend to offer that same configuration file. YAML provides a minimal syntax but is aimed at those same use cases.
YAML no es un lenguaje de marcas, como se ha mencionado es un lenguaje de serialización y ha ido ganando popularidad en los últimos años. Las capacidades de serialización de objetos lo convierten en un sustituto viable de lenguajes como JSON.
YAML Ain't Markup Language (YAML) is a serialisation language that has steadily increased in popularity over the last few years. The object serialisation abilities make it a viable replacement for languages like JSON.
El acrónimo YAML era la abreviatura de Yet Another Markup Language. Pero los mantenedores lo renombraron a YAML Ain't Markup Language para poner más énfasis en sus características orientadas a los datos.
The YAML acronym was shorthand for Yet Another Markup Language. But the maintainers renamed it to YAML Ain't Markup Language to place more emphasis on its data-oriented features.
De todos modos, volvamos al archivo docker-compose.yml. Este es un archivo de configuración de lo que queremos hacer cuando se trata de múltiples contenedores que se despliegan en nuestro único sistema.
Anyway, back to the docker-compose.yml file. This is a configuration file of what we want to do when it comes to multiple containers being deployed on our single system.
Straight from the tutorial linked above you can see the contents of the file looks like this:
Directamente desde el tutorial vinculado anteriormente se puede ver el contenido del archivo se parece a esto:
```
version: "3.9"
@ -72,95 +70,93 @@ volumes:
wordpress_data: {}
```
We declare a version and then a large part of this docker-compose.yml file is made up of our services, we have a DB service and a WordPress service. You can see each of those has an image defined with a version tag associated. We are now also introducing state into our configuration unlike our first walkthroughs, but now we are going to create volumes so we can store our databases there.
Declaramos una versión y luego una gran parte de este archivo docker-compose.yml se compone de nuestros servicios, tenemos un servicio DB y un servicio de WordPress. Puedes ver que cada uno de ellos tiene una imagen definida con una etiqueta de versión asociada. Ahora también estamos introduciendo el estado en nuestra configuración a diferencia de nuestros primeros paseos, pero ahora vamos a crear volúmenes para que podamos almacenar nuestras bases de datos allí.
We then have some environmental variables such as passwords and usernames. These files can get very complicated but the YAML configuration file simplifies what these look like overall.
Luego tenemos algunas variables de entorno como contraseñas y nombres de usuario. Estos archivos pueden llegar a ser muy complicados, pero el archivo de configuración YAML simplifica su aspecto general.
### Build the project
### Construir el proyecto
Next up we can head back into our terminal and we can use some commands with our docker-compose tool. Navigate to your directory, where your docker-compose.yml file is located.
A continuación podemos volver a nuestro terminal y podemos utilizar algunos comandos con nuestra herramienta docker-compose. Asegurate de estar ubicado en el directorio donde se encuentra el archivo docker-compose.yml.
From the terminal, we can simply run `docker-compose up -d` this will start the process of pulling those images and standing up your multi-container application.
Desde el terminal, podemos simplemente ejecutar `docker-compose up -d` esto iniciará el proceso de extracción de las imágenes y la puesta en marcha de su aplicación multi-contenedor.
The `-d` in this command means detached mode, which means that the Run command is or will be in the background.
La `-d` en este comando significa modo separado, lo que significa que el comando Run estará en segundo plano.
![](Images/Day46_Containers2.png)
If we now run the `docker ps` command, you can see we have 2 containers running, one being WordPress and the other being MySQL.
Si ahora ejecutamos el comando `docker ps`, podemos ver que tenemos 2 contenedores ejecutándose, uno es WordPress y el otro es MySQL.
![](Images/Day46_Containers3.png)
Next, we can validate that we have WordPress up and running by opening a browser and going to `http://localhost:8000` and you should see the WordPress set-up page.
A continuación, podemos verificar que tenemos WordPress funcionando abriendo un navegador y yendo a `http://localhost:8000`. Deberías ver la página de configuración de WordPress.
![](Images/Day46_Containers4.png)
We can run through the setup of WordPress, and then we can start building our website as we see fit in the console below.
Podemos ejecutar la configuración de WordPress, y luego podemos empezar a construir nuestro sitio web como mejor nos parezca en la consola de abajo.
![](Images/Day46_Containers5.png)
If we then open a new tab and navigate to that same address we did before `http://localhost:8000` we will now see a simple default theme with our site title "90DaysOfDevOps" and then a sample post.
Si a continuación abrimos una nueva pestaña y navegamos a la misma dirección que antes `http://localhost:8000` veremos ahora un sencillo tema por defecto con el título de nuestro sitio "90DaysOfDevOps" y a continuación un post de ejemplo.
![](Images/Day46_Containers6.png)
Before we make any changes, open Docker Desktop and navigate to the volumes tab and here you will see two volumes associated with our containers, one for WordPress and one for DB.
Antes de hacer ningún cambio, abre Docker Desktop y navega hasta la pestaña de volúmenes y aquí verás dos volúmenes asociados a nuestros contenedores, uno para WordPress y otro para DB.
![](Images/Day46_Containers7.png)
My Current wordpress theme is "Twenty Twenty-Two" and I want to change this to "Twenty Twenty" Back in the dashboard we can make those changes.
Mi tema actual de wordpress es "Twenty Twenty-Two" y quiero cambiarlo por "Twenty Twenty". De vuelta en el dashboard podemos hacer esos cambios.
![](Images/Day46_Containers8.png)
I am also going to add a new post to my site, and here below you see the latest version of our new site.
También voy a añadir un nuevo post a mi sitio, y aquí abajo se ve la última versión de nuestro nuevo sitio.
![](Images/Day46_Containers9.png)
### Clean Up or not
### Limpiar o no limpiar
If we were now to use the command `docker-compose down` this would bring down our containers. But will leave our volumes in place.
Si ahora usáramos el comando `docker-compose down` esto bajaría nuestros contenedores. Pero dejará nuestros volúmenes en su sitio.
![](Images/Day46_Containers10.png)
We can just confirm in Docker Desktop that our volumes are still there though.
Podemos confirmar en Docker Desktop que nuestros volúmenes siguen ahí.
![](Images/Day46_Containers11.png)
If we then want to bring things back up then we can issue the `docker up -d` command from within the same directory and we have our application back up and running.
Si luego queremos volver a poner las cosas en marcha, podemos ejecutar el comando `docker up -d` desde el mismo directorio y ya tenemos nuestra aplicación de nuevo en marcha.
![](Images/Day46_Containers12.png)
We then navigate in our browser to that same address of `http://localhost:8000` and notice that our new post and our theme change are all still in place.
A continuación, navegamos en nuestro navegador a la misma dirección de `http://localhost:8000` y observamos que nuestro nuevo post y nuestro cambio de tema siguen en su lugar.
![](Images/Day46_Containers13.png)
If we want to get rid of the containers and those volumes then issuing the `docker-compose down --volumes` will also destroy the volumes.
Si queremos deshacernos de los contenedores y de esos volúmenes, al ejecutar `docker-compose down --volumes` también destruiremos los volúmenes.
![](Images/Day46_Containers14.png)
Now when we use `docker-compose up -d` again we will be starting, however, the images will still be local on our system so you won't need to re-pull them from the DockerHub repository.
Ahora cuando usemos `docker-compose up -d` de nuevo estaremos arrancando, sin embargo, las imágenes seguirán siendo locales en nuestro sistema por lo que no será necesario volver a extraerlas del repositorio de DockerHub.
I know that when I started diving into docker-compose and its capabilities I was then confused as to where this sits alongside or with Container Orchestration tools such as Kubernetes, well everything we have done here in this short demo is focused on one host we have WordPress and DB running on the local desktop machine. We don't have multiple virtual machines or multiple physical machines, we also can't easily scale up and down the requirements of our application.
Sé que cuando empecé a bucear en docker-compose y sus capacidades estaba confundido en cuanto las diferencias con otras herramientas de orquestación de contenedores como Kubernetes. Por ahora lo que hemos hecho en esta breve demostración se centra en un host que tenemos WordPress y DB se ejecuta en la máquina de escritorio local. No tenemos múltiples máquinas virtuales o múltiples máquinas físicas, tampoco podemos escalar fácilmente hacia arriba y hacia abajo los requisitos de nuestra aplicación.
Our next section is going to cover Kubernetes but we have a few more days of Containers in general first.
En la sección de Kubernetes despejaremos algunas dudas, por ahora tenemos algunos días más de Contenedores en general.
This is also a great resource for samples of docker-compose applications with multiple integrations. [Awesome-Compose](https://github.com/docker/awesome-compose)
Este es también un gran recurso para muestras de aplicaciones docker-compose con múltiples integraciones. [Awesome-Compose](https://github.com/docker/awesome-compose)
In the above repository, there is a great example which will deploy an Elasticsearch, Logstash, and Kibana (ELK) in single-node.
I have uploaded the files to the [Containers folder](2022/Days/Containers/elasticsearch-logstash-kibana/) When you have this folder locally, navigate there and you can simply use `docker-compose up -d`
En el repositorio hay un gran ejemplo que desplegará un Elasticsearch, Logstash, y Kibana (ELK) en single-node. Podrás encontrar los ficheros en la carpeta [Containers](2022/Days/Containers/elasticsearch-logstash-kibana/). Si tienes esta carpeta en local, tan solo navega hasta allí y usa `docker-compose up -d`.
![](Images/Day46_Containers15.png)
We can then check we have those running containers with `docker ps`
Podrás comprobar que tenemos esos contenedores en ejecución con `docker ps`. Estos mantendrán el mismo entorno que en mi pc.
![](Images/Day46_Containers16.png)
Now we can open a browser for each of the containers:
Ahora podemos abrir un navegador para cada uno de los contenedores:
![](Images/Day46_Containers17.png)
To remove everything we can use the `docker-compose down` command.
Como en la anterior práctica, para eliminar todo podemos usar el comando `docker-compose down`.
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
@ -169,5 +165,11 @@ To remove everything we can use the `docker-compose down` command.
- [Blog on getting started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
- [YAML Tutorial: Everything You Need to Get Started in Minute](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
- [Comparando TOML, JSON y YAML](https://vergaracarmona.es/comparando-toml-json-y-yaml/)
See you on [Day 47](day47.md)
Nos vemos en el [Día 47](day47.md)

View File

@ -1,92 +1,92 @@
## Docker Networking & Security
During this container session so far we have made things happen but we have not looked at how things have worked behind the scenes either from a networking point of view also we have not touched on security, that is the plan for this session.
Hasta ahora hemos visto como desplegar contenedores, pero no sabemos aún cómo funcionan las redes y cuál es la seguridad mínima que necesitan. Cómo bien anuncia el título, este es el plan de hoy.
### Docker Networking Basics
Open a terminal, and type the command `docker network` this is the main command for configuring and managing container networks.
Vamos al grano, abre un terminal y escribe el comando `docker network`. Este es el comando principal para configurar y gestionar redes de los contenedores.
From the below, you can see this is how we can use the command, and all of the sub-commands available. We can create new networks, list existing ones, and inspect and remove networks.
Puedes ver como podemos usar el comando y todos los sub-comandos disponibles. Podemos crear nuevas redes, listar las existentes, inspeccionarlas y eliminarlas.
![](Images/Day47_Containers1.png)
Let's take a look at the existing networks we have since our installation, so the out-of-box Docker networking looks like using the `docker network list` command.
Vamos a echar un vistazo a las redes existentes que tenemos desde nuestra instalación usando el comando `docker network list`.
Each network gets a unique ID and NAME. Each network is also associated with a single driver. Notice that the "bridge" network and the "host" network have the same name as their respective drivers.
Cada red tiene un ID y un NOMBRE únicos. Cada red también está asociada a un único controlador. Observa que la red "bridge" y la red "host" tienen el mismo nombre que sus respectivos controladores.
![](Images/Day47_Containers2.png)
Next, we can take a deeper look into our networks with the `docker network inspect` command.
A continuación, podemos echar un vistazo más profundo a nuestras redes con el comando `docker network inspect`.
With me running `docker network inspect bridge` I can get all the configuration details of that specific network name. This includes name, ID, drivers, connected containers and as you can see quite a lot more.
Si ejecuto `docker network inspect bridge` puedo obtener todos los detalles de configuración de ese nombre de red específico. Esto incluye nombre, ID, controladores, contenedores conectados y mucho más como puedes ver.
![](Images/Day47_Containers3.png)
### Docker: Bridge Networking
As you have seen above a standard installation of Docker Desktop gives us a pre-built network called `bridge` If you look back up to the `docker network list` command, you will see that the network called bridge is associated with the `bridge` driver. Just because they have the same name doesn't they are the same thing. Connected but not the same thing.
Como has visto arriba una instalación estándar de Docker Desktop nos da una red pre-construida llamada `bridge` Si vuelves a mirar el comando `docker network list`, verás que la red llamada bridge está asociada con el driver `bridge`. Que tengan el mismo nombre no quiere decir que sean la misma cosa. Están conectadas pero no son lo mismo.
The output above also shows that the bridge network is scoped locally. This means that the network only exists on this Docker host. This is true of all networks using the bridge driver - the bridge driver provides single-host networking.
La salida anterior también muestra que la red bridge tiene un ámbito local. Esto significa que la red sólo existe en este host Docker. Esto es cierto para todas las redes que utilizan el controlador bridge que proporciona la red de un solo host.
All networks created with the bridge driver are based on a Linux bridge (a.k.a. a virtual switch).
Todas las redes creadas con el controlador bridge se basan en un bridge Linux (también conocido como conmutador virtual).
### Connect a Container
### Conectar un Contenedor
By default the bridge network is assigned to new containers, meaning unless you specify a network all containers will be connected to the bridge network.
Por defecto la red bridge es asignada a los nuevos contenedores, lo que significa que a menos que especifiques una red todos los contenedores serán conectados a la red bridge.
Let's create a new container with the command `docker run -dt ubuntu sleep infinity`
Vamos a crear un nuevo contenedor con el comando `docker run -dt ubuntu sleep infinity`.
The sleep command above is just going to keep the container running in the background so we can mess around with it.
El comando sleep de arriba sólo va a mantener el contenedor funcionando en segundo plano para que podamos trastear con él.
![](Images/Day47_Containers4.png)
If we then check our bridge network with `docker network inspect bridge` you will see that we have a container matching what we have just deployed because we did not specify a network.
Si a continuación comprobamos nuestra red bridge con `docker network inspect bridge` veremos que tenemos un contenedor que coincide con lo que acabamos de desplegar porque no hemos especificado ninguna red.
![](Images/Day47_Containers5.png)
We can also dive into the container using `docker exec -it 3a99af449ca2 bash` you will have to use `docker ps` to get your container ID.
También podemos bucear en el contenedor usando `docker exec -it 3a99af449ca2 bash`, tendrás que usar `docker ps` para obtener el ID del contenedor que has creado.
From here our image doesn't have anything to ping so we need to run the following command.`apt-get update && apt-get install -y iputils-ping` then ping an external interfacing address. `ping -c5 www.90daysofdevops.com`
En principio, nuestra imagen no tiene nada con lo que hacer ping, así que tenemos que ejecutar el siguiente comando: `apt-get update && apt-get install -y iputils-ping`. Luego vamos a hacer ping a una dirección de interfaz externa, a ver que pasa: `ping -c5 www.90daysofdevops.com`
![](Images/Day47_Containers6.png)
To clear this up we can run `docker stop 3a99af449ca2` again and use `docker ps` to find your container ID but this will remove our container.
Ahora podemos parar el contenedor con `docker stop 3a99af449ca2` y utilizar `docker ps` para buscar su ID de contenedor, veremops que esto eliminará nuestro contenedor.
### Configure NAT for external connectivity
### Configurar NAT para conectividad externa
In this step, we'll start a new NGINX container and map port 8080 on the Docker host to port 80 inside of the container. This means that traffic that hits the Docker host on port 8080 will be passed on to port 80 inside the container.
En este paso, iniciaremos un nuevo contenedor NGINX y asignaremos el puerto 8080 en el host Docker al puerto 80 dentro del contenedor. Esto significa que el tráfico que llega al host Docker en el puerto 8080 pasará al puerto 80 dentro del contenedor.
Start a new container based on the official NGINX image by running `docker run --name web1 -d -p 8080:80 nginx`
Inicie un nuevo contenedor basado en la imagen oficial de NGINX ejecutando `docker run --name web1 -d -p 8080:80 nginx`.
![](Images/Day47_Containers7.png)
Review the container status and port mappings by running `docker ps`
Revise el estado del contenedor y las asignaciones de puertos ejecutando `docker ps`.
![](Images/Day47_Containers8.png)
The top line shows the new web1 container running NGINX. Take note of the command the container is running as well as the port mapping - `0.0.0.0:8080->80/tcp` maps port 8080 on all host interfaces to port 80 inside the web1 container. This port mapping is what effectively makes the container's web service accessible from external sources (via the Docker hosts IP address on port 8080).
La línea superior muestra el nuevo contenedor web1 ejecutando NGINX. Fíjate en el output del contenedor en la asignación de puertos - `0.0.0.0:8080->80/tcp`. Asigna el puerto 8080 en todas las interfaces del host al puerto 80 dentro del contenedor web1. Esta asignación de puertos es lo que hace que el servicio web del contenedor sea accesible desde fuentes externas (a través de la dirección IP de los hosts Docker en el puerto 8080).
Now we need our IP address for our actual host, we can do this by going into our WSL terminal and using the `IP addr` command.
Ahora necesitamos nuestra dirección IP para nuestro host anfitrión, podemos hacer esto yendo a nuestro terminal WSL y utilizando el comando `ip addr`.
![](Images/Day47_Containers9.png)
Then we can take this IP and open a browser and head to `http://172.25.218.154:8080/` Your IP might be different. This confirms that NGINX is accessible.
Entonces podemos tomar esta IP y abrir un navegador y dirigirnos a `http://172.25.218.154:8080/` (Ten en cuenta que tiene que se tu IP, seguramente sea diferente). Esto confirma que NGINX es accesible.
![](Images/Day47_Containers10.png)
I have taken these instructions from this site from way back in 2017 DockerCon but they are still relevant today. However, the rest of the walkthrough goes into Docker Swarm and I am not going to be looking into that here. [Docker Networking - DockerCon 2017](https://github.com/docker/labs/tree/master/dockercon-us-2017/docker-networking)
Estas instrucciones se han sacado de "Docker Networking - DockerCon 2017". Aun siendo de la DockerCon 2017 sigue estando vigente a día de hoy. En ese tutorial siguen explicando otros conceptos de redes incluyyendo Docker Swarm, pero no lo veremos aquí. No obstante, aquí tenéis el enlace por si queréis echarle un vistazo: [Docker Networking - DockerCon 2017](https://github.com/docker/labs/tree/master/dockercon-us-2017/docker-networking)
### Securing your containers
### Asegurando tus contenedores
Containers provide a secure environment for your workloads vs a full server configuration. They offer the ability to break up your applications into much smaller, loosely coupled components each isolated from one another which helps reduce the attack surface overall.
Los contenedores proporcionan un entorno seguro para las cargas de trabajo frente a una configuración de servidor completa. Ofrecen la capacidad de dividir aplicaciones en componentes mucho más pequeños y poco acoplados, cada uno aislado del otro, lo que ayuda a reducir la superficie de ataque en general.
But they are not immune from hackers that are looking to exploit systems. We still need to understand the security pitfalls of the technology and maintain best practices.
Pero no son inmunes a los hackers que buscan explotar los sistemas. Todavía tenemos que entender las trampas de seguridad de la tecnología y mantener las mejores prácticas.
### Move away from root permission
### Alejarse del permiso de root
All of the containers we have deployed have been using the root permission to the process within your containers. This means they have full administrative access to your container and host environments. Now to walk through we knew these systems were not going to be up and running for long. But you saw how easy it was to get up and running.
Todos los contenedores que hemos desplegado han estado utilizando el permiso root al proceso dentro de sus contenedores. Esto significa que tienen pleno acceso administrativo a su contenedor y entornos de acogida. Ahora a recorrer sabíamos que estos sistemas no iban a estar en funcionamiento por mucho tiempo. Pero ya has visto lo fácil que es ponerlo en marcha.
We can add a few steps to our process to enable non-root users to be our preferred best practice. When creating our dockerfile we can create user accounts. You can find this example also in the containers folder in the repository.
Podemos añadir algunos pasos a nuestro proceso para permitir que los usuarios no root sean quienes administren el contenedor, siguiendo así una buena práctica de seguridad. Al crear nuestro dockerfile podemos crear cuentas de usuario. Puedes encontrar este ejemplo también en la carpeta [containers](containers) del repositorio.
```
# Use the official Ubuntu 18.04 as base
@ -96,27 +96,27 @@ RUN groupadd -g 1000 basicuser && useradd -r -u 1000 -g basicuser basicuser
USER basicuser
```
We can also use `docker run --user 1009 ubuntu` the Docker run command overrides any user specified in your Dockerfile. Therefore, in the following example, your container will always run with the least privilege—provided user identifier 1009 also has the lowest permission level.
También podemos usar `docker run --user 1009 ubuntu` el comando Docker run anula cualquier usuario especificado en tu Dockerfile. Por lo tanto, en el siguiente ejemplo, su contenedor siempre se ejecutará con el identificador de usuario 1009 con menos privilegios, con un nivel de permisos más bajo.
However, this method doesnt address the underlying security flaw of the image itself. Therefore its better to specify a non-root user in your Dockerfile so your containers always run securely.
Sin embargo, este método no aborda el fallo de seguridad subyacente de la propia imagen. Por lo tanto, es mejor especificar un usuario no root en tu Dockerfile para que tus contenedores siempre se ejecuten de forma segura.
### Private Registry
### Registro Privado
Another area we have used heavily in public registries in DockerHub, with a private registry of container images set up by your organisation means that you can host where you wish or there are managed services for this as well, but all in all, this gives you complete control of the images available for you and your team.
Hasta ahora hemos utilizado registros públicos en DockerHub. Con un registro privado de imágenes de contenedores establecido por la organización podremos evitar problemas de curiosos. Se puede alojar la imágen donde desees, existen registros OpenSources y también administrados por terceros. Esto da un control completo de las imágenes disponibles para el equipo de trabajo.
DockerHub is great to give you a baseline, but it's only going to be providing you with a basic service where you have to put a lot of trust into the image publisher.
DockerHub está muy bien para darte una base, pero sólo te va a proporcionar un servicio básico en el que tienes que confiar mucho en el editor de imágenes.
### Lean & Clean
### Liviano y limpio
Have mentioned this throughout, although not related to security. But the size of your container can also affect security in terms of attack surface if you have resources you do not use in your application then you do not need them in your container.
He mencionado esto en todo momento sin relacionarlo con la seguridad. Pero el tamaño del contenedor puede afectar a la seguridad en términos de superficie de ataque. Si tienes recursos que no usas en tu aplicación entonces no los necesitas en tu contenedor, los puedes eliminar.
This is also my major concern with pulling the `latest` images because that can bring a lot of bloat to your images as well. DockerHub does show the compressed size for each of the images in a repository.
Esta es mi mayor preocupación con la extracción de las imágenes `latest` porque eso puede traer un montón de bloat (hinchazón) a sus imágenes. DockerHub muestra el tamaño comprimido para cada una de las imágenes en un repositorio.
Checking `docker image` is a great command to see the size of your images.
En definitiva, busca siempre de que tus imágenes sean lo más pequeñas posibles. `docker image` es el comando para comprobar el tamaño de las imágenes en local.
![](Images/Day47_Containers11.png)
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
@ -125,5 +125,10 @@ Checking `docker image` is a great command to see the size of your images.
- [Blog on getting started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
- [YAML Tutorial: Everything You Need to Get Started in Minute](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
See you on [Day 48](day48.md)
Nos vemos en el [Día 48](day48.md)

View File

@ -1,96 +1,94 @@
## Alternatives to Docker
## Alternativas a Docker
I did say at the very beginning of this section that we were going to be using Docker, simply because resource wise there is so much and the community is very big, but also this was really where the indents to making containers popular came from. I would encourage you to go and watch some of the history around Docker and how it came to be, I found it very useful.
Dije al principio de esta sección que íbamos a usar Docker, simplemente porque tiene muchos recursos ya que la comunidad es muy grande, pero también porque fue de aquí de donde vinieron los impulsos para popularizar los contenedores. Te animo a que veas algo de la [historia de los contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/), me pareció muy útil para entender todos los conceptos que trae.
But as I have alluded to there are other alternatives to Docker. If we think about what Docker is and what we have covered. It is a platform for developing, testing, deploying, and managing applications.
Pero como he aludido existen alternativas a Docker si pensamos en lo que es Docker y de qué se ocupa: una plataforma para desarrollar, probar, desplegar y gestionar aplicaciones.
I want to highlight a few alternatives to Docker that you might or will in the future see out in the wild.
Quiero destacar algunas alternativas a Docker que podrías ver o verás en el futuro.
### Podman
What is Podman? Podman is a daemon-less container engine for developing, managing, and running OCI Containers on your Linux System. Containers can either be run as root or in rootless mode.
¿Qué es Podman? [Podman](https://podman.io/) es un motor de contenedores sin demonio para desarrollar, gestionar y ejecutar contenedores OCI en tu sistema Linux. Los contenedores se pueden ejecutar como root o en modo rootless.
I am going to be looking at this from a Windows point of view but know that like Docker there is no requirement for virtualisation there as it will use the underlying OS which is cannot do in the Windows world.
Al igual que Docker no hay ningún requisito para la virtualización, pero utilizará el sistema operativo subyacente y por eso no se puede ejecutar en Windows a pelo. Se puede ejecutar bajo WSL2 pero no es tan visual como la experiencia con Docker Desktop, que está hecho para quienes usan el ratón.
Podman can be run under WSL2 although not as sleek as the experience with Docker Desktop. There is also a Windows remote client where you can connect to a Linux VM where your containers will run.
My Ubuntu on WSL2 is the 20.04 release. Following the next steps will enable you to install Podman on your WSL instance.
También hay un cliente remoto de Windows donde se puede conectar a una máquina virtual Linux donde se ejecutarán los contenedores. Con el Ubuntu en WSL2 de la versión 20.04, siguiendo los siguientes pasos podrás instalar Podman en tu instancia WSL.
```Shell
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /" |
sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
```
Add the GPG Key
Para añadir la clave GPG:
```Shell
curl -L "https://download.opensuse.org/repositories/devel:/kubic:\
/libcontainers:/stable/xUbuntu_20.04/Release.key" | sudo apt-key add -
```
Run a system update and upgrade with the `sudo apt-get update && sudo apt-get upgrade` command. Finally, we can install podman using `sudo apt install podman`
Ejecute una actualización del sistema con `sudo apt-get update && sudo apt-get upgrade`. Por último, podemos instalar podman usando `sudo apt install podman`. Espero que os déis cuenta de la incomodidad que es usar un sistema operativo que no sea Linux para trabajar con contenedores. Suele pasar con la mayoría de aplicaciones de Sistemas o desarrollo. Así como hemos visto la optimización de los contenedores, deberéis tener en cuenta que el sistema operativo anfitrión también es importante.
We can now use a lot of the same commands we have been using for docker, note that we do not have that nice docker desktop UI. You can see below I used `podman images` and I have nothing after installation then I used `podman pull ubuntu` to pull down the ubuntu container image.
Ahora podemos utilizar muchos de los mismos comandos que hemos estado utilizando para docker. Como puedes ver a continuación, he utilizado `podman images` y no tengo nada después de la instalación. Luego, he utilizado `podman pull ubuntu` para bajar la imagen del contenedor ubuntu.
![](Images/Day48_Containers1.png)
We can then run our Ubuntu image using `podman run -dit ubuntu` and `podman ps` to see our running image.
Podemos ejecutar nuestra imagen de Ubuntu usando `podman run -dit ubuntu` y `podman ps` para ver nuestra imagen en ejecución.
![](Images/Day48_Containers2.png)
To then get into that container we can run `podman attach dazzling_darwin` your container name will most likely be different.
Para entrar en ese contenedor podemos ejecutar `podman attach dazzling_darwin` el nombre de tu contenedor seguramente será diferente.
![](Images/Day48_Containers3.png)
If you are moving from docker to podman it is also common to change your config file to have `alias docker=podman` that way any command you run with docker will use podman.
Si te estás moviendo de docker a podman también es común cambiar el archivo de configuración para tener `alias docker=podman` de esa manera cualquier comando que ejecute con docker utilizará podman.
### LXC
LXC is a containerisation engine that enables users again to create multiple isolated Linux container environments. Unlike Docker, LXC acts as a hypervisor for creating multiple Linux machines with separate system files, and networking features. Was around before Docker and then made a short comeback due to Docker's shortcomings.
LXC es un motor de contenedorización que permite a los usuarios crear múltiples entornos de contenedores Linux aislados. A diferencia de Docker, LXC actúa como un hipervisor para crear múltiples máquinas Linux con archivos de sistema separados, y características de red. Existió antes que Docker y volvió a aparecer debido a las deficiencias de Docker.
LXC is as lightweight though as docker and easily deployed.
Sin embargo, LXC es tan ligero como Docker y fácil de desplegar.
### Containerd
A standalone container runtime. Containerd brings simplicity and robustness as well as of course portability. Containerd was formerly a tool that runs as part of Docker container services until Docker decided to graduate its components into standalone components.
Un runtime de contenedor independiente. Containerd aporta simplicidad y robustez, así como, por supuesto, portabilidad. Containerd era antes una herramienta que se ejecutaba como parte de los servicios de contenedores Docker hasta que Docker decidió graduar sus componentes en componentes independientes.
A project in the Cloud Native Computing Foundation, placing it in the same class as popular container tools like Kubernetes, Prometheus, and CoreDNS.
Es un proyecto de la Cloud Native Computing Foundation, lo que lo sitúa en la misma clase que herramientas de contenedores populares como Kubernetes, Prometheus y CoreDNS. De hecho, a partir de la versión 1.11, Kubernetes utiliza containerd como su runtime de contenedor predeterminado mientras que antes era Docker.
### Other Docker tooling
### Otras herramientas Docker
We could also mention toolings and options around Rancher, and VirtualBox but we can cover them in more detail another time.
También podríamos mencionar herramientas y opciones alrededor de Rancher, y VirtualBox pero podemos cubrirlas en más detalle en otra ocasión.
[**Gradle**](https://gradle.org/)
- Build scans allow teams to collaboratively debug their scripts and track the history of all builds.
- Execution options give teams the ability to continuously build so that whenever changes are inputted, the task is automatically executed.
- The custom repository layout gives teams the ability to treat any file directory structure as an artefact repository.
- Las exploraciones de construcción permiten a los equipos depurar sus scripts de forma colaborativa y realizar un seguimiento del historial de todas las construcciones.
- Las opciones de ejecución dan a los equipos la capacidad de construir continuamente de modo que cada vez que se introducen cambios, la tarea se ejecuta automáticamente.
- El diseño personalizado del repositorio ofrece a los equipos la posibilidad de tratar cualquier estructura de directorios de archivos como un repositorio de artefactos.
[**Packer**](https://packer.io/)
- Ability to create multiple machine images in parallel to save developer time and increase efficiency.
- Teams can easily debug builds using Packers debugger, which inspects failures and allows teams to try out solutions before restarting builds.
- Support with many platforms via plugins so teams can customize their builds.
- Posibilidad de crear varias imágenes de máquina en paralelo para ahorrar tiempo a los desarrolladores y aumentar la eficacia.
- Los equipos pueden depurar fácilmente las compilaciones mediante el depurador de Packer, que inspecciona los fallos y permite a los equipos probar soluciones antes de reiniciar las compilaciones.
- Compatibilidad con muchas plataformas mediante plugins para que los equipos puedan personalizar sus compilaciones.
[**Logspout**](https://github.com/gliderlabs/logspout)
- Logging tool - The tools customizability allows teams to ship the same logs to multiple destinations.
- Teams can easily manage their files because the tool only requires access to the Docker socket.
- Completely open-sourced and easy to deploy.
- Herramienta de registro: la capacidad de personalización de la herramienta permite a los equipos enviar los mismos registros a varios destinos.
- Los equipos pueden gestionar fácilmente sus archivos porque la herramienta sólo requiere acceso al socket Docker.
- Completamente de código abierto y fácil de desplegar.
[**Logstash**](https://www.elastic.co/products/logstash)
- Customize your pipeline using Logstashs pluggable framework.
- Easily parse and transform your data for analysis and to deliver business value.
- Logstashs variety of outputs lets you route your data where you want.
- Personaliza tu pipeline utilizando el marco de trabajo pluggable de Logstash.
- Analice y transforme fácilmente sus datos para el análisis y para ofrecer valor empresarial.
- La variedad de salidas de Logstash le permite dirigir sus datos hacia donde desee.
[**Portainer**](https://www.portainer.io/)
- Utilise pre-made templates or create your own to deploy applications.
- Create teams and assign roles and permissions to team members.
- Know what is running in each environment using the tools dashboard.
- Utilice plantillas prediseñadas o cree las suyas propias para desplegar aplicaciones.
- Cree equipos y asigne funciones y permisos a sus miembros.
- Sepa qué se está ejecutando en cada entorno mediante el panel de control de la herramienta.
## Resources
## Recursos
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
@ -101,5 +99,10 @@ We could also mention toolings and options around Rancher, and VirtualBox but we
- [YAML Tutorial: Everything You Need to Get Started in Minute](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started)
- [Podman | Daemonless Docker | Getting Started with Podman](https://www.youtube.com/watch?v=Za2BqzeZjBk)
- [LXC - Guide to building an LXC Lab](https://www.youtube.com/watch?v=cqOtksmsxfg)
- [En español] En los [apuntes](https://vergaracarmona.es/apuntes/) del traductor:
- [Preparación de entorno de pruebas local para docker](https://vergaracarmona.es/preparacion-de-entorno-de-pruebas-local-para-docker/)
- [Uso básico de docker](https://vergaracarmona.es/uso-basico-de-docker/)
- [Una breve historia sobre contenedores](https://vergaracarmona.es/breve-historia-de-contenedores/)
- [Desplegar con docker-compose los servicios Traefik y Portainer](https://vergaracarmona.es/desplegar-con-docker-compose-los-servicios-traefik-y-portainer/)
See you on [Day 49](day49.md)
Nos vemos en el [Día 49](day49.md)

View File

@ -1,224 +1,199 @@
## The Big Picture: Kubernetes
## El panorama: Kubernetes
In the last section we covered Containers, Containers fall short when it comes to scale and orchestration alone. The best we can do is use docker-compose to bring up multiple containers together. When it comes to Kubernetes which is a Container Orchestrator, this gives us the ability to scale up and down in an automated way or based on a load of your applications and services.
En la última sección vimos los Contenedores. Los contenedores se quedan cortos cuando se trata de escalar y de orquestación, no pueden por sí solos. Lo mejor que podemos hacer es utilizar docker-compose para reunir varios contenedores. Cuando se trata de Kubernetes, que es un orquestador de contenedores, esto nos da la capacidad de escalar hacia arriba y hacia abajo de manera automatizada o basada en una carga de sus aplicaciones y servicios.
As a platform Kubernetes offers the ability to orchestrate containers according to your requirements and desired state. We are going to cover Kubernetes in this section as it is growing rapidly as the next wave of infrastructure. I would also suggest that from a DevOps perspective Kubernetes is just one platform that you will need to have a basic understanding of, you will also need to understand bare metal, virtualisation and most likely cloud-based services as well. Kubernetes is just another option to run our applications.
Como plataforma, Kubernetes ofrece la capacidad de orquestar contenedores de acuerdo a sus necesidades y el estado deseado. Vamos a cubrir Kubernetes en esta sección, ya que está creciendo rápidamente como la próxima ola de infraestructura. También me gustaría sugerir que, desde una perspectiva DevOps, Kubernetes es sólo una plataforma de las que tendrás que tener al menos un conocimiento básico. También tendrá que entender el bare metal, la virtualización y muy probablemente también los servicios basados en cloud. Kubernetes es sólo otra opción para ejecutar nuestras aplicaciones y se puede aplicar en estás dos mencionadas.
### What is Container Orchestration?
### ¿Qué es la orquestación de contenedores?
I have mentioned Kubernetes and I have mentioned Container Orchestration, Kubernetes is the technology whereas container orchestration is the concept or the process behind the technology. Kubernetes is not the only Container Orchestration platform we also have Docker Swarm, HashiCorp Nomad and others. But Kubernetes is going from strength to strength so I want to cover Kubernetes but wanted to say that it is not the only one out there.
He mencionado Kubernetes y he mencionado orquestación de contenedores, Kubernetes es la tecnología mientras que la orquestación de contenedores es el concepto o el proceso detrás de esta tecnología. Kubernetes no es la única plataforma de orquestación de contenedores, también tenemos las mencionadas anteriormente docker compose y Docker Swarm, o otras como HashiCorp Nomad. Pero Kubernetes va viento en popa, es la más utilizada, así que nos centraremos en ella.
### What is Kubernetes?
### ¿Qué es Kubernetes?
The first thing you should read if you are new to Kubernetes is the official documentation, My experience of really deep diving into Kubernetes a little over a year ago was that this is going to be a steep learning curve. Coming from a virtualisation and storage background I was thinking about how daunting this felt.
Lo primero que debes leer si eres nuevo en Kubernetes es la documentación oficial, es el mejor tutorial para aprender y además la van utilizando con más ejemplos o nuevas implementaciones. Mi experiencia de buceo realmente profundo en Kubernetes fue una curva de aprendizaje empinada. Viniendo de un fondo de virtualización y almacenamiento pensaba en lo desalentador que esto se sentía, pero el camino se hace al andar.
But the community, free learning resources and documentation are amazing. [Kubernetes.io](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
La comunidad, los recursos de aprendizaje gratuitos y la documentación son increíbles, no dejes de empaparte en ella: [Kubernetes.io](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
_Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available._
Ahora al pastel. Kubernetes es una plataforma portátil, extensible y de código abierto para gestionar cargas de trabajo y servicios en contenedores. Facilita tanto la configuración declarativa como la automatización. Cuenta con un ecosistema amplio y de rápido crecimiento. Los servicios, el soporte y las herramientas de Kubernetes están ampliamente disponibles.
Important things to note from the above quote, Kubernetes is Open-Source with a rich history that goes back to Google who donated the project to the Cloud Native Computing Foundation (CNCF) and it has now been progressed by the open-source community as well as large enterprise vendors contributing to making Kubernetes what it is today.
Cosas importantes a tener en cuenta de la cita anterior, Kubernetes es de código abierto con una rica historia que se remonta a cuando Google donó el proyecto a la Cloud Native Computing Foundation (CNCF). Ahora está siendo desarrollado por la comunidad de código abierto, así como grandes proveedores empresariales que contribuyen a hacer Kubernetes lo que es hoy.
I mentioned above that containers are great and in the previous section, we spoke about how containers and container images have changed and accelerated the adoption of cloud-native systems. But containers alone are not going to give you the production-ready experience you need from your application. Kubernetes gives us the following:
Antes he mencionado que los contenedores son geniales y, en la sección anterior, hemos hablado de cómo los contenedores y las imágenes de contenedores han cambiado y acelerado la adopción de sistemas nativos de la nube. Pero los contenedores por sí solos no van a darte la experiencia lista para producción que necesitas de tu aplicación. Kubernetes nos proporciona estas soluciones:
- **Service discovery and load balancing** Kubernetes can expose a container using the DNS name or using their IP address. If traffic to a container is high, Kubernetes can load balance and distribute the network traffic so that the deployment is stable.
- **Descubrimiento de servicios y equilibrio de carga** - Kubernetes puede exponer un contenedor utilizando el nombre DNS o su dirección IP. Si el tráfico a un contenedor es alto, Kubernetes puede equilibrar la carga y distribuir el tráfico de red para que el despliegue sea estable.
- **Orquestación de almacenamiento** - Kubernetes permite montar automáticamente un sistema de almacenamiento de su elección, como almacenamiento local, proveedores de nubes públicas, etc.
- **Rollouts y rollbacks automatizados** - Puedes describir el estado deseado para los contenedores desplegados utilizando Kubernetes, y puedes cambiar el estado actual al estado deseado a un ritmo controlado. Por ejemplo, puedes automatizar Kubernetes para crear nuevos contenedores para su despliegue, eliminar los contenedores existentes y adoptar todos sus recursos al nuevo contenedor.
- **Empaquetado automático de contenedores** - Proporcionas a Kubernetes un clúster de nodos que pueda utilizar para ejecutar tareas en contenedores, indicas cuánta CPU y memoria (RAM) necesitas para cada contenedor y Kubernetes puede acomodar los contenedores en sus nodos para hacer el mejor uso de los recursos.
- **Auto-reparación** - Kubernetes reinicia los contenedores que fallan, reemplaza los contenedores, mata los contenedores que no responden a su chequeo de salud definido por el usuario y no los anuncia a los clientes hasta que estén listos para servir.
- **Gestión de secretos y configuración** - Kubernetes permite almacenar y gestionar información confidencial, como contraseñas, tokens OAuth y claves SSH. Puede desplegar y actualizar secretos y la configuración de la aplicación sin reconstruir sus imágenes de contenedor, y sin exponer secretos en la configuración de su pila.
- **Storage orchestration** Kubernetes allows you to automatically mount a storage system of your choice, such as local storage, public cloud providers, and more.
Kubernetes proporciona un marco para ejecutar sistemas distribuidos de forma resiliente.
- **Automated rollouts and rollbacks** You can describe the desired state for your deployed containers using Kubernetes, and it can change the actual state to the desired state at a controlled rate. For example, you can automate Kubernetes to create new containers for your deployment, remove existing containers and adopt all their resources to the new container.
La orquestación de contenedores gestiona el despliegue, la colocación y el ciclo de vida de los contenedores.
- **Automatic bin packing** You provide Kubernetes with a cluster of nodes that it can use to run containerized tasks. You tell Kubernetes how much CPU and memory (RAM) each container needs. Kubernetes can fit containers onto your nodes to make the best use of your resources.
También tiene muchas otras responsabilidades:
- **Self-healing** Kubernetes restarts containers that fail, replaces containers, kills containers that don't respond to your user-defined health check, and doesn't advertise them to clients until they are ready to serve.
- La gestión de clústeres federa hosts en un objetivo.
- La gestión de la programación distribuye los contenedores entre los nodos a través del programador.
- El descubrimiento de servicios sabe dónde se encuentran los contenedores y distribuye las solicitudes de los clientes entre ellos.
- La replicación garantiza la disponibilidad del número adecuado de nodos y contenedores para la carga de trabajo solicitada.
- La gestión de la salud detecta y reemplaza los contenedores y nodos no saludables.
- **Secret and configuration management** Kubernetes lets you store and manage sensitive information, such as passwords, OAuth tokens, and SSH keys. You can deploy and update secrets and application configuration without rebuilding your container images, and without exposing secrets in your stack configuration.
### Principales componentes de Kubernetes
Kubernetes provides you with a framework to run distributed systems resiliently.
Kubernetes es un orquestador de contenedores para aprovisionar, gestionar y escalar aplicaciones. Puede utilizarlo para gestionar el ciclo de vida de aplicaciones en contenedores en un clúster de nodos, que es una colección de máquinas de trabajo como VMs o máquinas físicas.
Container Orchestration manages the deployment, placement, and lifecycle of containers.
Es posible que sus aplicaciones necesiten muchos otros recursos para ejecutarse, como volúmenes, redes y secretos que pueden ayudarle a conectarse a bases de datos, comunicarse con back-ends con firewalls y proteger claves. Con Kubernetes, puede añadir estos recursos a su aplicación. Los recursos de infraestructura que sus aplicaciones necesitan que se gestionen de forma declarativa.
It also has many other responsibilities:
El paradigma clave de Kubernetes es su modelo declarativo. Usted proporciona el estado que desea y Kubernetes lo hace posible. Si necesita cinco instancias, no inicie cinco instancias separadas por su cuenta. En su lugar, le dice a Kubernetes que necesita cinco instancias, y Kubernetes reconcilia automáticamente el estado. Si algo sale mal con una de sus instancias y falla, Kubernetes aún conoce el estado que usted desea y crea instancias en un nodo disponible.
- Cluster management federates hosts into one target.
- Schedule management distributes containers across nodes through the scheduler.
- Service discovery knows where containers are located and distributes client requests across them.
- Replication ensures that the right number of nodes and containers are available for the requested workload.
- Health management detects and replaces unhealthy containers and nodes.
### Main Kubernetes Components
Kubernetes is a container orchestrator to provision, manage, and scale apps. You can use it to manage the lifecycle of containerized apps in a cluster of nodes, which is a collection of worker machines such as VMs or physical machines.
Your apps might need many other resources to run, such as volumes, networks, and secrets that can help you connect to databases, talk to firewalled back ends, and secure keys. With Kubernetes, you can add those resources to your app. Infrastructure resources that your apps need are managed declaratively.
The key paradigm of Kubernetes is its declarative model. You provide the state that you want and Kubernetes makes it happen. If you need five instances, you don't start five separate instances on your own. Instead, you tell Kubernetes that you need five instances, and Kubernetes automatically reconciles the state. If something goes wrong with one of your instances and it fails, Kubernetes still knows the state that you want and creates instances on an available node.
### Node
### Nodo
#### Control Plane
Every Kubernetes cluster requires a Control Plane node, the control plane's components make global decisions about the cluster (for example, scheduling), as well as detecting and responding to cluster events.
Cada clúster Kubernetes requiere un nodo de Control Plane, los componentes del Control Plane toman decisiones globales sobre el clúster, por ejemplo la programación, así como la detección y respuesta a los eventos del clúster.
![](Images/Day49_Kubernetes1.png)
#### Worker Node
A worker machine that runs Kubernetes workloads. It can be a physical (bare metal) machine or a virtual machine (VM). Each node can host one or more pods. Kubernetes nodes are managed by a control plane
Un Worker machine que ejecuta cargas de trabajo Kubernetes. Puede ser una máquina física (bare metal) o una máquina virtual (VM). Cada nodo puede alojar uno o más pods. Los nodos Kubernetes son gestionados por un plano de control.
![](Images/Day49_Kubernetes2.png)
There are other node types but I won't be covering them here.
Existen otros tipos de nodos pero no los trataré aquí.
#### kubelet
An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod.
Un agente que se ejecuta en cada nodo del clúster. Se asegura de que los contenedores se ejecutan en un Pod.
The kubelet takes a set of PodSpecs that are provided through various mechanisms and ensures that the containers described in those PodSpecs are running and healthy. The kubelet doesn't manage containers which were not created by Kubernetes.
El kubelet toma un conjunto de PodSpecs que se proporcionan a través de diversos mecanismos y se asegura de que los contenedores descritos en los PodSpecs se están ejecutando y en buen estado. El kubelet no gestiona contenedores que no hayan sido creados por Kubernetes.
![](Images/Day49_Kubernetes3.png)
#### kube-proxy
kube-proxy is a network proxy that runs on each node in your cluster, implementing part of the Kubernetes Service concept.
kube-proxy es un proxy de red que se ejecuta en cada nodo de su clúster, implementando parte del concepto de Servicio Kubernetes.
kube-proxy maintains network rules on nodes. These network rules allow network communication to your Pods from network sessions inside or outside of your cluster.
kube-proxy mantiene reglas de red en los nodos. Estas reglas de red permiten la comunicación de red a sus Pods desde sesiones de red dentro o fuera de su cluster.
kube-proxy uses the operating system packet filtering layer if there is one and it's available. Otherwise, kube-proxy forwards the traffic itself.
kube-proxy utiliza la capa de filtrado de paquetes del sistema operativo si existe y está disponible. De lo contrario, kube-proxy reenvía el tráfico por sí mismo.
![](Images/Day49_Kubernetes4.png)
#### Container runtime
The container runtime is the software that is responsible for running containers.
El container runtime es el software responsable de ejecutar los contenedores.
Kubernetes supports several container runtimes: Docker, containerd, CRI-O, and any implementation of the Kubernetes CRI (Container Runtime Interface).
Kubernetes soporta varios container runtime: Docker, containerd, CRI-O, y cualquier implementación del CRI (Container Runtime Interface) de Kubernetes.
![](Images/Day49_Kubernetes5.png)
### Cluster
A cluster is a group of nodes, where a node can be a physical machine or a virtual machine. Each of the nodes will have the container runtime (Docker) and will also be running a kubelet service, which is an agent that takes in the commands from the Master controller (more on that later) and a Proxy, that is used to proxy connections to the Pods from another component (Services, that we will see later).
Un cluster es un grupo de nodos, donde un nodo puede ser una máquina física o una máquina virtual. Cada uno de los nodos tendrá el tiempo de ejecución del contenedor (Docker) y también estará ejecutando un servicio kubelet, que es un agente que recibe los comandos del controlador Maestro (veremos más sobre esto más adelante) y un Proxy, que se utiliza para proxy conexiones a los Pods de otro componente (Servicios, que veremos más adelante).
Our control plane which can be made highly available will contain some unique roles compared to the worker nodes, the most important will be the kube API server, this is where any communication will take place to get information or push information to our Kubernetes cluster.
Nuestro control plane, que se puede hacer altamente disponible, contendrá algunos roles únicos en comparación con los nodos Workers, el más importante será el servidor API kube, aquí es donde cualquier comunicación se llevará a cabo para obtener información o enviar información a nuestro clúster Kubernetes.
#### Kube API-Server
#### Servidor API Kube
The Kubernetes API server validates and configures data for the API objects which include pods, services, replication controllers, and others. The API Server services REST operations and provide the frontend to the cluster's shared state through which all other components interact.
El servidor API de Kubernetes valida y configura los datos para los objetos API que incluyen pods, servicios, controladores de replicación y otros. El servidor API da servicio a las operaciones REST y proporciona el frontend al estado compartido del cluster a través del cual interactúan el resto de componentes.
#### Scheduler
#### Planificador (Scheduler)
The Kubernetes scheduler is a control plane process which assigns Pods to Nodes. The scheduler determines which Nodes are valid placements for each Pod in the scheduling queue according to constraints and available resources. The scheduler then ranks each valid Node and binds the Pod to a suitable Node.
El programador de Kubernetes es un proceso del control plane que asigna Pods a Nodos. El programador determina qué Nodos son válidos para cada Pod en la cola de programación de acuerdo con las restricciones y los recursos disponibles. A continuación, el planificador clasifica cada Nodo válido y vincula el Pod a un Nodo adecuado.
#### Controller Manager
#### Gestor de Controladores
The Kubernetes controller manager is a daemon that embeds the core control loops shipped with Kubernetes. In applications of robotics and automation, a control loop is a non-terminating loop that regulates the state of the system. In Kubernetes, a controller is a control loop that watches the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired state.
El gestor de controladores de Kubernetes es un demonio que incorpora los bucles de control centrales incluidos en Kubernetes. En aplicaciones de robótica y automatización, un bucle de control es un bucle no terminal que regula el estado del sistema. En Kubernetes, un controlador es un bucle de control que observa el estado compartido del cluster a través del apiserver y realiza cambios intentando mover el estado actual hacia el estado deseado.
#### etcd
Consistent and highly-available key value store used as Kubernetes' backing store for all cluster data.
Almacén de valores clave consistente y de alta disponibilidad utilizado como almacén de respaldo de Kubernetes para todos los datos del clúster.
![](Images/Day49_Kubernetes6.png)
#### kubectl
To manage this from a CLI point of view we have kubectl, kubectl interacts with the API server.
Para gestionar esto desde un punto de vista CLI tenemos kubectl, kubectl interactúa con el servidor API.
The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
La herramienta de línea de comandos de Kubernetes, kubectl, le permite ejecutar comandos contra clústeres Kubernetes. Puede utilizar kubectl para desplegar aplicaciones, inspeccionar y gestionar recursos de clúster y ver registros.
![](Images/Day49_Kubernetes7.png)
### Pods
A Pod is a group of containers that form a logical application. E.g. If you have a web application that is running a NodeJS container and also a MySQL container, then both these containers will be located in a single Pod. A Pod can also share common data volumes and they also share the same networking namespace. Remember that Pods are ephemeral and they could be brought up and down by the Master Controller. Kubernetes uses a simple but effective means to identify the Pods via the concepts of Labels (name values).
Un Pod es un grupo de contenedores que forman una aplicación lógica. Por ejemplo, si tienes una aplicación web que está ejecutando un contenedor NodeJS y también un contenedor MySQL, entonces ambos contenedores pueden estar ubicados en un único Pod, aunque no es lo aconsejable. Un Pod también puede compartir volúmenes de datos comunes y también comparten el mismo espacio de nombres de red. Recuerda que los Pods son efímeros y pueden ser subidos y bajados por el Controlador Maestro. Kubernetes utiliza un medio simple pero eficaz para identificar los Pods a través de los conceptos de Labels (nombre - valor).
- Pods handle Volumes, Secrets, and configuration for containers.
- Pods are ephemeral. They are intended to be restarted automatically when they die.
- Pods are replicated when the app is scaled horizontally by the ReplicationSet. Each Pod will run the same container code.
- Pods live on Worker Nodes.
Algunas características importantes de los Pods:
- Los Pods son la unidad más pequeña de Kubernetes.
- Los Pods manejan Volúmenes, Secretos y configuración para los contenedores.
- Los Pods son efímeros. Están pensados para reiniciarse automáticamente cuando mueren.
- Los Pods se replican cuando la aplicación se escala horizontalmente mediante el ReplicationSet. Cada Pod ejecutará el mismo código de contenedor.
- Los Pods viven en Nodos Workers.
- Los Pods pueden comunicarse entre sí usando localhost.
![](Images/Day49_Kubernetes8.png)
### Deployments
- You can just decide to run Pods but when they die they die.
Puedes decidir ejecutar Pods pero cuando mueren, mueren. Los Deployments son una forma de ejecutar Pods de forma continua. Los Deployments también le permiten actualizar una aplicación en ejecución sin tiempo de inactividad.
- A Deployment will enable your pod to run continuously.
- Deployments allow you to update a running app without downtime.
- Deployments also specify a strategy to restart Pods when they die
- Un Deployment permitirá que tu pod se ejecute continuamente.
- Los Deployments le permiten actualizar una aplicación en ejecución sin tiempo de inactividad.
- Los Deployments también especifican una estrategia para reiniciar Pods cuando mueren.
- Los Deployments son la forma recomendada de administrar Pods en producción.
- Los Deployments son una abstracción de alto nivel que maneja la creación de Pods y ReplicaSets.
- Los Deployments son declarativos, como todo en Kubernetes, esto significa que describe el estado deseado en su clúster y Kubernetes se encarga de cambiar el estado real para que coincida con el estado deseado.
![](Images/Day49_Kubernetes9.png)
### ReplicaSets
- The Deployment can also create the ReplicaSet
Como se ha comentado, el Deployment también puede crear el ReplicaSet. Un ReplicaSet es un objeto que define un conjunto de Pods idénticos. Un ReplicaSet garantiza que un número especificado de réplicas de un Pod se estén ejecutando en todo momento. Si hay demasiados Pods, el ReplicaSet eliminará los Pods adicionales. Si hay muy pocos Pods, el ReplicaSet creará más. Los ReplicaSets son la forma recomendada de administrar Pods en producción.
- A ReplicaSet ensures your app has the desired number of Pods
- ReplicaSets will create and scale Pods based on the Deployment
- Deployments, ReplicaSets, and Pods are not exclusive but can be
- Un ReplicaSet asegura que su aplicación tiene el número deseado de Pods
- Los ReplicaSets crearán y escalarán Pods basándose en el Deployment
- Los Deployments, ReplicaSets y Pods no son excluyentes, pero pueden ser
### StatefulSets
- Does your App require you to keep information about its state?
¿Necesita tu App mantener información sobre su estado? Por ejemplo, una base de datos necesita estado. Los StatefulSets son la forma de ejecutar aplicaciones que necesitan mantener un estado. Los StatefulSets son similares a los Deployments, pero tienen algunas diferencias importantes:
- A database needs state
- A StatefulSets Pods are not interchangeable.
- Each pod has a unique, persistent identifier that the controller maintains over any rescheduling.
- Los Pods de un StatefulSet no son intercambiables.
- Cada pod tiene un identificador único y persistente que el controlador mantiene por encima de cualquier reprogramación.
- Los Pods de un StatefulSet se crean en orden secuencial, uno a la vez.
- Los Pods de un StatefulSet tienen un nombre DNS estable y predecible. Mantienen el mismo nombre a través de las reprogramaciones.
- Los volúmenes pueden ser persistentes.
![](Images/Day49_Kubernetes10.png)
### DaemonSets
- DaemonSets are for continuous process
- They run one Pod per Node.
- Each new node added to the cluster gets a pod started
- Useful for background tasks such as monitoring and log collection
- Each pod has a unique, persistent identifier that the controller maintains over any rescheduling.
- Los DaemonSets son para procesos continuos que se ejecutan en todos los nodos. Un Pod por Nodo.
- Cada nuevo nodo añadido al cluster hace que se inicie un pod.
- Útiles para tareas en segundo plano como monitorización y recogida de logs.
- Cada pod tiene un identificador único y persistente que el controlador mantiene por encima de cualquier reprogramación.
![](Images/Day49_Kubernetes11.png)
### Services
### Servicios
- A single endpoint to access Pods
Características de los Servicios:
- Un único punto final para acceder a los Pods
- Una forma unificada de dirigir el tráfico a un cluster y eventualmente a una lista de Pods.
- Usando un Servicio, los Pods pueden ser subidos y bajados sin afectar a nada.
- Los Servicios pueden ser expuestos interna o externamente. También pueden ser expuestos en diferentes puertos.
- a unified way to route traffic to a cluster and eventually to a list of Pods.
- By using a Service, Pods can be brought up and down without affecting anything.
This is just a quick overview and notes around the fundamental building blocks of Kubernetes, we can take this knowledge and add in some other areas around Storage and Ingress to enhance our applications but we then also have a lot of choices on where our Kubernetes cluster runs. The next session will focus on those options on where can I run a Kubernetes cluster, whilst also exploring some specifics around Storage.
Esto es sólo una visión general rápida y notas sobre los bloques de construcción fundamentales de Kubernetes, podemos tomar este conocimiento y añadir en algunas otras áreas alrededor de almacenamiento y de entrada para mejorar nuestras aplicaciones, pero entonces también tenemos un montón de opciones sobre dónde se ejecuta nuestro clúster Kubernetes. La siguiente sesión se centrará en esas opciones sobre dónde se puede ejecutar un clúster Kubernetes, mientras que también exploraremos algunos detalles sobre el almacenamiento.
![](Images/Day49_Kubernetes12.png)
### What we will cover in the series on Kubernetes
- Kubernetes Architecture
- Kubectl Commands
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm Package Manager
- Persistent Storage
- Stateful Apps
## Resources
## Recursos
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
See you on [Day 50](day50.md)
Nos vemos en el [Día 50](day50.md)

View File

@ -1,42 +1,46 @@
## Choosing your Kubernetes platform
## Elegir tu plataforma Kubernetes
I wanted to use this session to break down some of the platforms or maybe distributions is a better term to use here, one thing that has been a challenge in the Kubernetes world is removing complexity.
En esta sesión se va a desglosar algunas de las plataformas o tal vez distribuciones es un mejor término a utilizar aquí. Una cosa que ha sido un reto en el mundo Kubernetes es eliminar la complejidad.
Kubernetes the hard way walks through how to build out from nothing to a full-blown functional Kubernetes cluster this is to the extreme but more and more at least the people I am speaking to are wanting to remove that complexity and run a managed Kubernetes cluster. The issue there is that it costs more money but the benefits could be if you use a managed service do you need to know the underpinning node architecture and what is happening from a Control Plane node point of view when generally you do not have access to this.
Kubernetes the hard way (el camino difícil) explica cómo construir desde la nada un clúster Kubernetes completamente funcional. Esto es extremo, pero cada vez más, al menos las personas con las que hablo, quieren eliminar esa complejidad y ejecutar un clúster Kubernetes gestionado. El problema es que cuesta más dinero, pero las ventajas podrían ser que, si se utiliza un servicio gestionado, es necesario conocer la arquitectura de los nodos y lo que ocurre desde el punto de vista del control plane, algo a lo que generalmente no se tiene acceso.
Then we have the local development distributions that enable us to use our systems and run a local version of Kubernetes so developers can have the full working environment to run their apps in the platform they are intended for.
Luego tenemos las distribuciones de desarrollo local que nos permiten utilizar nuestros sistemas y ejecutar una versión local de Kubernetes para que los desarrolladores puedan tener el entorno de trabajo completo para ejecutar sus aplicaciones en la plataforma para la que están destinadas.
The general basis of all of these concepts is that they are all a flavour of Kubernetes which means we should be able to freely migrate and move our workloads where we need them to suit our requirements.
La base general de todos estos conceptos es que todos son una variante de Kubernetes, lo que significa que deberíamos poder migrar y mover libremente nuestras cargas de trabajo donde las necesitemos para adaptarlas a nuestras necesidades.
A lot of our choice will also depend on what investments have been made. I mentioned the developer experience as well but some of those local Kubernetes environments that run our laptops are great for getting to grips with the technology without spending any money.
Gran parte de nuestra elección dependerá también de las inversiones realizadas. También he mencionado la experiencia de los desarrolladores, pero algunos de esos entornos locales de Kubernetes que ejecutan nuestros portátiles son estupendos para familiarizarse con la tecnología sin gastar dinero.
### Bare-Metal Clusters
### Clusters Bare-Metal
An option for many could be running your Linux OS straight onto several physical servers to create our cluster, it could also be Windows but I have not heard much about the adoption rate around Windows, Containers and Kubernetes. If you are a business and you have made a CAPEX decision to buy your physical servers then this might be how you go when building out your Kubernetes cluster, the management and admin side here means you are going to have to build yourself and manage everything from the ground up.
Una opción para muchos podría ser ejecutar su sistema operativo Linux directamente en varios servidores físicos para crear nuestro clúster, también podría ser Windows pero no he oído hablar mucho de la tasa de adopción en entornos Windows, puede ser anecdótica.
### Virtualisation
Si en tu empresa se ha tomado la decisión de CAPEX para comprar sus servidores físicos, entonces esto podría ser una forma en la que construir la arquitectura, un clúster Kubernetes. La gestión y administración de lado significa que la vas a tener que construir tu mismo y gestionarlo todo desde el principio.
Regardless of test and learning environments or enterprise-ready Kubernetes clusters virtualisation is a great way to go, typically the ability to spin up virtual machines to act as your nodes and then cluster those together. You have the underpinning architecture, efficiency and speed of virtualisation as well as leveraging that existing spend. VMware for example offers a great solution for both Virtual Machines and Kubernetes in various flavours.
### Virtualización
My first ever Kubernetes cluster was built based on Virtualisation using Microsoft Hyper-V on an old server that I had which was capable of running a few VMs as my nodes.
Independientemente de si se trata de entornos de prueba y aprendizaje o de clústeres Kubernetes listos para la funcionar, la virtualización es una gran opción, ya que permite crear máquinas virtuales que actúan como nodos y, a continuación, agruparlos en clústeres. Dispones de la arquitectura de apoyo, la eficiencia y la velocidad de la virtualización, además de aprovechar el gasto existente. VMware, por ejemplo, ofrece una gran solución tanto para máquinas virtuales como para Kubernetes en varias versiones.
### Local Desktop options
Mi primer clúster Kubernetes se construyó sobre la base de la virtualización utilizando Microsoft Hyper-V en un servidor antiguo que tenía que era capaz de ejecutar algunas máquinas virtuales como mis nodos. Esto me permitió construir un clúster Kubernetes y empezar a jugar con él.
There are several options when it comes to running a local Kubernetes cluster on your desktop or laptop. This as previously said gives developers the ability to see what their app will look like without having to have multiple costly or complex clusters. Personally, this has been one that I have used a lot and in particular, I have been using minikube. It has some great functionality and adds-ons which changes the way you get something up and running.
### Opciones de escritorio local
### Kubernetes Managed Services
Hay varias opciones cuando se trata de ejecutar un clúster local de Kubernetes en su ordenador de sobremesa o portátil. Esto, como se dijo anteriormente, ofrece a los desarrolladores la posibilidad de ver cómo se verá su aplicación sin tener que tener múltiples clústeres costosos o complejos. Personalmente, he utilizado mucho minikube. Tiene una gran funcionalidad y complementos que cambian la forma de poner algo en marcha.
I have mentioned virtualisation, and this can be achieved with hypervisors locally but we know from previous sections we could also leverage VMs in the public cloud to act as our nodes. What I am talking about here with Kubernetes managed services are the offerings we see from the large hyperscalers but also from MSPs removing layers of management and control away from the end user, this could be removing the control plane from the end user this is what happens with Amazon EKS, Microsoft AKS and Google Kubernetes Engine. (GKE)
### Servicios gestionados Kubernetes
### Overwhelming choice
He mencionado la virtualización, y esto se puede lograr con hipervisores a nivel local, pero sabemos por secciones anteriores que también podríamos aprovechar las máquinas virtuales en la nube pública para actuar como nuestros nodos. De lo que estoy hablando aquí con los servicios gestionados Kubernetes son las ofertas que vemos de los grandes hiperescaladores, pero también de los MSP eliminando capas de gestión y control lejos del usuario final, esto podría ser eliminar el plano de control del usuario final, esto es lo que sucede con Amazon EKS, Microsoft AKS y Google Kubernetes Engine. (GKE)
I mean the choice is great but there is a point where things become overwhelming and this is not a depth look into all options within each category listed above. On top of the above, we also have OpenShift which is from Red Hat and this option can be run across the options above in all the major cloud providers and probably today gives the best overall useability to the admins regardless of where clusters are deployed.
### Elección abrumadora
So where do you start from your learning perspective, as I said I started with the virtualisation route but that was because I had access to a physical server which I could use for the purpose, I appreciate and in fact, since then I no longer have this option.
Quiero decir que la elección es grande, pero hay un punto en el que las cosas se vuelven abrumadoras y esto no es una mirada en profundidad a todas las opciones dentro de cada categoría enumerada anteriormente.
My actual advice now would be to use Minikube as a first option or Kind (Kubernetes in Docker) but Minikube gives us some additional benefits which almost abstracts the complexity out as we can just use add-ons and get things built out quickly and we can then blow it away when we are finished, we can run multiple clusters, we can run it almost anywhere, cross-platform and hardware agnostic.
No podemos olvidar que además de lo anterior también tenemos OpenShift que es de Red Hat. Esta opción se puede ejecutar a través de las opciones anteriores en todos los principales proveedores de nube y, probablemente, hoy en día ofrece la mejor facilidad de uso general para los administradores, independientemente de donde se despliegan los clusters.
I have been through a bit of a journey with my learning around Kubernetes so I am going to leave the platform choice and specifics here to list out the options that I have tried to give me a better understanding of Kubernetes the platform and where it can run. What I might do with the below blog posts is take another look at these update them and bring them more into here vs them being linked to blog posts.
Por lo tanto, ¿por dónde empezar desde la perspectiva del aprendizaje? Como he dicho yo empecé por la ruta de la virtualización, pero eso fue porque tenía acceso a un servidor físico que podía utilizar para este fin, lo agradezco muchísimo.
Mi consejo actual sería utilizar Minikube como primera opción o Kind (Kubernetes en Docker), pero Minikube nos da algunos beneficios adicionales que casi abstrae la complejidad, ya que sólo podemos utilizar complementos y hacer las cosas rápidamente y luego podemos volarlo cuando hayamos terminado, podemos ejecutar múltiples clusters, podemos ejecutarlo casi en cualquier lugar, multiplataforma y agnóstico de hardware.
He estado a través de un poco de un viaje con mi aprendizaje en torno a Kubernetes así que voy a dejar la elección de la plataforma y los detalles aquí para enumerar las opciones que he probado para darme una mejor comprensión de Kubernetes la plataforma y donde se puede ejecutar. Lo que podría hacer con las siguientes entradas de blog es echar otro vistazo a estos actualizarlos y traerlos más aquí frente a ellos están vinculados a las entradas del blog.
- [Kubernetes playground How to choose your platform](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-1)
- [Kubernetes playground Setting up your cluster](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-2)
@ -48,22 +52,11 @@ I have been through a bit of a journey with my learning around Kubernetes so I a
- [Getting started with CIVO Cloud](https://vzilla.co.uk/vzilla-blog/getting-started-with-civo-cloud)
- [Minikube - Kubernetes Demo Environment For Everyone](https://vzilla.co.uk/vzilla-blog/project_pace-kasten-k10-demo-environment-for-everyone)
### What we will cover in the series on Kubernetes
- Kubernetes Architecture
- Kubectl Commands
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm Package Manager
- Persistent Storage
- Stateful Apps
## Resources
## Recursos
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
See you on [Day 51](day51.md)
Nos vemos en el [Día 51](day51.md)

View File

@ -53,12 +53,13 @@ date: '2022-04-17T10:12:40Z'
## 자료
이곳을 학습 도구로 활용하기 위해 이 readme 파일에 추가적으로 자료를 붙이는 것에 대해 항상 열려있습니다.
이곳을 학습 도구로 활용하기 위해 이 readme 파일에 추가적으로 자료를 붙이는 것에 대해 항상 열려있습니다.
그리고 아래 동영상들을 꼭 보시기 바랍니다. 또한 위에 설명드린 내용에서 많은 인사이트를 얻었으면 합니다.
- [DevOps in 5 Minutes](https://www.youtube.com/watch?v=Xrgk023l4lI)
- [What is DevOps? Easy Way](https://www.youtube.com/watch?v=_Gpe1Zn-1fE&t=43s)
- [DevOps roadmap 2022 | Success Roadmap 2022](https://www.youtube.com/watch?v=7l_n97Mt0ko)
- [From Zero to DevOps Engineer - DevOps Roadmap for YOUR specific background](https://www.youtube.com/watch?v=G_nVMUtaqCk)
여기까지 읽었다면 나에게 필요한 내용인지 아닌지 알 수 있을 것입니다. [Day 2](day02.md)

View File

@ -13,7 +13,7 @@ date: '2022-04-17T21:15:34Z'
부디, 여러분이 자료를 찾고 [Day1 of #90DaysOfDevOps](day01.md) 페이지에 글을 올리면서 함께 참여하기를 바랍니다.
첫 번째 글에서 게 다루었습니다만, 이제 더 깊이 있는 개념 그리고 애플리케이션을 만드는 것에는 두가지 주요 파트가 있다는 것에 대해 이해할 필요가 있습니다. 소프트웨어 개발자들이 애플리케이션을 작성하고 테스트하는 **개발** 파트와 애플리케이션을 서버에 배포하고 유지하는 **운영** 파트 입니다.
첫 번째 글에서 게 다루었습니다만, 이제 더 깊이 있는 개념 그리고 애플리케이션을 만드는 것에는 두 가지 주요 파트가 있다는 것에 대해 이해할 필요가 있습니다. 소프트웨어 개발자들이 애플리케이션을 작성하고 테스트하는 **개발** 파트와 애플리케이션을 서버에 배포하고 유지하는 **운영** 파트 입니다.
## 데브옵스는 그 둘을 연결합니다.
@ -39,7 +39,7 @@ To get to grips with DevOps or the tasks which a DevOps engineer would be carryi
## 이것도 알고, 저것도 알고
네트워크 또는 인프라의 스페셜리스트가 될 필요는 없습니다. 서버를 올리고, 실행시키고 상호간 통신이 가능하도록 구성하는 방법에 대한 지식만 있으면됩니다. 마찬가지로 개발자가 될 필요는 없습니다. 프로그래밍 언어에 대한 기본적인 지식만 있으면 됩니다. 하지만 어느 한 분야의 전문가로 데브옵스 업무에 참여할 수 있고, 이럴 경우 다른 분야에 적응하기 위한 매우 좋은 기반이 될 것입니다.
네트워크 또는 인프라의 스페셜리스트가 될 필요는 없습니다. 서버를 올리고, 실행시키고 상호 간 통신이 가능하도록 구성하는 방법에 대한 지식만 있으면 됩니다. 마찬가지로 개발자가 될 필요는 없습니다. 프로그래밍 언어에 대한 기본적인 지식만 있으면 됩니다. 하지만 어느 한 분야의 전문가로 데브옵스 업무에 참여할 수 있고, 이럴 경우 다른 분야에 적응하기 위한 매우 좋은 기반이 될 것입니다.
또한 서버나 애플리케이션의 관리를 매일 인계받지 못할 수도 있습니다.
@ -47,7 +47,7 @@ To get to grips with DevOps or the tasks which a DevOps engineer would be carryi
## 고차원적인 개요
한쪽에서 우리 개발자들이 애플리케이션을 위핸 시 기능들을 (버그 수정과 더불어) 추가합니다.
한쪽에서 우리 개발자들이 애플리케이션을 위 기능들을 (버그 수정과 더불어) 추가합니다.
다른 한쪽에서는 실제 애플리케이션이 실행되고 필요 서비스들과 통신하도록 구성 및 관리되고 있는 서버, 인프라 내지는 환경이 있습니다.
@ -59,7 +59,7 @@ To get to grips with DevOps or the tasks which a DevOps engineer would be carryi
## 자료
이곳을 학습 도구로 활용하기 위해 이 readme 파일에 추가적으로 자료를 붙이는 것에 대해 항상 열려있습니다.
이곳을 학습 도구로 활용하기 위해 이 readme 파일에 추가적으로 자료를 붙이는 것에 대해 항상 열려있습니다.
그리고 아래 동영상들을 꼭 보시기 바랍니다. 또한 위에 설명드린 내용에서 많은 인사이트를 얻었으면 합니다.

97
2022/ko/Days/day03.md Normal file
View File

@ -0,0 +1,97 @@
---
title: '#90DaysOfDevOps - Application Focused - Day 3'
published: false
description: 90DaysOfDevOps - Application Focused
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048825
---
## 데브옵스 수명 주기 - 애플리케이션 중심
앞으로 몇 주 동안 계속 진행하면서 지속적 개발, 테스트, 배포, 모니터에 대해 100% 반복해서 접하게 될 것입니다. DevOps 엔지니어 역할로 향하고 있다면 반복성이 익숙해질 것이지만 매번 지속적으로 향상시키는 것도 흥미를 유지하는 또 다른 요소입니다.
이번 시간에는 애플리케이션을 처음부터 끝까지 살펴본 다음 다시 반복하듯 되돌아보는 고차원의 시각으로 살펴보겠습니다.
### Development (개발)
애플리케이션의 새로운 예를 들어 보겠습니다. 먼저 아무것도 만들어지지 않은 상태에서 개발자는 고객 또는 최종 사용자와 요구 사항을 논의하고 애플리케이션에 대한 일종의 계획이나 요구 사항을 마련해야 합니다. 그런 다음 요구 사항을 바탕으로 새로운 애플리케이션을 만들어야 합니다.
이 단계의 도구와 관련해서는 애플리케이션을 작성하는 데 사용할 IDE와 프로그래밍 언어를 선택하는 것 외에는 실제 요구 사항이 없습니다.
데브옵스 엔지니어로서 이 계획을 만들거나 최종 사용자를 위해 애플리케이션을 코딩하는 것은 여러분이 아니라 숙련된 개발자가 할 일이라는 점을 기억하세요.
그러나 애플리케이션에 대한 최상의 인프라 결정을 내릴 수 있도록 일부 코드를 읽을 수 있는 것도 나쁘지 않을 것입니다.
앞서 이 애플리케이션은 어떤 언어로든 작성할 수 있다고 언급했습니다. 중요한 것은 버전 관리 시스템을 사용하여 유지 관리해야 한다는 것인데, 이 부분은 나중에 자세히 다룰 것이며 특히 **Git**에 대해 자세히 살펴볼 것입니다.
또한 이 프로젝트에서 한 명의 개발자가 작업하는 것이 아닐 수도 있지만, 이 경우에도 모범 사례에서는 코드를 저장하고 협업하기 위한 코드 저장소가 필요하며, 이는 비공개 또는 공개일 수 있고 호스팅되거나 비공개로 배포될 수 있으며 일반적으로 **GitHub 또는 GitLab**과 같은 코드 저장소가 코드 저장소로 사용되는 것을 듣게 될 것입니다. 이에 대해서는 나중에 **Git** 섹션에서 다시 다루겠습니다.
### Testing (테스팅)
이 단계에서는 요구 사항이 있고 애플리케이션이 개발되고 있습니다. 하지만 우리가 사용할 수 있는 모든 다양한 환경, 특히 선택한 프로그래밍 언어에서 코드를 테스트하고 있는지 확인해야 합니다.
이 단계에서 QA는 버그를 테스트할 수 있으며, 테스트 환경을 시뮬레이션하는 데 컨테이너를 사용하는 경우가 많아져 전반적으로 물리적 또는 클라우드 인프라의 비용 오버헤드를 개선할 수 있습니다.
이 단계는 또한 다음 영역인 지속적 통합의 일부로 자동화될 가능성이 높습니다.
이 테스트를 자동화할 수 있다는 것은 수십, 수백, 심지어 수천 명의 QA 엔지니어가 이 작업을 수동으로 수행해야 하는 것과 비교하면 그 자체로 의미가 있으며, 이러한 엔지니어는 스택 내에서 다른 작업에 집중하여 워터폴 방법론을 사용하는 대부분의 기존 소프트웨어 릴리스에서 지체되는 경향이 있는 버그 및 소프트웨어 테스트 대신 더 빠르게 움직이고 더 많은 기능을 개발할 수 있습니다.
### Integration (통합)
매우 중요한 것은 통합이 데브옵스 라이프사이클의 중간에 있다는 것입니다. 개발자가 소스 코드에 변경 사항을 더 자주 커밋해야 하는 practice(관행)입니다. 이는 매일 또는 매주 단위로 이루어질 수 있습니다.
커밋할 때마다 애플리케이션은 자동화된 테스트 단계를 거치게 되며, 이를 통해 다음 단계로 넘어가기 전에 문제나 버그를 조기에 발견할 수 있습니다.
이제 이 단계에서 "하지만 우리는 애플리케이션을 만들지 않고 소프트웨어 공급업체에서 기성품을 구입합니다."라고 말할 수 있습니다. 많은 회사가 이렇게 하고 있고 앞으로도 계속 그렇게 할 것이며 위의 3단계에 집중하는 것은 소프트웨어 공급업체가 될 것이므로 걱정하지 마세요. 하지만 마지막 단계를 채택하면 기성품 배포를 더 빠르고 효율적으로 배포할 수 있으므로 여전히 채택하고 싶을 수도 있습니다.
오늘 당장 상용 소프트웨어를 구매할 수도 있지만 내일이나 또는... 다음 직장에서 사용할 수도 있기 때문에 위의 지식을 갖추는 것만으로도 매우 중요하다고 말씀드리고 싶습니다.
### Deployment (배포)
Ok so we have our application built and tested against the requirements of our end user and we now need to go ahead and deploy this application into production for our end users to consume.
This is the stage where the code is deployed to the production servers, now this is where things get extremely interesting and it is where the rest of our 86 days dives deeper into these areas. Because different applications require different possibly hardware or configurations. This is where **Application Configuration Management** and **Infrastructure as Code** could play a key part in your DevOps lifecycle. It might be that your application is **Containerised** but also available to run on a virtual machine. This then also leads us onto platforms like **Kubernetes** which would be orchestrating those containers and making sure you have the desired state available to your end users.
Of these bold topics, we will go into more detail over the next few weeks to get a better foundational knowledge of what they are and when to use them.
이제 최종 사용자의 요구 사항에 따라 애플리케이션을 빌드하고 테스트를 마쳤으므로 이제 최종 사용자가 사용할 수 있도록 이 애플리케이션을 프로덕션에 배포해야 합니다.
이 단계는 코드를 프로덕션 서버에 배포하는 단계로, 이제부터 매우 흥미로운 일이 벌어지며 나머지 86일 동안 이러한 영역에 대해 더 자세히 알아볼 것입니다. 애플리케이션마다 필요한 하드웨어나 구성이 다르기 때문입니다. 바로 이 부분에서 **Application Configuration Management(애플리케이션 구성 관리)**와 **Infrastructure as Code(코드형 인프라)**가 데브옵스 라이프사이클에서 중요한 역할을 할 수 있습니다. 애플리케이션이 **Containerised(컨테이너화)**되어 있지만 가상 머신에서 실행할 수 있는 경우도 있을 수 있습니다. 그런 다음 이러한 컨테이너를 오케스트레이션하고 최종 사용자가 원하는 상태를 사용할 수 있도록 하는 **Kubernetes**와 같은 플랫폼으로 이어집니다.
이 대담한 주제 중 앞으로 몇 주에 걸쳐 더 자세히 살펴보면서 컨테이너가 무엇이고 언제 사용하는지에 대한 기초 지식을 쌓을 것입니다.
### Monitoring (관제)
새로운 기능으로 지속적으로 업데이트하고 있는 애플리케이션이 있으며, 테스트 과정에서 문제점이 발견되지 않는지 확인하고 있습니다. 필요한 구성과 성능을 지속적으로 유지할 수 있는 애플리케이션이 우리 환경에서 실행되고 있습니다.
하지만 이제 최종 사용자가 필요한 경험을 얻고 있는지 확인해야 합니다. 이 단계에서는 애플리케이션 성능을 지속적으로 모니터링하여 개발자가 향후 릴리스에서 애플리케이션을 개선하여 최종 사용자에게 더 나은 서비스를 제공할 수 있도록 더 나은 결정을 내릴 수 있도록 해야 합니다.
또한 이 섹션에서는 구현된 기능에 대한 피드백을 수집하고 최종 사용자가 어떻게 개선하기를 원하는지에 대한 피드백을 수집할 것입니다.
안정성은 여기서도 핵심 요소이며, 결국에는 애플리케이션이 필요할 때 항상 사용할 수 있기를 원합니다. 이는 지속적으로 모니터링해야 하는 다른 **observability, security and data management(관찰 가능성, 보안 및 데이터 관리)** 영역으로 이어지며, 피드백을 통해 애플리케이션을 지속적으로 개선, 업데이트 및 릴리스하는 데 항상 사용할 수 있습니다.
특히 [@\_ediri](https://twitter.com/_ediri) 커뮤니티의 일부 의견은 이러한 지속적인 프로세스의 일부로 FinOps 팀도 참여해야 한다고 언급했습니다. 앱과 데이터는 어딘가에서 실행되고 저장되므로 리소스 관점에서 상황이 변경될 경우 비용이 클라우드 요금에 큰 재정적 고통을 주지 않도록 지속적으로 모니터링해야 합니다.
위에서 언급한 "DevOps 엔지니어"에 대해서도 언급할 때가 되었다고 생각합니다. 많은 사람들이 DevOps 엔지니어라는 직책을 가지고 있지만, 이것은 DevOps 프로세스를 포지셔닝하는 이상적인 방법은 아닙니다. 제 말은 커뮤니티의 다른 사람들과 이야기할 때 데브옵스 엔지니어라는 직책이 누구의 목표가 되어서는 안 된다는 것입니다. 실제로 어떤 직책이든 여기에서 설명한 데브옵스 프로세스와 문화를 채택해야 하기 때문입니다. 데브옵스는 클라우드 네이티브 엔지니어/아키텍트, 가상화 관리자, 클라우드 아키텍트/엔지니어, 인프라 관리자와 같은 다양한 직책에서 사용되어야 합니다. 몇 가지 예를 들었지만, 위에서 DevOps 엔지니어를 사용한 이유는 위의 모든 직책에서 사용하는 프로세스의 범위 등을 강조하기 위해서입니다.
## Resources
I am always open to adding additional resources to these readme files as it is here as a learning tool.
My advice is to watch all of the below and hopefully you also picked something up from the text and explanations above.
학습 도구로서 이 Readme 파일에 추가 리소스를 추가하는 것은 언제나 열려 있습니다.
아래의 내용을 모두 보시고 위의 텍스트와 설명에서 많은 것들을 얻으셨으면 좋겠습니다.
- [Continuous Development](https://www.youtube.com/watch?v=UnjwVYAN7Ns) I will also add that this is focused on manufacturing but the lean culture can be closely followed with DevOps.
- [Continuous Testing - IBM YouTube](https://www.youtube.com/watch?v=RYQbmjLgubM)
- [Continuous Integration - IBM YouTube](https://www.youtube.com/watch?v=1er2cjUq1UI)
- [Continuous Monitoring](https://www.youtube.com/watch?v=Zu53QQuYqJ0)
- [The Remote Flow](https://www.notion.so/The-Remote-Flow-d90982e77a144f4f990c135f115f41c6)
- [FinOps Foundation - What is FinOps](https://www.finops.org/introduction/what-is-finops/)
- [**NOT FREE** The Phoenix Project: A Novel About IT, DevOps, and Helping Your Business Win](https://www.amazon.com/Phoenix-Project-DevOps-Helping-Business/dp/1942788290/)
여기까지 왔다면 이곳이 자신이 원하는 곳인지 아닌지 알 수 있을 것입니다. 다음에 뵙겠습니다. [Day 4](day04.md).

99
2022/ko/Days/day04.md Normal file
View File

@ -0,0 +1,99 @@
---
title: '#90DaysOfDevOps - DevOps & Agile - Day 4'
published: false
description: 90DaysOfDevOps - DevOps & Agile
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048700
---
## DevOps & Agile (데브옵스 & 애자일)
데브옵스와 애자일의 차이점을 알고 계신가요? 데브옵스와 애자일은 독립적인 개념으로 형성되었습니다. 하지만 이제 이 두 용어는 융합되고 있습니다.
이 글에서는 애자일과 데브옵스의 중요한 차이점을 살펴보고 이 둘이 긴밀하게 연결되어 있는 이유를 알아보겠습니다.
이 분야를 배우면서 제가 본 공통적인 관점, 즉 목표와 프로세스가 비슷하지만 데브옵스와 애자일에 대해 조금 더 이해하는 것이 시작하기에 좋은 출발점이라고 생각합니다. 이 섹션에서는 이에 대해 간략하게 정리해 보려고 합니다.
정의부터 시작하겠습니다.
### Agile Development
애자일은 제품의 큰 결과물을 한 번에 출시하기보다는 작은 결과물을 더 빠르게 제공하는 데 중점을 두는 접근 방식으로, 소프트웨어는 반복적으로 개발됩니다. 팀은 매주 또는 매달 점진적인 업데이트를 통해 새 버전을 출시합니다. 애자일의 최종 목표는 최종 사용자에게 최적의 경험을 제공하는 것입니다.
### DevOps
지난 며칠 동안 데브옵스의 최종 목표를 설명하는 몇 가지 다른 방법으로 이 문제를 다뤄왔습니다. 데브옵스는 일반적으로 소프트웨어 개발자와 운영 전문가 간의 협력을 기반으로
및 소프트웨어 개발자와 운영 전문가 간의 협력을 기반으로 하는 배포 관행을 설명합니다. 데브옵스의 주요 이점은 간소화된 개발 프로세스를 제공하고 잘못된 커뮤니케이션을 최소화하는 것입니다.
## 애자일과 데브옵스의 차이점은 무엇인가?
차이점은 주로 선입견에 있습니다. 애자일과 데브옵스는 서로 다른 선입견을 가지고 있지만 서로를 돕고 있습니다. 애자일은 짧은 반복을 원하는데, 이는 데브옵스가 제공하는 자동화를 통해서만 가능합니다. 애자일은 고객이 특정 버전을 사용해보고 신속하게 피드백을 주기를 원하는데, 이는 데브옵스가 새로운 환경을 쉽게 만들 수 있을 때만 가능합니다.
### Different participants (서로 다른 참여자)
애자일은 최종 사용자와 개발자 간의 커뮤니케이션을 최적화하는 데 중점을 두는 반면 데브옵스는 개발자와 운영, 팀원을 대상으로 합니다. 애자일은 고객을 향한 외부 지향적인 반면 데브옵스는 일련의 내부 관행이라고 할 수 있습니다.
### 팀
애자일은 일반적으로 소프트웨어 개발자와 프로젝트 관리자에게 적용됩니다. 데브옵스 엔지니어의 역량은 제품 주기의 모든 단계에 관여하고 애자일 팀의 일원이므로 개발, QA(품질 보증) 및 운영이 교차하는 지점에 있습니다.
### 적용된 프레임워크
애자일에는 유연성과 투명성을 달성하기 위한 다양한 관리 프레임워크가 있습니다: Scrum > Kanban > Lean > Extreme > Crystal > Dynamic > Feature-Driven. 데브옵스는 협업을 통한 개발 접근 방식에 중점을 두지만 구체적인 방법론을 제공하지는 않습니다. 그러나 데브옵스는 코드형 인프라, 코드형 아키텍처, 모니터링, 자가 치유, 엔드투엔드 테스트 자동화와 같은 관행을 장려합니다. 그러나 이것은 그 자체로 프레임워크가 아니라 관행입니다.
### 피드백
애자일에서는 피드백의 주요 출처가 최종 사용자인 반면, 데브옵스에서는 이해관계자와 팀 자체의 피드백이 더 높은 우선순위를 갖습니다.
### 대상 영역
애자일은 배포 및 유지 관리보다 소프트웨어 개발에 더 중점을 둡니다. 데브옵스는 소프트웨어 개발에도 중점을 두지만 그 가치와 도구는 모니터링, 고가용성, 보안 및 데이터 보호와 같은 배포 및 릴리스 후 단계에도 적용됩니다.
### 문서
애자일은 문서화 및 모니터링보다 유연성과 당면한 작업에 우선순위를 둡니다. 반면 데브옵스는 프로젝트 문서를 필수 프로젝트 구성 요소 중 하나로 간주합니다.
### 위험요소
애자일 리스크는 방법론의 유연성에서 비롯됩니다. 애자일 프로젝트는 우선순위와 요구사항이 계속 변하기 때문에 예측하거나 평가하기가 어렵습니다.
데브옵스 위험은 용어에 대한 오해와 적절한 도구의 부재에서 비롯됩니다. 어떤 사람들은 데브옵스를 개발 프로세스의 기본 구조를 바꾸지 못하는 배포 및 지속적 통합을 위한 소프트웨어 모음으로 간주합니다.
### 사용되는 툴들
애자일 도구는 경영진의 커뮤니케이션 협업, 메트릭 및 피드백 처리에 중점을 둡니다. 가장 인기 있는 애자일 도구로는 JIRA, Trello, Slack, Zoom, SurveyMonkey 등이 있습니다.
데브옵스는 팀 커뮤니케이션, 소프트웨어 개발, 배포 및 통합을 위해 Jenkins, GitHub Actions, BitBucket 등과 같은 도구를 사용합니다. 애자일과 데브옵스는 초점과 범위가 약간 다르지만 핵심 가치는 거의 동일하므로 두 가지를 결합할 수 있습니다.
## 모두 모아본다면... 좋은 선택일까요? 논의가 필요할까요?
애자일과 데브옵스를 결합하면 다음과 같은 이점을 얻을 수 있습니다:
- 유연한 관리와 강력한 기술.
- 애자일 관행은 데브옵스 팀이 우선순위를 보다 효율적으로 소통하는 데 도움이 됩니다.
- 데브옵스 관행을 위해 지불해야 하는 자동화 비용은 신속하고 자주 배포해야 하는 애자일 요구 사항에 따라 정당화됩니다.
- 애자일 방식을 채택하는 팀은 협업을 개선하고 팀의 동기를 높이며 직원 이직률을 낮출 수 있습니다.
- 결과적으로 제품 품질이 향상됩니다.
애자일을 사용하면 이전 제품 개발 단계로 돌아가 오류를 수정하고 기술 부채의 누적을 방지할 수 있습니다. 애자일과 데브옵스를 동시에 도입하려면
동시에 도입하려면 다음 7단계를 따르세요:
1. 개발 팀과 운영 팀을 통합합니다.
2. 빌드 및 운영 팀을 만들고 모든 개발 및 운영 관련 문제를 전체 DevOps 팀에서 논의합니다.
3. 스프린트에 대한 접근 방식을 변경하고 우선순위를 지정하여 개발 작업과 동일한 가치를 지닌 DevOps 작업을 제공하세요. 개발 팀과 운영 팀이 다른 팀의 workflow와 발생 가능한 문제에 대해 의견을 교환하도록 장려하세요.
4. 모든 개발 단계에 QA를 포함하세요.
5. 올바른 도구를 선택하세요.
6. 가능한 모든 것을 자동화하세요.
7. 가시적인 수치 결과물을 사용하여 측정하고 제어하세요.
어떻게 생각하시나요? 다른 견해가 있으신가요? 개발자, 운영, QA 또는 애자일 및 DevOps에 대해 더 잘 이해하고 이에 대한 의견과 피드백을 전달해 주실 수 있는 분들의 의견을 듣고 싶습니다.
### Resources
- [DevOps for Developers Day in the Life: DevOps Engineer in 2021](https://www.youtube.com/watch?v=2JymM0YoqGA)
- [3 Things I wish I knew as a DevOps Engineer](https://www.youtube.com/watch?v=udRNM7YRdY4)
- [How to become a DevOps Engineer feat. Shawn Powers](https://www.youtube.com/watch?v=kDQMjAQNvY4)
여기까지 왔다면 이곳이 자신이 원하는 곳인지 아닌지 알 수 있을 것입니다. 다음에 뵙겠습니다. [Day 5](day05.md).

86
2022/ko/Days/day05.md Normal file
View File

@ -0,0 +1,86 @@
---
title: '#90DaysOfDevOps - Plan > Code > Build > Testing > Release > Deploy > Operate > Monitor > - Day 5'
published: false
description: 90DaysOfDevOps - Plan > Code > Build > Testing > Release > Deploy > Operate > Monitor >
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048830
---
## 계획 > 코드 작성 > 빌드 > 테스트 > 릴리즈 > 배포 > 운영 > 모니터링 >
오늘은 데브옵스 환경에서 애플리케이션의 시작부터 끝까지 개별 단계와 continuous cycle에 대해 집중적으로 살펴보겠습니다.
![DevOps](/2022/Days/Images/Day5_DevOps8.png)
### 계획
개발팀이 다음 스프린트에서 출시할 기능과 버그 수정을 결정하는 계획 프로세스는 데브옵스 엔지니어가 참여하여, 앞으로 어떤 일이 발생할지 파악하고 개발팀의 결정이나 경로에 영향을 미치고, 그들이 구축한 인프라로 작업하도록 돕거나 그들이 다른 경로를 따를 경우 더 나은 방향으로 안내할 수 있는 기회입니다. 중요한 점은 개발자나 소프트웨어 엔지니어링 팀이 데브옵스 엔지니어의 고객이 되므로, 고객이 나쁜 방향으로 가기 전에 고객과 협력할 수 있는 기회라는 것입니다.
### 코드 작성
이제 계획 세션을 마치고 코드 작성 단계에 진입합니다. 이 단계에서 당신이 참여할 수 있는 역할 중 하나는 코드를 작성하는 동안 인프라에 대한 이해도를 높여서 어떤 서비스를 사용할 수 있는지, 그 서비스와 어떻게 상호작용할 수 있는지를 더 잘 이해할 수 있도록 돕는 것입니다. 또한, 코드 작성이 완료되면 해당 코드를 리포지토리에 병합하는 일도 중요한 역할입니다.
### 빌드
여기에서는 자동화 프로세스의 첫 번째로, 코드를 가져와서 사용하는 언어에 따라 변환하거나 컴파일하거나 해당 코드에서 도커 이미지를 생성할 수 있기 때문에, CI 파이프라인을 사용하여 이러한 프로세스를 자동화할 것입니다. 이렇게 함으로써, 코드를 변경하거나 새 코드를 추가할 때마다 일일이 수동으로 작업하는 것이 아니라, 자동화된 프로세스를 통해 더욱 효율적이고 일관성 있는 작업을 수행할 수 있게 됩니다.
## 테스트
빌드가 완료되면 몇 가지 테스트를 실행합니다. 개발 팀은 보통 어떤 테스트를 작성할지 제안할 수 있지만, 이를 실행해야 합니다. 테스트는 프로덕션에 문제가 발생하지 않도록 최소화하기 위한 시도입니다. 새로운 버그가 발생하지 않도록 보장하는 것은 불가능하지만, 최대한 이전에 작동하던 것이 깨지지 않도록 보장하기 위해 노력합니다.
## 릴리즈
테스트가 모두 통과되면, 애플리케이션 유형에 따라 릴리스 프로세스가 수행됩니다. 하지만 이 단계는 작업 중인 애플리케이션에 따라 생략될 수도 있습니다. 일반적으로, GitHub 리포지토리나 git 리포지토리에서 가져온 코드나 빌드된 도커 이미지를 프로덕션 서버에 배포하기 위해 레지스트리나 리포지토리에 저장합니다. 이를 통해 배포 프로세스가 진행됩니다.
## 배포
배포는 모든 개발과정의 최종 단계이기 때문에, 프로덕션 환경에 코드를 적용하는 과정입니다. 이 단계에서 비즈니스에서는 여러분과 소프트웨어 엔지니어링 팀이 지금까지 이 제품에 투자한 모든 시간과 노력의 가치를 실현할 수 있습니다.
## 운영
한 번 배포가 완료되면, 해당 제품이 운영되기 시작하게 됩니다. 운영에는 고객이 사이트나 애플리케이션을 사용할 때 발생하는 문제를 파악하고, 이에 대한 대처 방안을 마련하는 것이 포함됩니다. 예를 들어, 사이트가 느리게 실행되는 문제가 발생하면, 운영팀은 이유를 파악하고 피크 기간 동안은 서버 수를 늘리고, 사용량이 적은 기간에는 서버 수를 줄이는 자동 확장 기능을 구축할 수 있습니다. 또한, 운영 유형 메트릭 처리와 같은 다양한 작업도 수행됩니다. 가능한 경우에는 이러한 작업을 자동화하는 것이 좋습니다. 그러나, 몇 가지 단계를 수행해야 하는 환경에서는 자동화가 어려울 수도 있습니다. 그런 경우에는 가능한 한 자동화를 시도하면서도, 일부 작업을 수동으로 처리해야 할 수도 있습니다. 그리고, 자동화 프로세스에서는 운영팀이 배포가 발생했음을 알 수 있도록 몇 가지 유형의 알림을 포함하는 것이 좋습니다.
## 모니터링
위의 모든 부분이 마지막 단계로 이어지는데, 특히 운영 문제 자동 확장 문제 해결과 관련된 모니터링이 필요하기 때문입니다.
문제가 있다는 것을 알려주는 모니터링이 없다면 문제가 있는 것이므로 메모리 사용률 CPU 사용률 디스크 공간, API 엔드포인트, 응답 시간, 엔드포인트가 얼마나 빨리 응답하는지 등을 모니터링할 수 있으며, 이 중 큰 부분은 로그입니다. 개발자는 로그를 통해 프로덕션 시스템에 액세스하지 않고도 무슨 일이 일어나고 있는지 확인할 수 있습니다.
## 다듬기 & 반복
여태까지 수행한 프로세스를 검토하고 개선할 부분을 찾습니다. 그리고 이를 바탕으로 다시 계획 단계로 돌아가 전체 과정을 재진행합니다. 이는 지속적인 개선과 반복적인 프로세스 개선을 위한 사이클을 형성하며, 더 나은 제품과 높은 품질의 서비스를 제공하기 위한 필수적인 단계입니다.
## Continuous
여러 도구들이 지속적인 프로세스를 달성하는 데 도움을 줍니다. 이 모든 코드와 클라우드 인프라 또는 모든 환경을 완전히 자동화하는 것이 궁극적인 목표이며, 이를 지속적 통합/지속적 배포/지속적 배포 또는 줄여서 "CI/CD"로 설명하기도 합니다. 이번에는 90일 후에 CI/CD에 대한 기본 사항을 예제와 함께 배울 수 있는 워크숍을 제공할 예정입니다.
### Continuous Delivery
Continuous Delivery = 계획 > 코드 작성 > 빌드 > 테스트
### Continuous Integration
이는 위에서 설명한 지속적 배포 단계와 릴리스 단계의 결과를 합친 것입니다. 이 단계는 성공과 실패 모두에 해당하며, 지속적 배포를 통해 피드백을 받거나 지속적 배포로 진행될 수 있습니다.
Continuous Integration = 계획 > 코드 > 빌드 > 테스트 > 릴리즈
### Continuous Deployment
성공적인 CI 릴리스 후, CD 단계로 이동합니다.
성공적인 CI 릴리즈 = Continuous Deployment = 배포 > 운영 > 모니터링
위의 세 가지 개념은 데브옵스 라이프사이클의 각 단계를 간단히 정리한 것으로 볼 수 있습니다.
이전에 다룬 Day 3 를 약간 요약했었지만, 이제는 더 이해하기 쉬워진 것 같습니다.
### 자료
- [DevOps for Developers Software or DevOps Engineer?](https://www.youtube.com/watch?v=a0-uE3rOyeU)
- [Techworld with Nana -DevOps Roadmap 2022 - How to become a DevOps Engineer? What is DevOps?](https://www.youtube.com/watch?v=9pZ2xmsSDdo&t=125s)
- [How to become a DevOps Engineer in 2021 - DevOps Roadmap](https://www.youtube.com/watch?v=5pxbp6FyTfk)
여기까지 왔다면 이 여정이 자신이 찾던 여정인지 아닌지를 판단할 수 있을 것입니다.
[Day 6](day06.md)에서 봐요!

75
2022/ko/Days/day06.md Normal file
View File

@ -0,0 +1,75 @@
---
title: '#90DaysOfDevOps - DevOps - The real stories - Day 6'
published: false
description: 90DaysOfDevOps - DevOps - The real stories
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048855
---
## 데브옵스 - 실제 사례
처음에는 넷플릭스나 포춘지 선정 500대 기업처럼 데브옵스를 실행하는 기업이 없었기 때문에 많은 사람들이 데브옵스를 쉽게 접하기 어려웠습니다. 그러나 현재는 많은 기업이 데브옵스를 도입하면서, 데브옵스가 점차 일상적인 개발 방법으로 자리 잡게 되었다고 생각합니다.
뒤에 나올 예시를 통해 다양한 산업과 업종에서 DevOps를 적용하고 있으며, 이로 인해 비즈니스의 목표 달성에 큰 긍정적인 영향을 미치고 있다는 것을 알 수 있습니다.
여기서 가장 중요한 이점은 데브옵스를 올바르게 수행하면, 비즈니스의 소프트웨어 개발 속도와 품질을 개선하는 데 큰 도움이 된다는 것입니다.
저는 오늘 이 자리를 통해, 데브옵스를 성공적으로 도입한 기업들의 사례를 살펴보고 이와 관련된 몇 가지 리소스를 공유하고자 합니다. 이 자리는 여러분들이 함께 참여하여, 서로 도움을 주고받을 수 있는 좋은 기회가 될 것입니다. 여러분의 비즈니스에 데브옵스 문화를 도입하셨나요? 그렇다면, 성공적이었나요?
앞서 언급한 넷플릭스는 매우 좋은 사례이며, 오늘날 우리가 일반적으로 볼 수 있는 것들과 비교하면 상당히 발전된 모델입니다. 그러나, 성공하고 있는 다른 대형 브랜드들에 대해서도 언급하고자 합니다.
## Amazon
2010년에 아마존은 물리적 서버 공간을 AWS(Amazon Web Services) 클라우드로 이전하여, 아주 작은 단위로 용량을 확장하거나 축소함으로써 리소스를 절약할 수 있게 되었습니다. 이를 통해 아마존은 리테일 지점을 운영하면서 뿐만 아니라, AWS 자체적으로도 높은 수익을 창출하게 되었다는 사실도 알려져 있습니다.
아마존은 2011년에 (자료를 통해 확인할 수 있는 바와 같이) 지속적인 배포 프로세스를 채택하여, 개발자가 원할 때 필요한 서버에 코드를 배포할 수 있게 되었습니다. 이를 통해 아마존은 새로운 소프트웨어를 평균 11.6초 만에 프로덕션 서버에 배포할 수 있게 되었습니다!
## Netflix
넷플릭스를 사용하지 않는 사람이 있을까요? 그들은 고품질의 스트리밍 서비스를 제공하며, 개인적으로도 훌륭한 사용자 경험을 제공합니다.
사용자 경험이 왜 그렇게 좋을까요? 글쎄요, 기억에 남는 결함 없이 서비스를 제공하려면 속도, 유연성, 품질에 대한 관심이 필요합니다.
넷플릭스 개발자는 IT 운영에 의존하지 않고도 배포 가능한 웹 이미지로 코드를 자동으로 빌드할 수 있습니다. 이미지가 업데이트되면 맞춤형으로 구축된 웹 기반 플랫폼을 사용하여 넷플릭스 인프라에 통합됩니다.
이미지 배포에 실패하면, 롤백 되어 이전 버전으로 트래픽이 다시 라우팅 되도록 지속적인 모니터링이 이루어집니다.
Netflix 팀 내에서 수행해야 할 일과 수행하지 말아야 할 일에 대해 자세히 설명하는 훌륭한 강연이 뒤에 있습니다.
## Etsy
많은 회사에서는 배포가 느리고 고통스러워서 어려움을 겪는 경우가 많습니다. 이와 관련하여, 많은 팀이 사일로에 갇혀 협력하지 못하는 문제가 있습니다.
Amazon과 Netflix에 관한 글을 읽으면서 알게 된 것 중 하나는, Etsy가 2009년 말에 이미 개발자가 코드를 배포할 수 있도록 해뒀을 가능성이 높다는 것입니다. 이는 다른 두 회사보다 훨씬 앞선 시기였습니다. (흥미로운 사실이죠!)
더 흥미로운 점은, 개발자가 배포 책임감을 느낄 때 애플리케이션 성능, 가동 시간 및 기타 목표에 대한 책임감도 함께 갖게 된다는 것을 깨달았다는 것입니다.
학습 문화는 데브옵스의 핵심적인 부분입니다. 실패를 통해 교훈을 얻는다면, 실패도 성공으로 이어질 수 있다는 내용은 인용된 것 같지만, 어느 정도 일리가 있는 것 같습니다!
일부 대규모 기업에서는 데브옵스가 판도를 바꾼 다른 사례도 뒤에 추가했습니다.
## 자료
- [How Netflix Thinks of DevOps](https://www.youtube.com/watch?v=UTKIT6STSVM)
- [16 Popular DevOps Use Cases & Real Life Applications [2021]](https://www.upgrad.com/blog/devops-use-cases-applications/)
- [DevOps: The Amazon Story](https://www.youtube.com/watch?v=ZzLa0YEbGIY)
- [How Etsy makes DevOps work](https://www.networkworld.com/article/2886672/how-etsy-makes-devops-work.html)
- [Adopting DevOps @ Scale Lessons learned at Hertz, Kaiser Permanente and lBM](https://www.youtube.com/watch?v=gm18-gcgXRY)
- [Interplanetary DevOps at NASA JPL](https://www.usenix.org/conference/lisa16/technical-sessions/presentation/isla)
- [Target CIO explains how DevOps took root inside the retail giant](https://enterprisersproject.com/article/2017/1/target-cio-explains-how-devops-took-root-inside-retail-giant)
### 데브옵스에 대해 살펴본 첫 며칠의 요약
- 데브옵스는 전체 애플리케이션 개발 라이프사이클인 **개발**, **테스트**, **배포**, **운영**을 단일 팀이 관리할 수 있도록 하는 개발과 운영의 조합입니다.
- 데브옵스의 주요 초점과 목표는 개발 라이프사이클을 단축하면서도 비즈니스 목표와 긴밀하게 연계하여 기능 및 수정 사항을 자주 제공하는 것입니다.
- 데브옵스는 소프트웨어를 안정적이고 신속하게 배포하고 개발할 수 있는 소프트웨어 개발 접근 방식으로, 이를 **지속적인 개발, 테스트, 배포, 모니터링**이라고도 합니다.
여기까지 왔다면 이 여정이 자신이 찾던 여정인지 아닌지를 판단할 수 있을 것입니다. [Day 7](day07.md)에 뵙겠습니다.
Day 7 에서는 개발자가 되는 것이 목표가 아니라, 개발자들이 하는 일을 이해할 수 있도록 프로그래밍 언어에 대해 알아보게 됩니다.
일주일 안에 모든 것을 배울 수는 없겠지만, 7일 또는 7시간 동안 무언가를 배운다면 처음 시작할 때보다 더 많은 것을 알게 될 것입니다.

71
2022/ko/Days/day07.md Normal file
View File

@ -0,0 +1,71 @@
---
title: '#90DaysOfDevOps - The Big Picture: Learning a Programming Language - Day 7'
published: false
description: 90DaysOfDevOps - The Big Picture DevOps & Learning a Programming Language
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048856
---
## 큰 그림: 데브옵스 및 프로그래밍 언어 학습
장기적으로 데브옵스 엔지니어로 성공하려면, 적어도 하나의 프로그래밍 언어를 기초 수준에서 이해하는 것이 매우 중요합니다. 이번 섹션에서는 이러한 중요성에 대해 자세히 알아보고, 이번 주나 섹션이 끝날 때까지 학습 계획을 수립하기 위해 왜, 어떻게, 무엇을 해야 하는지 더 잘 이해하도록 합니다.
소셜 미디어에서 데브옵스 관련 직무를 수행하기 위해 프로그래밍 기술이 필요한지 묻는다면 대부분 '그렇다'고 대답할 것입니다. 하지만 이러한 역할을 위해 어떤 프로그래밍 언어를 배워야 하는지에 대한 질문은 대답하기 어렵습니다. 일반적으로 Python을 추천하지만, Go(Golang)를 추천하는 경우도 점점 늘어나고 있습니다.
제 생각에는 데브옵스에서 성공하려면 프로그래밍 기술에 대한 탄탄한 기초를 갖추는 것이 중요합니다. 그러나 이러한 기술이 왜 필요한지 이해해야 목표를 달성하기 위한 적절한 길을 선택할 수 있습니다.
## 프로그래밍 언어를 배워야 하는 이유를 이해합니다.
데브옵스에서 사용되는 대부분의 도구가 Python 또는 Go로 작성되어 있기 때문에 데브옵스 엔지니어에게 Python과 Go를 자주 권장합니다. 이러한 도구를 만들거나 이러한 도구를 만드는 팀에 합류하는 데 관심이 있다면 데브옵스 도구를 만드는 데 사용되는 언어를 배우는 것이 좋습니다. Kubernetes나 컨테이너에 많이 관여하고 있다면 프로그래밍 언어로 Go를 배우는 것이 더 유리할 수 있습니다. 제 경우에는 클라우드 네이티브 에코시스템에 속해 있으며 Kubernetes의 데이터 관리에 중점을 두는 회사로, 모든 도구가 Go로 작성되어 있는 Kasten by Veeam에서 일하고 있습니다.
아직 명확한 결정이 내려지지 않은 학생이나 경력 전환기의 경우, 진로를 선택하는 것이 쉽지 않을 수 있습니다. 이런 상황에서는 자신이 만들고 싶은 애플리케이션과 가장 잘 맞고 가장 공감할 수 있는 것을 선택하는 것이 가장 좋습니다.
저는 소프트웨어 개발자가 되고자 하는 것이 아닙니다. 프로그래밍 언어에 대한 기본적인 이해를 바탕으로 다양한 도구의 기능을 이해하고 이를 개선할 수 있는 방법을 찾는 것이 목표입니다.
Kasten K10이나 Terraform, HCL과 같은 데브옵스 도구와 상호 작용하는 방법을 이해하는 것이 중요합니다. 이는 일반적으로 YAML로 작성되는 구성 파일을 통해 이루어집니다. 이러한 파일을 통해 DevOps 도구로 작업을 수행할 수 있습니다. (이 섹션의 마지막 날에는 YAML에 대해 더 자세히 살펴보겠습니다.)
## 제가 방금 프로그래밍 언어를 배우지 말라고 설득한 건가요?
많은 경우, 데브옵스 엔지니어의 주된 책임은 엔지니어링 팀과 협력하여 데브옵스 관행을 workflow에 통합하는 것입니다. 여기에는 애플리케이션에 대한 광범위한 테스트와 workflow가 앞서 설명한 데브옵스 원칙을 준수하는지 확인하는 작업인 경우가 많습니다. 그러나 작업의 상당 부분에는 애플리케이션 성능 또는 기타 기술적 결함과 관련된 문제 해결도 포함될 수 있습니다. 따라서 작업 중인 애플리케이션에서 사용하는 프로그래밍 언어에 대한 전문 지식을 갖추는 것이 중요합니다. 예를 들어, 애플리케이션이 Node.js로 작성된 경우 Go나 Python을 알아도 별 도움이 되지 않습니다.
## 왜 Go인가요?
Go가 데브옵스를 위한 유망한 프로그래밍 언어인 이유. Go는 최근 몇 년 동안 상당한 인기를 얻었으며, 2021년 StackOverflow 설문조사에서 가장 선호하는 프로그래밍, 스크립팅 및 마크업 언어 중 하나로 4위에 올랐고, 1위는 Python이었습니다. 자세히 살펴보겠습니다. [StackOverflow 2021 Developer Survey Most Wanted Link](https://insights.stackoverflow.com/survey/2021#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages)
앞서 언급했듯이, Kubernetes, Docker, Grafana, Prometheus 등 가장 잘 알려진 데브옵스 도구 및 플랫폼 중 일부는 Go로 작성되었습니다.
데브옵스 목적에 특히 적합한 Go의 주요 기능이나 특성은 무엇일까요?
## Go 프로그램 구축 및 배포
데브옵스 역할에서 Python과 같은 언어를 사용하면 프로그램을 실행하기 전에 컴파일할 필요가 없다는 이점이 있습니다. 빌드 프로세스가 길어지면 불필요하게 프로세스 속도가 느려질 수 있으므로 소규모 자동화 작업에 특히 유용합니다. Go는 컴파일 언어이긴 하지만 **머신 코드로 직접 컴파일되며** 컴파일 시간이 빠른 것으로 알려져 있다는 점에 집중할 필요가 있습니다.
## 데브옵스를 위한 Go vs Python
Go 프로그램은 정적으로 링크됩니다. 즉, Go 프로그램을 컴파일할 때 모든 것이 단일 바이너리 실행 파일에 포함되며 원격 시스템에 외부 종속성을 설치할 필요가 없습니다. 따라서 외부 라이브러리에 의존하는 경우가 많은 Python 프로그램에 비해 Go 프로그램을 더 쉽게 배포할 수 있습니다. Python을 사용하면 프로그램을 실행하려는 원격 머신에 필요한 모든 라이브러리가 설치되어 있는지 확인해야 합니다.
Go는 특정 플랫폼에 종속되지 않는 언어이기 때문에 Linux, Windows, macOS 등 \*다양한 운영 체제용 바이너리 실행 파일을 쉽게 만들 수 있습니다. 반면에 Python으로 특정 운영 체제용 바이너리 실행 파일을 생성하는 것은 더 어려울 수 있습니다.
Go는 Python에 비해 컴파일 및 실행 시간이 빠르고 CPU와 메모리 측면에서 리소스 소비가 적은 매우 효율적인 프로그래밍 언어입니다. 이 언어에는 다양한 최적화가 구현되어 있어 뛰어난 성능을 제공합니다. (자세한 내용은 아래 리소스를 참조하세요.)
특정 프로그래밍 작업을 위해 종종 서드파티 라이브러리에 의존하는 Python에 비해 Go에는 데브옵스에 필요한 대부분의 기능을 바로 사용할 수 있는 표준 라이브러리가 있습니다. 여기에는 파일 처리, HTTP 웹 서비스, JSON 처리, 동시성 및 병렬 처리를 위한 기본 지원, 심지어 테스트 기능까지 포함됩니다.
제가 Go를 선택한 이유는 파이썬을 비판하기 위해서가 아니라는 점을 분명히 말씀드리고 싶습니다. 제가 근무하는 회사에서 Go로 소프트웨어를 개발하기 때문에 Go를 사용하는 것이 합리적입니다.
프로그래밍 언어 하나를 배우면 다른 언어를 배우기가 더 쉬워진다는 말을 들었습니다. 어느 회사에서든 자바스크립트 및 Node.js 애플리케이션을 관리, 설계, 오케스트레이션, 디버깅하게 될 가능성이 있고, 지금 Go를 배워두면 도움이 될 것입니다.
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
앞으로 6일 동안 위에서 언급한 자료를 공부하고 매일 진행 상황을 메모할 계획입니다. 전체 과정은 약 3시간 정도 걸리지만, 저는 이 학습에 하루 한 시간씩 할애할 예정입니다. 시간이 여유가 있으신 분들도 함께 하며 깊이 있게 공부하실 수 있도록 전체 리소스 목록을 공유해 드립니다.
[Day 8](day08.md)에서 봐요!

118
2022/ko/Days/day08.md Normal file
View File

@ -0,0 +1,118 @@
---
title: '#90DaysOfDevOps - Setting up your DevOps environment for Go & Hello World - Day 8'
published: false
description: 90DaysOfDevOps - Setting up your DevOps environment for Go & Hello World
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048857
---
## Go를 위한 데브옵스 환경 설정 및 Hello World
Go 언어에 대한 몇 가지 기본 사항을 살펴보기 전에, 먼저 컴퓨터에 Go를 설치하고 모든 "learning programming 101" 모듈에서 가르치는 Hello World 앱을 만들어야 합니다. 이 문서에서는 컴퓨터에 Go를 설치하는 단계를 안내하며, 그림으로 문서화하여 사람들이 쉽게 따라 할 수 있도록 하겠습니다.
먼저, [go.dev/dl](https://go.dev/dl/)로 이동하면 다운로드할 수 있는 몇 가지 옵션이 나타납니다.
![](/2022/Days/Images/Day8_Go1.png)
여기까지 오셨다면, 현재 사용 중인 컴퓨터의 운영 체제를 확인하고 해당하는 다운로드를 선택하여 설치를 시작하시면 됩니다. 제가 사용하는 운영 체제는 Windows입니다. 기본적으로 다음 화면부터는 모든 기본값을 그대로 두어도 됩니다. **(최신 버전이 나오면 스크린샷과 다르게 나올 수도 있으니 참고해주세요.)**
![](/2022/Days/Images/Day8_Go2.png)
만약 이전 버전의 Go가 설치되어 있다면, 먼저 해당 버전을 제거해야 합니다. Windows에서는 이를 위한 내장 제거 기능을 제공하며, 이를 통해 이전 버전을 제거하고 하나의 설치 프로그램으로 설치할 수 있습니다.
작업을 완료한 후 명령 프롬프트/터미널을 열어서 Go가 설치되어 있는지 확인해야 합니다. 만약 아래와 같은 출력이 표시되지 않았다면, Go가 설치되지 않은 것이므로 단계를 되짚어봐야 합니다.
`go version`
![](/2022/Days/Images/Day8_Go3.png)
다음으로 Go 환경변수를 확인하겠습니다. 작업 디렉토리가 올바르게 구성되었는지 항상 확인하는 것이 좋으므로, 아래 디렉토리가 시스템에 있는지 확인해야 합니다.
![](/2022/Days/Images/Day8_Go4.png)
확인하셨나요? 지금까지 잘 따라오고 있나요? 해당 디렉토리로 이동하면 아래와 같은 메시지가 나타납니다.
![](/2022/Days/Images/Day8_Go5.png)
그럼 PowerShell 터미널에서 mkdir 명령어를 사용하여 디렉토리를 만들어 보겠습니다. 또한, 아래에서 보이듯이 Go 폴더 내에 3개의 폴더를 생성해야 합니다.
![](/2022/Days/Images/Day8_Go6.png)
이제 Go를 설치하고 작업 디렉토리를 준비했습니다. 이제 통합 개발 환경(IDE)이 필요합니다. 사용 가능한 IDE는 여러 가지가 있지만, 가장 일반적이고 제가 사용하는 것은 VSCode(Visual Studio Code)입니다. IDE에 대한 자세한 내용은 [여기](https://www.youtube.com/watch?v=vUn5akOlFXQ)에서 확인할 수 있습니다. _(엄밀히 말하면 VSCode는 IDE가 아닌 코드 에디터입니다. - 옮긴이)_
만약 컴퓨터에 아직 VSCode를 다운로드하고 설치하지 않았다면, [여기](https://code.visualstudio.com/download)로 이동하여 설치할 수 있습니다. 아래에서 확인할 수 있는 것처럼, 다양한 운영체제를 제공됩니다.
![](/2022/Days/Images/Day8_Go7.png)
Go 설치와 마찬가지로, 기본값으로 다운로드하여 설치합니다. 설치가 완료되면, 파일 열기를 선택하고 Go 디렉토리를 만들었던 곳으로 이동하여 VSCode를 열 수 있습니다.
![](/2022/Days/Images/Day8_Go8.png)
신뢰에 관한 팝업이 표시될 수 있는데, 원한다면 이를 읽고 '예, 작성자를 신뢰합니다'를 누르세요. (나중에 신뢰하지 않는 파일을 열기 시작해도 저는 책임지지 않습니다!)
이전에 만든 세 개의 폴더를 모두 볼 수 있습니다. 이제 `src` 폴더를 마우스 오른쪽 버튼으로 클릭하고 `Hello`라는 새 폴더를 생성하겠습니다.
![](/2022/Days/Images/Day8_Go9.png)
여기까지는 꽤 쉬운 내용이었죠? 이제 다음 단계에서는 아무것도 이해하지 못한 상태에서 첫 번째 Go 프로그램을 만들 것입니다.
다음으로, `Hello` 폴더에 `main.go` 파일을 생성합니다. `main.go` 파일을 열고 Enter 키를 누르면 Go 확장 프로그램과 패키지를 설치할 것인지 묻는 메시지가 나타납니다. 이전에 만든 빈 `pkg` 폴더를 확인하면 이제 새로운 패키지가 추가된 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day8_Go10.png)
이제 Hello World 앱을 실행하고 다음 코드를 새 `main.go` 파일에 복사하여 저장해 보겠습니다.
```go
package main
import "fmt"
func main() {
fmt.Println("Hello #90DaysOfDevOps")
}
```
이해가 어려울 수도 있지만, 함수, 패키지 등에 대해 더 자세하게 다룰 예정입니다. 현재는 앱을 실행해보겠습니다. 터미널에서 `Hello` 폴더로 돌아가서 제대로 작동하는지 확인할 수 있습니다. 다음 명령을 사용하여 프로그램이 제대로 작동하는지 확인할 수 있습니다.
```
go run main.go
```
![](/2022/Days/Images/Day8_Go11.png)
여기서 끝이 아닙니다. 다른 Windows 컴퓨터에서 이 프로그램을 실행하려면 어떻게 해야 할까요? 다음 명령을 사용하여 바이너리로 빌드하면 됩니다.
```
go build main.go
```
![](/2022/Days/Images/Day8_Go12.png)
_(Mac 운영체제의 경우 `main` 파일이 생성됩니다. - 옮긴이)_
이를 실행한다면 동일한 결과를 볼 수 있습니다:
```bash
# Windows
$ ./main.exe
Hello #90DaysOfDevOps
# Mac - 올긴이
$ ./main
Hello #90DaysOfDevOps
```
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
[Day 9](day09.md)에서 봐요!
![](/2022/Days/Images/Day8_Go13.png)

82
2022/ko/Days/day09.md Normal file
View File

@ -0,0 +1,82 @@
---
title: "#90DaysOfDevOps - Let's explain the Hello World code - Day 9"
published: false
description: 90DaysOfDevOps - Let's explain the Hello World code
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1099682
---
## Hello World 코드를 설명해 보겠습니다.
### Go 작동 방식
[Day 8](day08.md)에서는 컴퓨터에 Go를 설치하는 방법을 안내하고, 그 후 첫 번째 Go 애플리케이션을 만들었습니다.
이 섹션에서는 코드를 더 자세히 살펴보고 Go 언어를 더 잘 이해해보겠습니다.
### 컴파일이 무엇인가요?
[Hello World 코드](/2022/Days/Go/hello.go)를 이해하기 전에 컴파일에 대한 이해가 필요합니다.
파이썬, 자바, Go, C++ 등은 우리가 일반적으로 사용하는 고수준 프로그래밍 언어입니다. 이는 사람이 이해하기 쉽지만, 기계가 실행하기 위해서는 기계가 이해할 수 있는 형태로 변환되어야 합니다. 이러한 변환 작업을 컴파일이라고 합니다. 컴파일은 사람이 작성한 코드를 기계가 이해할 수 있는 코드로 변환하는 과정입니다.
![](/2022/Days/Images/Day9_Go1.png)
이전에 [Day 8](day08.md)에서 수행한 작업을 위 그림으로 확인할 수 있습니다. 우선 간단한 Hello World를 출력하는 main.go를 작성하고, 이를 `go build main.go` 명령을 사용하여 실행 파일로 컴파일했습니다.
### 패키지가 무엇인가요?
패키지는 같은 디렉토리에 있는 여러 개의 .go 확장자 파일의 모음으로 구성됩니다. 더 간단히 말하면, 패키지는 같은 디렉토리 내에서 함께 컴파일되는 소스 파일들입니다. 또한, 더 복잡한 Go 프로그램에서는 여러 패키지가 폴더1, 폴더2, 폴더3 등에 분산되어 있을 수 있으며, 각 패키지는 서로 다른 .go 파일들로 이루어질 수 있습니다.
패키지를 사용하면 다른 사람들의 코드를 재사용하여 처음부터 모든 것을 새로 작성할 필요가 없어집니다. 만약 프로그램에서 계산기가 필요하다면, 기존에 Go 언어로 작성된 패키지에서 수학 함수를 가져와 코드에 적용시키면 장기적으로 많은 시간과 노력을 절약할 수 있습니다.
Go 언어는 코드를 패키지로 구성하여 소스 코드의 재사용성과 유지 보수성을 쉽게 확보할 수 있도록 권장합니다.
### Hello #90DaysOfDevOps 한 줄 한 줄
이제 Hello #90DaysOfDevOps main.go 파일을 살펴보겠습니다.
![](/2022/Days/Images/Day9_Go2.png)
Go 언어에서는 모든 .go 파일은 패키지에 속해야 하며, `package something`과 같이 첫 줄에 패키지 이름을 명시해야 합니다. 이때, `package main`은 이 파일이 main 함수를 포함하는 패키지임을 나타냅니다.
패키지 이름은 원하는 대로 지정할 수 있습니다. 하지만 이 프로그램 시작점에서의 패키지는 `main`으로 지정해야 하며, 이는 규칙입니다. (이 규칙에 대해 추가적인 이해가 필요한가요?)
![](/2022/Days/Images/Day9_Go3.png)
코드를 컴파일하고 실행할 때, 시작해야 하는 위치를 컴퓨터에게 알려주어야 합니다. 이를 위해 'main'이라는 함수를 작성합니다. 컴퓨터는 프로그램의 시작점을 찾기 위해 'main' 함수를 찾습니다.
함수는 특정 작업을 수행하는 코드 블록으로, 프로그램 전체에서 사용할 수 있습니다.
`func`를 사용하여 함수를 어떤 이름으로든 선언할 수 있지만, 이 경우 코드가 시작되는 곳이므로 `main`이라는 이름을 지정해야 합니다.
![](/2022/Days/Images/Day9_Go4.png)
다음으로, 코드의 세 번째 줄인 'import'를 살펴보겠습니다. 이 줄은 메인 프로그램에 다른 패키지를 가져오고자 하는 것을 의미합니다. 'fmt'는 Go에서 제공하는 표준 패키지 중 하나이며, `Println()` 함수를 포함하고 있기 때문에, 이를 'import' 했으므로 여섯 번째 줄에서 이 함수를 사용할 수 있습니다. 프로그램에서 사용하거나 재사용할 수 있는 여러 표준 패키지가 있으므로, 처음부터 작성해야 하는 번거로움을 줄일 수 있습니다. [Go Standard Library](https://pkg.go.dev/std)
![](/2022/Days/Images/Day9_Go5.png)
여기에 있는 `Println()`은 실행 파일이 성공적으로 실행됐을 때 터미널에 STDOUT(standard output)을 출력하는 함수입니다. 괄호 안에는 원하는 메시지를 자유롭게 입력할 수 있습니다.
![](/2022/Days/Images/Day9_Go6.png)
### TLDR
- **1행** = 이 파일은 `main` 패키지에 있으며, 프로그램의 진입점을 포함하고 있으므로 `main`으로 불러야 합니다.
- **3행** = `Println()`을 사용하려면 6행에서 'fmt' 패키지를 'import'하여야 합니다.
- **5행** = 프로그램의 실제 시작점은 `main` 함수입니다.
- **6행** = 이렇게 하면 시스템에 "Hello #90DaysOfDevOps"을 출력할 수 있습니다.
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
[Day 10](day10.md)에서 봐요!

99
2022/ko/Days/day10.md Normal file
View File

@ -0,0 +1,99 @@
---
title: '#90DaysOfDevOps - The Go Workspace - Day 10'
published: false
description: 90DaysOfDevOps - The Go Workspace
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048701
---
### Go 워크스페이스
[Day 8](day08.md)에서 Go 워크스페이스를 간략히 살펴보고 'Hello #90DaysOfDevOps'의 데모를 실행했습니다. 그러나 Go 워크스페이스에 대해 좀 더 자세히 설명해야 합니다.
기본값을 선택한 다음 이미 정의된 GOPATH에 Go 폴더가 생성됐지만, 실제로는 이 GOPATH를 원하는 위치로 변경할 수 있습니다.
다음 명령어를 실행하면
```
echo $GOPATH
```
출력은 다음과 유사해야 합니다.(사용자 아이디가 다를 수 있습니다.)
```
/home/michael/projects/go
```
그런 다음 여기에 3개의 디렉토리를 생성했습니다. **src**, **pkg**, **bin**.
![](/2022/Days/Images/Day10_Go1.png)
**src**는 Go 프로그램과 프로젝트를 저장하는 곳으로, 모든 Go 리포지토리의 네임스페이스 패키지 관리를 담당합니다. 컴퓨터에서 Hello #90DaysOfDevOps 프로젝트를 위한 Hello 폴더를 확인할 수 있습니다.
![](/2022/Days/Images/Day10_Go2.png)
**pkg**는 프로그램에 설치되거나 설치되었던 패키지의 파일을 저장하는 곳입니다. 이것은 사용 중인 패키지가 수정되었는지 여부에 따라 컴파일 프로세스의 속도를 향상하는 데 도움이 됩니다.
![](/2022/Days/Images/Day10_Go3.png)
**bin**은 컴파일된 모든 바이너리가 저장되는 곳입니다.
![](/2022/Days/Images/Day10_Go4.png)
Hello #90DaysOfDevOps는 복잡한 프로그램이 아니기 때문에, 다른 훌륭한 리소스인 [GoChronicles](https://gochronicles.com/)에서 가져온 좀 더 복잡한 Go 프로그램의 예시를 소개해 드리겠습니다.
![](/2022/Days/Images/Day10_Go5.png)
이 페이지는 [GoChronicles](https://gochronicles.com/project-structure/)에 언급되지 않은 다른 폴더에 대한 자세한 설명과 함께, 레이아웃이 왜 이렇게 구성되었는지에 대해 자세히 설명합니다.
### 코드 컴파일 및 실행
[Day 9](day09.md)에서도 코드 컴파일에 대한 간략한 소개를 다루었지만, 이번에는 더 자세히 살펴보겠습니다.
코드를 실행하기 위해서는 먼저 코드를 **컴파일**해야 합니다. Go에서 컴파일하는 방법은 세 가지가 있습니다.
- go build
- go install
- go run
컴파일을 진행하기 전에 Go를 설치하면 무엇을 얻을 수 있는지 살펴봅시다.
8일 차에 Go를 설치하는 동안 Go 소스 파일의 빌드 및 처리를 용이하게 하는 다양한 프로그램으로 구성된 Go 도구를 얻었습니다. 이러한 도구 중 하나가 `Go`입니다.
표준 Go 설치에 포함되지 않은 추가 도구도 설치할 수 있다는 점에 유의하세요.
Go가 제대로 설치되었는지 확인하려면 명령 프롬프트를 열고 `go`를 입력합니다. 아래 이미지와 비슷한 내용이 표시되고 그 뒤에 "Additional Help Topics"가 표시됩니다. 현재로서는 이것에 대해 생각할 필요는 없습니다.
![](/2022/Days/Images/Day10_Go6.png)
8일째인 지금까지 이미 이 도구 중 최소 두 가지를 사용했다는 사실을 기억하실 겁니다.
![](/2022/Days/Images/Day10_Go7.png)
자세히 알고 싶은 것은 "build", "install", 그리고 "run"입니다.
![](/2022/Days/Images/Day10_Go8.png)
- `go run` - 이 명령은 command line에 지정한 .go 파일로 구성된 기본 패키지를 컴파일하고 실행합니다. 이때, 컴파일된 실행 파일은 임시 폴더에 저장됩니다.
- `go build` - 현재 디렉토리에서 패키지와 종속성을 컴파일합니다. 만약 프로젝트에 `main` 패키지가 포함되어 있다면, 실행 파일이 현재 디렉토리에 생성됩니다. 그렇지 않은 경우, 실행 파일은 `pkg` 폴더에 생성되며, 이후 다른 Go 프로그램에서 가져와서 사용할 수 있습니다. 또한 `go build`를 사용하면 Go가 지원하는 모든 OS 플랫폼에 대해 실행 파일을 빌드할 수 있습니다.
- `go install` - go build와 비슷하지만, 실행 파일을 `bin` 폴더에 저장합니다.
`go build``go run`을 실행했지만, 원하는 경우 이곳에서 다시 실행할 수 있습니다. `go install`은 실행 파일을 bin 폴더에 넣는 것으로 설명한 대로 수행됩니다.
![](/2022/Days/Images/Day10_Go9.png)
이 글을 따라오면서 아래의 재생 목록이나 동영상 중 하나를 시청하시기 바랍니다. 제 목표는 여러분과 함께하는 7일 또는 7시간 동안의 여정에서 제가 발견한 흥미로운 정보들을 공유하는 것이기에 저는 이 모든 자료에서의 핵심 정보를 모아서 Go 언어의 기본 개념을 설명하고자 합니다. 아래 자료들은 여러분이 이해해야 할 필수적인 주제에 대한 이해에 도움을 줄 수 있습니다.
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
[Day 11](day11.md)에서 봐요!

176
2022/ko/Days/day11.md Normal file
View File

@ -0,0 +1,176 @@
---
title: '#90DaysOfDevOps - Variables & Constants in Go - Day 11'
published: false
description: 90DaysOfDevOps - Variables & Constants in Go
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048862
---
오늘의 주제에 들어가기 전에, [Techworld with Nana](https://www.youtube.com/watch?v=yyUHQIec83I)에서 다룬 Go의 기초에 대한 환상적이고 간결한 여정에 대해 큰 박수를 보내고 싶습니다.
[Day 8](day08.md)에는 환경을 설정하였고, [Day 9](day09.md)에는 Hello #90DaysOfDevOps 코드를 검토하였으며, [Day 10](day10.md)에는 Go 워크스페이스를 살펴보고 코드를 컴파일한 후 실행하는 과정까지 자세히 학습했습니다.
오늘은 새로운 프로그램을 만들어보면서 변수, 상수 그리고 데이터 타입에 대해 살펴볼 예정입니다.
## Go의 변수 및 상수
우선, 애플리케이션을 계획하는 것으로 시작하겠습니다. #90DaysOfDevOps 챌린지가 얼마나 남았는지 알려주는 프로그램을 만드는 것이 좋을 것 같습니다.
프로그램을 실행하기 전에 고려해야 할 사항은 앱을 빌드하고 참가자를 환영하며 완료한 일 수에 대한 피드백을 줄 때 "#90DaysOfDevOps"이란 용어를 여러 번 사용할 수 있다는 것입니다. 이것은 프로그램에서 #90DaysOfDevOps를 변수로 사용할 좋은 상황입니다.
- 변수는 값을 저장하기 위해 사용됩니다.
- 저장된 정보나 값이 담긴 작은 상자와 같은 것입니다.
- 변수는 프로그램 전체에서 사용할 수 있으며, 챌린지나 변수가 변경되더라도 한 곳에서만 변경하면 되는 장점이 있습니다. 즉, 변수 하나만 변경하면 커뮤니티의 다른 챌린지에도 적용할 수 있습니다.
Go 프로그램에서는 변수를 선언하고 값을 정의하기 위해 **키워드(var, const...)**를 사용합니다. 이러한 변수 선언은 `func main` 코드 블록 내에서 이루어집니다. `키워드`에 대한 자세한 내용은 [여기](https://go.dev/ref/spec#Keywords)에서 확인할 수 있습니다.
변수 이름이 명시적인지 항상 확인하세요. 변수를 선언하면 반드시 사용해야 하며, 그렇지 않으면 오류가 발생합니다. 이는 사용되지 않는 코드(죽은 코드)를 방지할 수 있습니다. 사용되지 않는 패키지도 마찬가지입니다.
```go
var challenge = "#90DaysOfDevOps"
```
다음 코드 스니펫에서 볼 수 있듯이 위와 같이 선언하면 변수를 사용할 수 있음을 알 수 있습니다.
```go
package main
import "fmt"
func main() {
var challenge = "#90DaysOfDevOps"
fmt.Println("Welcome to", challenge, "")
}
```
위 코드 스니펫은 [day11_example1.go](/2022/Days/Go/day11_example1.go)에서 볼 수 있습니다.
위 예제를 사용하여 코드를 빌드하면 아래와 같이 출력되는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day11_Go1.png)
이번 챌린지의 기간은 90일이지만, 다음 챌린지에서는 100일이 될 수도 있으므로, 이번 챌린지에서 사용되는 변수가 다음 챌린지에서도 유용하게 사용될 수 있도록 정의하고 싶습니다. 하지만 우리 프로그램에서는 이 변수를 상수로 정의하고자 합니다. 상수는 값을 변경할 수 없지만, 변수와 유사합니다.(이 코드를 사용하여 새로운 앱을 만들 경우 상수를 변경할 수 있지만, 애플리케이션을 실행하는 동안에는 이 90이 변경되지 않습니다.)
`const` 키워드를 코드에 추가하고, 출력을 위해 다른 코드 라인을 추가합니다.
```go
package main
import "fmt"
func main() {
var challenge = "#90DaysOfDevOps"
const daystotal = 90
fmt.Println("Welcome to", challenge, "")
fmt.Println("This is a", daystotal, "challenge")
}
```
위 코드 스니펫은 [day11_example2.go](/2022/Days/Go/day11_example2.go)에서 볼 수 있습니다.
`go build`를 다시 실행하면 아래와 같은 결과를 확인할 수 있습니다.
![](/2022/Days/Images/Day11_Go2.png)
이것이 우리 프로그램의 끝은 아니며 [Day 12](day12.md)에서 더 많은 기능을 추가할 예정입니다. 현재 완료한 일 수 외에도 다른 변수를 추가하려고 합니다.
`dayscomplete` 변수를 추가하였고, 완료한 일 수도 함께 기록하였습니다.
```go
package main
import "fmt"
func main() {
var challenge = "#90DaysOfDevOps"
const daystotal = 90
var dayscomplete = 11
fmt.Println("Welcome to", challenge, "")
fmt.Println("This is a", daystotal, "challenge and you have completed", dayscomplete, "days")
fmt.Println("Great work")
}
```
위 코드 스니펫은 [day11_example3.go](/2022/Days/Go/day11_example3.go)에서 볼 수 있습니다.
`go build`를 다시 실행하거나 `go run`을 실행할 수 있습니다.
![](/2022/Days/Images/Day11_Go3.png)
코드를 더 쉽게 읽고 편집하기 위해 몇 가지 다른 예제입니다. 이전에는 `Println`을 사용했지만, `Printf`를 사용하여 코드 줄 끝에 변수를 순서대로 정의하는 `%v`를 사용하면 코드를 간단히 만들 수 있습니다. 또한 줄 바꿈은 `\n`을 사용합니다.
기본값을 사용하기 때문에 `%v`를 사용하고 있지만, 다른 옵션은 [fmt package documentation](https://pkg.go.dev/fmt)의 코드 예제 [day11_example4.go](/2022/Days/Go/day11_example4.go)에서 확인할 수 있습니다.
변수를 정의하는 방법 중에는 '변수'와 '타입'을 명시하는 대신 더 간단한 형태로 정의하는 것도 있습니다. 이렇게 코딩하면 코드의 기능은 동일하지만, 더 깔끔하고 간결해집니다. 하지만 이 방법은 변수에만 적용되며 상수에는 적용되지 않습니다.
```go
func main() {
challenge := "#90DaysOfDevOps"
const daystotal = 90
```
## 데이터 타입
예제에서는 변수의 타입을 정의하지 않았습니다. 이는 값을 지정하고 Go가 해당 타입을 유추할 수 있을 만큼 똑똑하거나 저장한 값에 기반하여 타입을 결정할 수 있기 때문입니다. 그러나 사용자가 입력하도록 하려면 특정 타입을 명시해야 합니다.
지금까지 코드에서는 문자열과 정수를 사용했습니다. 정수는 일 수를, 문자열은 챌린지 이름을 나타내는 데 사용했습니다.
각 데이터 타입은 서로 다른 작업을 수행하며, 이에 따라 다르게 작동한다는 것을 유의해야 합니다. 예를 들어, 정수는 문자열과는 곱할 수 없습니다.
총 네 가지 타입이 있습니다:
- **Basic type**: 숫자, 문자열, 불리언 값이 해당 범주에 속합니다.
- **Aggregate type**: 배열과 구조체가 해당 범주에 속합니다.
- **Reference type**: 포인터, 슬라이스, 맵, 함수, 채널이 해당 범주에 속합니다.
- **Interface type**
데이터 타입은 프로그래밍에서 매우 중요한 개념입니다. 이는 변수의 크기와 타입을 지정하는 데 사용됩니다.
Go는 정적으로 타입이 지정되어 있어서 변수의 타입이 정의된 후에는 해당 타입의 데이터만 저장할 수 있습니다.
Go 언어에는 다음과 같이 세 가지 기본 데이터 타입이 있습니다:
- **bool**: 참(True) 또는 거짓(False) 값을 나타냅니다.
- **Numeric**: 정수형(integer), 부동 소수점 값(floating-point), 복소수형(complex)을 나타냅니다.
- **string**: 문자열 값을 나타냅니다.
[Golang by example](https://golangbyexample.com/all-data-types-in-golang-with-examples/)에서 데이터 타입에 대해 매우 자세하게 설명되어 있습니다.
[Techworld with Nana](https://www.youtube.com/watch?v=yyUHQIec83I&t=2023s)에서도 데이터 타입에 대해 자세히 다루고 있으니 추천해드립니다.
변수의 타입을 정의해야 하는 경우 다음과 같이 정의할 수 있습니다:
```go
var TwitterHandle string
var DaysCompleted uint
```
Go 언어에서 변수는 값이 할당되는 것을 의미합니다. 따라서 해당 값을 출력하려면 다음과 같이 할 수 있습니다:
```go
fmt.Printf("challenge is %T, daystotal is %T, dayscomplete is %T\n", conference, daystotal, dayscomplete)
```
여러 종류의 정수 및 부동 소수점 타입이 있으며, 앞의 링크들에서 자세한 내용을 확인할 수 있습니다.
- **int** = 정수
- **unint** = 양의 정수
- **floating point types** = 소수점이 있는 실수
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
이제부터는 프로그램에 몇 가지 사용자 입력 기능을 추가해서 완료된 일수를 입력받도록 하겠습니다.
[Day 12](day12.md)에서 봐요!

85
2022/ko/Days/day12.md Normal file
View File

@ -0,0 +1,85 @@
---
title: '#90DaysOfDevOps - Getting user input with Pointers and a finished program - Day 12'
published: false
description: 90DaysOfDevOps - Getting user input with Pointers and a finished program
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048864
---
## 포인터를 이용하여 사용자 입력을 받아 프로그램 완성하기
어제([Day 11](day11.md)) 독립적인 첫 번째 Go 프로그램을 만들 때, 코드 내에서 사용자 입력을 받기 위한 변수를 생성하고 값을 할당했습니다. 이제 사용자에게 입력을 요청하여 최종 메시지 값을 변수에 할당하려고 합니다.
## 사용자 입력 받기
사용자 입력을 받기 전에 애플리케이션을 다시 살펴보고 변수를 점검해보겠습니다.
어제 우리는 [day11_example4.go](/2022/Days/Go/day11_example4.go) 코드에서 `challenge, daystotal, dayscomplete`를 변수와 상수로 정의했습니다.
이제 새로운 변수 `TwitterName`을 추가하겠습니다. 이 변수는 [day12_example1.go](/2022/Days/Go/day12_example1.go) 코드에서 찾을 수 있습니다. 코드를 실행하면 아래와 같이 출력됩니다.
![](/2022/Days/Images/Day12_Go1.png)
현재 12일째인데, 코드가 하드코딩되어 있다면 매일 `dayscomplete`를 수정하고 매일 코드를 컴파일해야 하기 때문에 효율적이지 않습니다.
사용자로부터 이름과 수행한 일수를 입력받아야 합니다. 이를 위해서는 `fmt` 패키지 내의 다른 함수를 사용할 수 있습니다.
`fmt` 패키지는 포맷된 입력 및 출력(I/O)을 위한 다양한 기능을 제공합니다. 이 패키지에 대한 요약은 다음과 같습니다.
- 메시지 출력
- 사용자 입력 수집
- 파일에 쓰기
이 방법은 변수에 값을 할당하는 대신 사용자로부터 입력을 요청하는 방식입니다.
```go
fmt.Scan(&TwitterName)
```
변수 앞에 `&`를 사용하는 것도 주목해 주세요. 이것은 포인터라 불리며, 다음 섹션에서 다룰 예정입니다.
[day12_example2.go](/2022/Days/Go/day12_example2.go) 코드에서는 사용자로부터 `TwitterName``DaysCompleted`라는 두 변수를 입력받고 있습니다.
프로그램을 실행하면 위의 두 변수 모두에 대한 입력을 받는 걸 볼 수 있습니다.
![](/2022/Days/Images/Day12_Go2.png)
사용자 의견을 반영하여 메시지를 출력하는 기능도 좋지만, 챌린지 종료까지 남은 일수를 알려주는 기능도 추가하는 것이 어떨까요?
이를 위해 `remainingDays`라는 변수를 만들고, `90`이라는 값을 할당하겠습니다. 그리고 `DaysCompleted`로 사용자 입력을 받으면 남은 날짜를 계산하여 `remainingDays`의 값을 변경하겠습니다. 다음과 같이 간단하게 변수를 변경하면 됩니다.
```go
remainingDays = remainingDays - DaysCompleted
```
[day12_example2.go](/2022/Days/Go/day12_example3.go) 코드에서 완성된 프로그램의 모습을 확인할 수 있습니다.
프로그램을 실행하면, 사용자 입력을 기반으로 `remainingDays` 값을 계산하는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day12_Go3.png)
## 포인터가 무엇인가요?(특수 변수)
포인터는 다른 변수의 메모리 주소를 가리키는 (특수)변수입니다.
이에 대한 자세한 설명은 [geeksforgeeks](https://www.geeksforgeeks.org/pointers-in-golang/)에서 확인할 수 있습니다.
출력 명령에 `&`를 사용할 때와 사용하지 않은 코드 예시를 통해 포인터의 메모리 주소를 확인해 볼 수 있습니다. [day12_example4.go](/2022/Days/Go/day12_example4.go)에 코드 예제를 추가했습니다.
아래는 이 코드를 실행한 모습입니다.
![](/2022/Days/Images/Day12_Go4.png)
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
[Day 13](day13.md)에서 봐요!

322
2022/ko/Days/day13.md Normal file
View File

@ -0,0 +1,322 @@
---
title: '#90DaysOfDevOps - Tweet your progress with our new App - Day 13'
published: false
description: 90DaysOfDevOps - Tweet your progress with our new App
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048865
---
## 새로운 앱으로 진행 상황을 트윗하세요
프로그래밍 언어를 살펴본 마지막 날입니다. 우리는 프로그래밍 언어의 겉 부분만 살짝 살펴봤을 뿐이고 앞으로는 더 큰 흥미와 관심을 가지고 더욱 깊이 파고들어야 합니다.
최근 며칠간 애플리케이션에 작은 아이디어를 추가하면서 기능을 개선했습니다. 이번 세션에서는 앞서 언급한 패키지를 활용하여 화면에 진행 상황을 업데이트하는 것뿐만 아니라, 챌린지의 세부 정보와 상태를 트윗할 수 있는 기능을 만들어보려고 합니다.
## 진행 상황을 트윗하는 기능 추가
이 기능을 사용하려면 먼저 트위터에서 개발자 API 접근을 설정해야 합니다.
[Twitter Developer Platform](https://developer.twitter.com)으로 이동하여 내 트위터로 계정으로 로그인하면, 이미 만든 앱이 없는 경우 아래와 같은 화면이 표시됩니다.
![](/2022/Days/Images/Day13_Go1.png)
여기에서 Elevated 등급 계정을 요청할 수 있습니다. 시간이 조금 걸릴 수 있지만, 제 경우에는 빠르게 승인이 됐습니다.
다음으로, 프로젝트 및 앱을 선택하여 앱을 생성합니다. 보유한 계정 액세스 권한에 따라 제한이 있으며, Essential 계정은 하나의 앱과 하나의 프로젝트만, Elevated 계정은 3개의 앱만 만들 수 있습니다.
![](/2022/Days/Images/Day13_Go2.png)
애플리케이션의 이름을 지정합니다.
![](/2022/Days/Images/Day13_Go3.png)
API token이 제공됩니다. 이를 안전한 장소에 저장해야 합니다.(저는 이후 앱을 삭제했습니다.) 나중에 Go 애플리케이션에서 이 토큰이 필요할 것입니다.
![](/2022/Days/Images/Day13_Go4.png)
이제 앱이 생성되었습니다.(스크린샷에 보이는 앱 이름은 이미 생성된 것이기 때문에, 고유해야 하므로 앱 이름을 변경해야 했습니다.)
![](/2022/Days/Images/Day13_Go5.png)
"consumer keys"는 이전에 생성한 key를 의미하며, access token과 비밀번호도 필요합니다. 이 정보는 "Keys & Tokens" 탭에서 확인할 수 있습니다.
![](/2022/Days/Images/Day13_Go6.png)
트위터 개발자 포털에서 필요한 모든 작업을 마쳤습니다. 나중에 필요하실 수 있으니 key를 안전한 곳에 보관해주세요.
## Go 트위터 봇
애플리케이션을 시작했던 코드인 [day13_example1](/2022/Days/Go/day13_example1.go)를 기억해주세요. 하지만 먼저 올바른 코드로 트윗을 생성할 수 있는지 확인해야 합니다.
트위터에 메시지나 출력을 트윗 형태로 전달하기 위한 코드를 생각해봐야 합니다. 이를 위해 [go-twitter](https://github.com/dghubble/go-twitter) 라이브러리를 사용할 것입니다. 이 라이브러리는 Go 언어로 작성된 트위터 API 클라이언트 라이브러리입니다.
메인 애플리케이션에 적용하기 전에 `src` 폴더에 'go-twitter-bot'이라는 새 디렉토리를 만들고, 해당 폴더에서 `go mod init github.com/michaelcade/go-Twitter-bot` 명령을 실행하여 `go.mod` 파일을 생성한 후, 새로운 'main.go' 파일을 작성하여 테스트해 보았습니다.
트위터 개발자 포털에서 생성한 key, token 및 비밀번호가 필요하며, 이를 환경 변수로 설정해야 합니다. 하지만 이는 실행 중인 운영 체제에 따라 다를 수 있습니다.
환경 변수와 관련하여 몇 가지 질문이 있어, 블로그 게시물을 소개해드립니다. 해당 게시물은 환경 변수 설정 방법을 더 자세히 설명하고 있습니다. [How To Set Environment Variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html)를 통해 확인해보세요.
Windows
```
set CONSUMER_KEY
set CONSUMER_SECRET
set ACCESS_TOKEN
set ACCESS_TOKEN_SECRET
```
Linux / MacOS
```
export CONSUMER_KEY
export CONSUMER_SECRET
export ACCESS_TOKEN
export ACCESS_TOKEN_SECRET
```
이 단계에서는 [day13_example2](/2022/Days/Go/day13_example2.go) 코드를 살펴볼 수 있습니다. 이 코드에서는 구조체를 사용하여 key, secret, token을 정의합니다.
Credentials를 분석하고 트위터 API에 연결하는 `func`가 있습니다.
이후 성공 여부에 따라 트윗을 전송합니다.
```go
package main
import (
// ...
"fmt"
"log"
"os"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
// Credentials는 트위터 REST API에 대한 인증에 필요한
// 모든 access/consumer token과 secret key를 저장합니다.
type Credentials struct {
ConsumerKey string
ConsumerSecret string
AccessToken string
AccessTokenSecret string
}
// getClient는 인증에 필요한 모든 것을 포함하며,
// 트위터 클라이언트 또는 오류에 대한 포인터를 반환하는
// Credentials 구조체에 대한 포인터를 받아 나중에 트윗을 보내거나
// 새 트윗을 스트리밍하는 데 사용할 수 있는 헬퍼 함수입니다.
func getClient(creds *Credentials) (*twitter.Client, error) {
// consumer key(API key)와 consumer secret(API secret)을 전달합니다.
config := oauth1.NewConfig(creds.ConsumerKey, creds.ConsumerSecret)
// access token과 access token secret을 전달합니다.
token := oauth1.NewToken(creds.AccessToken, creds.AccessTokenSecret)
httpClient := config.Client(oauth1.NoContext, token)
client := twitter.NewClient(httpClient)
// Credentials 확인
verifyParams := &twitter.AccountVerifyParams{
SkipStatus: twitter.Bool(true),
IncludeEmail: twitter.Bool(true),
}
// 사용자를 검색하고 Credentials가 올바른지 확인할 수 있고,
// 성공적으로 로그인할 수 있는지 확인할 수 있습니다!
user, _, err := client.Accounts.VerifyCredentials(verifyParams)
if err != nil {
return nil, err
}
log.Printf("User's ACCOUNT:\n%+v\n", user)
return client, nil
}
func main() {
fmt.Println("Go-Twitter Bot v0.01")
creds := Credentials{
AccessToken: os.Getenv("ACCESS_TOKEN"),
AccessTokenSecret: os.Getenv("ACCESS_TOKEN_SECRET"),
ConsumerKey: os.Getenv("CONSUMER_KEY"),
ConsumerSecret: os.Getenv("CONSUMER_SECRET"),
}
client, err := getClient(&creds)
if err != nil {
log.Println("Error getting Twitter Client")
log.Println(err)
}
tweet, resp, err := client.Statuses.Update("A Test Tweet from the future, testing a #90DaysOfDevOps Program that tweets, tweet tweet", nil)
if err != nil {
log.Println(err)
}
log.Printf("%+v\n", resp)
log.Printf("%+v\n", tweet)
}
```
위와 같이 작성하면 상황에 따라 오류가 발생하거나 성공하여 코드에 적힌 메시지가 포함된 트윗이 전송됩니다.
## 두 가지의 결합 - Go-Twitter-Bot + 우리의 앱
이제 이 두 가지를 `main.go`에서 병합해야 합니다. 이 작업을 수행하는 더 좋은 방법이 있을 것이며, 프로젝트에 둘 이상의 `.go` 파일을 가질 수 있으므로 이에 대해 의견을 제시해 주시기 바랍니다.
[day13_example3](/2022/Days/Go/day13_example3.go)에서 병합된 코드를 볼 수 있지만 아래에서도 보여드리겠습니다.
```go
package main
import (
// ...
"fmt"
"log"
"os"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
// Credentials는 트위터 REST API에 대한 인증에 필요한
// 모든 access/consumer token과 secret key를 저장합니다.
Credentials REST API에 대한 인증에 필요한 모든 액세스/소비자 토큰과 비밀 키를 저장합니다.
type Credentials struct {
ConsumerKey string
ConsumerSecret string
AccessToken string
AccessTokenSecret string
}
// getClient는 인증에 필요한 모든 것을 포함하며,
// 트위터 클라이언트 또는 오류에 대한 포인터를 반환하는
// Credentials 구조체에 대한 포인터를 받아 나중에 트윗을 보내거나
// 새 트윗을 스트리밍하는 데 사용할 수 있는 헬퍼 함수입니다.
func getClient(creds *Credentials) (*twitter.Client, error) {
// consumer key(API key)와 consumer secret(API secret)을 전달합니다.
config := oauth1.NewConfig(creds.ConsumerKey, creds.ConsumerSecret)
// access token과 access token secret을 전달합니다.
token := oauth1.NewToken(creds.AccessToken, creds.AccessTokenSecret)
httpClient := config.Client(oauth1.NoContext, token)
client := twitter.NewClient(httpClient)
// Verify Credentials
verifyParams := &twitter.AccountVerifyParams{
SkipStatus: twitter.Bool(true),
IncludeEmail: twitter.Bool(true),
}
// we can retrieve the user and verify if the credentials
// we have used successfully allow us to log in!
user, _, err := client.Accounts.VerifyCredentials(verifyParams)
if err != nil {
return nil, err
}
log.Printf("User's ACCOUNT:\n%+v\n", user)
return client, nil
}
func main() {
creds := Credentials{
AccessToken: os.Getenv("ACCESS_TOKEN"),
AccessTokenSecret: os.Getenv("ACCESS_TOKEN_SECRET"),
ConsumerKey: os.Getenv("CONSUMER_KEY"),
ConsumerSecret: os.Getenv("CONSUMER_SECRET"),
}
{
const DaysTotal int = 90
var remainingDays uint = 90
challenge := "#90DaysOfDevOps"
fmt.Printf("Welcome to the %v challenge.\nThis challenge consists of %v days\n", challenge, DaysTotal)
var TwitterName string
var DaysCompleted uint
// asking for user input
fmt.Println("Enter Your Twitter Handle: ")
fmt.Scanln(&TwitterName)
fmt.Println("How many days have you completed?: ")
fmt.Scanln(&DaysCompleted)
// Credentials 확인
remainingDays = remainingDays - DaysCompleted
//fmt.Printf("Thank you %v for taking part and completing %v days.\n", TwitterName, DaysCompleted)
//fmt.Printf("You have %v days remaining for the %v challenge\n", remainingDays, challenge)
//fmt.Println("Good luck")
client, err := getClient(&creds)
if err != nil {
log.Println("Error getting Twitter Client, this is expected if you did not supply your Twitter API tokens")
log.Println(err)
}
message := fmt.Sprintf("Hey I am %v I have been doing the %v for %v days and I have %v Days left", TwitterName, challenge, DaysCompleted, remainingDays)
tweet, resp, err := client.Statuses.Update(message, nil)
if err != nil {
log.Println(err)
}
log.Printf("%+v\n", resp)
log.Printf("%+v\n", tweet)
}
}
```
결과는 트윗으로 표시되어야 하지만, 환경 변수가 제공되지 않은 경우 아래와 같은 오류가 발생해야 합니다.
![](/2022/Days/Images/Day13_Go7.png)
만약 이 문제를 해결하거나 트위터 인증을 사용하지 않기로 선택했다면, 어제 작성한 코드를 사용할 수 있습니다. 성공한 경우 터미널 출력은 다음과 유사하게 표시됩니다:
![](/2022/Days/Images/Day13_Go8.png)
결과 트윗은 아래와 같이 표시되어야 합니다:
![](/2022/Days/Images/Day13_Go9.png)
## 여러 OS에 맞게 컴파일하는 방법
"여러 운영체제에서 컴파일하려면 어떻게 해야 할까요?"라는 질문에 대해 다루고자 합니다. Go의 가장 장점 중 하나는 다양한 운영체제에 대해 쉽게 컴파일할 수 있다는 점입니다. 아래 명령어를 실행하면 모든 운영체제 목록을 확인할 수 있습니다:
```
go tool dist list
```
지금까지 `go build` 명령을 사용하여 HM(host machine)과 빌드 대상을 환경 변수 `GOOS``GOARCH`를 이용하여 결정할 수 있었습니다. 그러나 아래 예제와 같이 다른 바이너리를 생성할 수도 있습니다.
```
GOARCH=amd64 GOOS=darwin go build -o ${BINARY_NAME}_0.1_darwin main.go
GOARCH=amd64 GOOS=linux go build -o ${BINARY_NAME}_0.1_linux main.go
GOARCH=amd64 GOOS=windows go build -o ${BINARY_NAME}_0.1_windows main.go
GOARCH=arm64 GOOS=linux go build -o ${BINARY_NAME}_0.1_linux_arm64 main.go
GOARCH=arm64 GOOS=darwin go build -o ${BINARY_NAME}_0.1_darwin_arm64 main.go
```
위의 모든 플랫폼에 대한 바이너리가 디렉토리에 생성됩니다. 이후 코드에 새로운 기능을 추가할 때마다, 바이너리로 빌드하기 위해 [makefile](/2022/Days/Go/makefile)을 사용할 수도 있습니다.
지금 리포지토리에서 볼 수 있는 릴리스를 만드는 데 사용한 [repository](https://github.com/MichaelCade/90DaysOfDevOps/releases)입니다.
## 자료
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
- [Jake Wright - Learn Go in 12 minutes](https://www.youtube.com/watch?v=C8LgvuEBraI&t=312s)
- [Techworld with Nana - Golang full course - 3 hours 24 mins](https://www.youtube.com/watch?v=yyUHQIec83I)
- [**NOT FREE** Nigel Poulton Pluralsight - Go Fundamentals - 3 hours 26 mins](https://www.pluralsight.com/courses/go-fundamentals)
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
- [A great repo full of all things DevOps & exercises](https://github.com/bregman-arie/devops-exercises)
- [GoByExample - Example based learning](https://gobyexample.com/)
- [go.dev/tour/list](https://go.dev/tour/list)
- [go.dev/learn](https://go.dev/learn/)
7일간의 프로그래밍 언어 학습을 마무리합니다. 앞으로도 더 많은 내용을 다룰 예정이며, 이번 학습을 통해 Go 프로그래밍 언어의 다른 측면도 이해할 수 있었기를 바랍니다.
다음으로, Linux와 Linux에서 알아야 할 몇 가지 기본 사항에 대해 살펴보겠습니다.
[Day 14](day14.md)에서 봐요!

116
2022/ko/Days/day14.md Normal file
View File

@ -0,0 +1,116 @@
---
title: '#90DaysOfDevOps - The Big Picture: DevOps and Linux - Day 14'
published: false
description: 90DaysOfDevOps - The Big Picture DevOps and Linux
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049033
---
## 큰 그림: 데브옵스와 Linux
Linux와 데브옵스는 유사한 문화와 관점을 공유하며, 둘 다 커스터마이징과 확장성에 중점을 둡니다. 이 두 가지 측면은 특히 데브옵스에서 중요한 역할을 합니다.
특히 소프트웨어 개발이나 인프라 관리와 관련 기술들이 Linux에서 개발되었습니다.
또한 많은 오픈 소스 프로젝트, 특히 DevOps 도구는 Linux에서 바로 실행되도록 설계되었습니다.
DevOps나 운영 역할 관점에서는 대부분 Linux를 다룰 가능성이 높습니다. WinOps를 다루는 일도 있지만, 보통은 Linux 서버를 관리하고 배포하는 일이 많을 것입니다.
저는 몇 년 동안 Linux를 사용해왔지만, 메인 데스크탑 컴퓨터는 주로 macOS나 Windows였습니다. 하지만 클라우드 네이티브 역할로 전환한 후에는 노트북에서 Linux를 기본 운영 체제로 사용하기로 결정했습니다. 일부 오디오 및 비디오 장비는 Linux와 호환되지 않기 때문에 업무 관련 애플리케이션은 여전히 Windows가 필요하지만, 앞으로 7일간은 개념을 더 잘 이해하기 위해 데스크탑에서 Linux를 사용하겠습니다.
## 시작하기
더 쉬운 방법이 있기 때문에 여러분도 저와 똑같이 하라고 권하고 싶지는 않지만, 저처럼 단계를 밟으면 Linux를 더 빨리 배울 수 있다는 걸 알려드리고 싶습니다.
이번 7일 동안, 저는 Windows에서 VirtualBox를 사용해 가상 머신을 띄울 계획입니다. 데스크탑 버전의 Linux 배포판도 함께 사용할 예정이지만, 여러분이 관리하게 될 대부분의 Linux 서버는 GUI가 없이 shell 기반으로 운영될 것입니다. 하지만, 앞서 90일 동안 학습한 많은 도구들이 Linux에서 시작되었다는 것을 언급했듯이, Linux 데스크탑을 실행해 보는 것도 강력히 추천합니다.
이 글의 나머지 부분에서는 Virtual Box 환경에서 우분투 데스크탑 가상 머신 실행에 초점을 맞출 것입니다. [Virtual Box](https://www.virtualbox.org/)를 다운로드하고 링크된 사이트에서 최신 [Ubuntu ISO](https://ubuntu.com/download)를 가져와서 데스크탑 환경을 구축할 수도 있지만, 그렇게 하는 것은 데브옵스답지 않겠죠?
Linux 배포판을 선택한 또 다른 이유는 대부분 무료이며 오픈 소스이기 때문입니다. 또한, 모바일 디바이스와 엔터프라이즈 RedHat Enterprise 서버를 제외하고 가장 널리 배포된 배포판인 우분투를 선택했습니다. 제가 틀렸을 수도 있지만 CentOS의 역사를 살펴보면 우분투가 목록에서 높은 순위에 있으며 매우 간단한 편이라고 생각합니다.
## HashiCorp Vagrant 소개
Vagrant는 CLI 유틸리티로 가상 머신의 수명 주기를 관리합니다. vSphere, Hyper-v, Virtual Box, Docker 등 다양한 플랫폼에서 Vagrant를 사용하여 가상 머신을 생성하고 제거할 수 있습니다. 다른 대안도 있지만, 저는 Virtual Box를 사용할 것입니다.
먼저 해야 할 일은 Vagrant를 컴퓨터에 설치하는 것입니다. [HashiCorp Vagrant](https://www.vagrantup.com/downloads) 다운로드 페이지에서는 사용 가능한 모든 운영 체제를 볼 수 있습니다. 저는 Windows를 사용 중이기 때문에 시스템용 바이너리를 다운로드하여 설치하였습니다.
다음으로 [Virtual Box](https://www.virtualbox.org/wiki/Downloads)를 설치해야 합니다. 이 프로그램은 다양한 운영체제에서 실행할 수 있으며, 윈도우, 맥 OS, 또는 리눅스를 실행할 경우 필요합니다.
두 설치 모두 매우 간단하며, 훌륭한 커뮤니티도 있어서 문제가 발생하면 언제든지 연락하시면 도움을 드릴 수 있습니다.
## 첫 번째 VAGRANTFILE
VAGRANTFILE은 배포하려는 가상 머신의 유형을 정의하고, 해당 머신의 구성과 프로비저닝을 설정합니다.
VAGRANTFILE을 저장하고 정리할 때, 저는 워크스페이스의 폴더에 파일을 저장합니다. 제 시스템에서의 예시를 아래에서 확인하실 수 있습니다. 이 방법을 따라 하면 다른 시스템으로 쉽게 전환할 수 있으며, Linux 데스크탑을 "distro hopping"_(리눅스 사용자들이 사용하는 운영체제를 자주 바꾸는 행위 - 옮긴이)_ 하는 "rabbit hole"_(위험을 대비한 대안을 여러 개 준비하는 행위 - 옮긴이)_ 에도 적합합니다.
![](/2022/Days/Images/Day14_Linux1.png)
VAGRANTFILE을 살펴보고 우리가 현재 만들고 있는 것을 확인해 봅시다.
```
Vagrant.configure("2") do |config|
config.vm.box = "chenhan/ubuntu-desktop-20.04"
config.vm.provider :virtualbox do |v|
v.memory = 8096
v.cpus = 4
v.customize ["modifyvm", :id, "--vram", "128"]
end
end
```
이건 매우 간단한 VAGRANTFILE입니다. 특정 "box"를 원한다는 뜻이며, 이 box는 여러분이 찾고 있는 시스템의 공개 이미지 또는 비공개 빌드일 가능성이 높습니다. 공개적으로 사용 가능한 "box"들의 목록은 [public catalogue of Vagrant boxes](https://app.vagrantup.com/boxes/search)에서 찾을 수 있습니다.
다음 줄에서는 `VirtualBox`라는 특정한 공급자를 사용하고자 합니다. 또한 컴퓨터의 메모리를 `8GB`로, CPU 수를 `4`로 정의합니다. 제 경험상, 디스플레이 문제가 발생하면 비디오 메모리를 추가하는 것이 좋습니다. 이렇게 하면 비디오 메모리를 `128MB`까지 늘릴 수 있지만 시스템에 따라 다를 수 있습니다.
```
v.customize ["modifyvm", :id, "--vram", ""]
```
이 vagrant 파일은 [Linux Folder](/2022/Days/Linux/VAGRANTFILE)에서 확인할 수 있습니다.
## Linux 데스크탑 프로비저닝
제 첫 번째 Linux 데스크탑을 시작하고 실행할 준비가 된 상태입니다. 저는 Windows 운영체제에서 PowerShell을 사용하고 있습니다. 프로젝트 폴더로 이동하여 VAGRANTFILE이 위치한 경로로 이동해주세요. 그곳에서 `vagrant up` 명령어를 입력하면 아래와 같은 내용이 표시됩니다.
![](/2022/Days/Images/Day14_Linux2.png)
추가해야 할 사항은 이 가상 머신에서 네트워크가 `NAT`로 설정된다는 것입니다. 현재 단계에서는 NAT에 대해 알 필요가 없으며, 네트워킹 세션에서 이에 대해 자세히 설명할 계획입니다. 가상 머신을 홈 네트워크에 연결하는 가장 간단한 방법이기도 하며, Virtual Box의 기본 네트워킹 모드입니다. 추가적인 정보는 [Virtual Box documentation](https://www.virtualbox.org/manual/ch06.html#network_nat)에서 확인할 수 있습니다.
`vagrant up`이 완료되면 `vagrant ssh`를 사용하여 새 VM의 터미널로 바로 이동할 수 있습니다.
![](/2022/Days/Images/Day14_Linux3.png)
앞으로 며칠 동안 이곳에서 대부분의 작업을 진행할 예정입니다. 또한 개발자 워크스테이션에 몇 가지 사용자 지정 기능을 추가하여 일상적인 작업을 훨씬 더 간편하게 만들 계획입니다. 비표준 터미널이 없다면, 스스로를 DevOps 전문가로 여길 수 있을까요?
확인을 위해 가상 머신을 선택하면 로그인 프롬프트가 표시되어야 합니다.
![](/2022/Days/Images/Day14_Linux4.png)
여기까지 읽으셨는데 "Username과 Password가 무엇인가요?"라는 질문이 계속 나오신다면?
- Username = vagrant
- Password = vagrant
내일은 터미널에서의 몇 가지 명령어와 그 명령어들이 하는 일에 대해 알아보도록 하겠습니다.
## 자료
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
앞으로 더 많은 자원을 확보할 예정이며, Go 언어 자료와 마찬가지로 일반적으로 무료 콘텐츠를 제공하여 모두가 참여하고 배울 수 있도록 할 것입니다.
다음 글에서는 자주 사용할 수 있는 Linux 환경의 명령어에 대해 살펴볼 것입니다.
[Day 15](day15.md)에서 봐요!

195
2022/ko/Days/day15.md Normal file
View File

@ -0,0 +1,195 @@
---
title: '#90DaysOfDevOps - Linux Commands for DevOps (Actually everyone) - Day 15'
published: false
description: 90DaysOfDevOps - Linux Commands for DevOps (Actually everyone)
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048834
---
## 데브옵스(실제로는 모든 사용자)를 위한 Linux 명령
[어제](day14.md) 터미널에서 몇 가지 명령을 사용하여 작업을 수행하는 데 많은 시간을 할애하게 될 것이라고 언급했습니다.
또한 vagrant 프로비저닝된 VM을 사용하면 `vagrant ssh`를 사용하여 box에 액세스할 수 있다고도 언급했습니다. 프로비저닝한 디렉토리와 동일한 디렉토리에 있어야 합니다.
SSH의 경우 username과 password는 필요하지 않으며, 가상 box 콘솔에 로그인하려는 경우에만 필요합니다.
아래는 우리가 원하는 위치입니다:
![](/2022/Days/Images/Day15_Linux1.png)
## 명령어들
여기서 다루지 않은 명령어도 있습니다. 이러한 명령어를 다루는 문서 페이지가 있지만, 특정 명령에 대한 옵션을 이해해야 할 때는 `man` 페이지를 사용할 수 있습니다. `man` 페이지를 사용하면 이 글에서 다루는 각 명령어에 대한 더 많은 옵션을 찾을 수 있습니다. `man man`을 실행하면 `man` 페이지에 대한 도움말을 볼 수 있습니다. `Q`를 눌러 매뉴얼 페이지를 종료할 수 있습니다.
![](/2022/Days/Images/Day15_Linux2.png)
![](/2022/Days/Images/Day15_Linux3.png)
Windows에서 `관리자 권한으로 실행`을 마우스 오른쪽 버튼으로 클릭으로 하는 것에 익숙하다면, `sudo` 명령어를 비슷하게 생각할 수 있습니다. 이 명령어를 사용하면 명령을 `root` 권한으로 실행하며, 명령 실행 전에 암호를 입력해야 하는 메시지가 표시됩니다.
![](/2022/Days/Images/Day15_Linux4.png)
일회성 작업이 아니라 여러 작업을 수행하며 일시적으로 `sudo` 권한을 유지하려면 어떻게 해야 할까요? `sudo su`를 사용하면 `sudo`와 동일한 권한을 가질 수 있습니다. 그러나 이 방법은 보안상 위험할 수 있습니다. `root` 권한을 오랜 시간 동안 유지하는 것은 위험하기 때문입니다. 테스트 VM에서는 문제가 되지 않을 수 있지만 실제 서버에서는 위험할 수 있습니다. 따라서 작업을 마치면 `exit`를 입력하여 `root` 권한을 해제해야 합니다.
![](/2022/Days/Images/Day15_Linux5.png)
저는 항상 `clear` 명령어를 사용합니다. 이 명령어는 이전 명령의 출력 화면을 모두 지우고 깔끔한 작업 공간을 제공하기 때문에 프롬프트를 맨 위에 위치시키는 것과 같은 효과를 가집니다. 윈도우 운영체제에서는 이 명령어를 `cls`로 사용할 수 있습니다.
![](/2022/Days/Images/Day15_Linux6.png)
이제 시스템 내에서 무언가를 생성한 후에 터미널에서 시각화할 수 있는 몇 가지 명령어를 살펴보겠습니다. 먼저 `mkdir` 명령어를 사용하여 시스템에 폴더를 생성할 수 있습니다. 예를 들어, 홈 디렉토리에 Day15라는 폴더를 생성하려면 `mkdir Day15` 명령어를 사용하면 됩니다.
![](/2022/Days/Images/Day15_Linux7.png)
`cd`를 사용하면 디렉토리를 변경할 수 있으므로, 새로운 디렉토리로 이동하려면 `cd D`에서 탭을 사용하여 `cd Day15` 같이 가능한 디렉토리를 자동 완성할 수 있습니다. 시작 위치로 돌아가려면 `cd ..`을 사용하면 됩니다.
![](/2022/Days/Images/Day15_Linux8.png)
`rmdir` 명령어를 사용하면 디렉토리를 삭제할 수 있습니다. 예를 들어, `rmdir Day15` 명령어를 실행하면 폴더가 삭제됩니다.(단, 해당 폴더가 비어있을 경우에만 작동합니다.)
![](/2022/Days/Images/Day15_Linux9.png)
가끔 파일 시스템의 깊은 곳에서 디렉토리를 찾았지만, 그 위치를 모르는 경우가 있습니다. `pwd` 명령어는 작업 디렉토리의 경로를 출력해주는데, 비밀번호처럼 보이지만 실제로는 "print working directory"의 약자입니다.
![](/2022/Days/Images/Day15_Linux10.png)
폴더와 디렉토리를 만드는 방법은 알고 있지만, 파일을 만드는 방법은 어떨까요? 파일을 생성하는 방법 중 하나는 `touch` 명령을 사용하는 것입니다. 예를 들어, `touch Day15` 명령을 실행하면 파일이 생성됩니다. `mkdir` 명령은 이후에 살펴볼 예정이므로, 지금은 무시하셔도 됩니다.
![](/2022/Days/Images/Day15_Linux11.png)
현재 디렉토리 내 모든 파일과 폴더를 나열하려면 `ls` 명령을 반복해서 사용해야 할 것입니다. 해당 명령어로 방금 생성한 파일이 있는지 확인해보겠습니다.
![](/2022/Days/Images/Day15_Linux12.png)
우리는 리눅스 시스템에서 어떻게 파일을 찾을 수 있을까요? `locate` 명령어를 사용하면 파일 시스템을 검색할 수 있습니다. 만약 `locate Day15`와 같이 입력하면 해당 파일의 위치를 알려줍니다. 또한, 파일이 존재하는데 검색 결과가 없다면 `sudo updatedb` 명령어를 실행하여 파일 시스템의 모든 파일을 인덱싱한 후 다시 `locate` 명령어를 실행하세요. 만약 `locate` 명령어가 없다면 `sudo apt install mlocate` 명령어를 사용하여 설치할 수 있습니다.
![](/2022/Days/Images/Day15_Linux13.png)
리눅스 시스템에서 파일을 찾으려면 어떻게 해야 할까요? `mv` 명령어를 사용하면 파일을 이동할 수 있습니다. 예를 들어, `mv Day15 90DaysOfDevOps` 명령어는 Day15 파일을 90DaysOfDevOps 폴더로 이동시킵니다.
![](/2022/Days/Images/Day15_Linux14.png)
파일을 옮겼는데, 이름을 변경하고 싶다면 어떻게 해야 할까요? 이름을 변경하려면 `mv` 명령어를 다시 사용하면 됩니다. 예를 들어, 대소문자를 변경하려면 `mv Day15 day15`와 같이 입력하고, 파일 이름을 완전히 바꾸려면 `mv day15 AnotherDay`와 같이 입력하면 됩니다. 변경 후에는 `ls` 명령어를 사용하여 파일이 정상적으로 변경되었는지 확인할 수 있습니다.
![](/2022/Days/Images/Day15_Linux15.png)
이제 파일과 디렉토리가 생성되면 디렉토리를 삭제해 보겠습니다. 파일을 삭제하려면 간단히 `rm AnotherDay` 명령어를 사용할 수 있습니다. 폴더를 재귀적으로(하위 폴더까지) 삭제하려면 `rm -R` 명령어를 사용하는 것이 일반적입니다. 또한, `rm -R -f` 명령어를 사용하여 해당 파일을 강제로 삭제할 수도 있습니다. 시스템과 영원한 작별 인사를 하고 싶다면 `sudo rm -R -f /`를 입력하면 됩니다._(주의: 이 명령어는 시스템을 완전히 삭제합니다. - 옮긴이)_
![](/2022/Days/Images/Day15_Linux16.png)
파일 이동에 대해 살펴봤는데, 한 폴더에서 다른 폴더로 파일을 복사하고 싶을 때는 `mv` 명령어 대신 `cp` 명령어를 사용해야 합니다. 이제 `cp Day15 Desktop`으로 파일을 복사할 수 있습니다.
![](/2022/Days/Images/Day15_Linux17.png)
폴더와 파일을 만들었지만, 폴더에는 아직 내용이 없습니다. 내용을 추가하는 몇 가지 방법이 있지만, 가장 쉬운 방법은 `echo`를 사용하는 것입니다. `echo`를 사용하면 터미널에서 많은 내용을 출력할 수 있습니다. 저는 시스템 변수가 설정되어 있는지를 확인하기 위해 시스템 변수를 출력할 때 echo를 자주 사용합니다. 파일에 내용을 추가하려면 `echo "Hello #90DaysOfDevOps" > Day15`를 사용할 수 있습니다. 또는 `echo "Commands are fun!" >> Day15`를 사용할 수도 있습니다.
![](/2022/Days/Images/Day15_Linux18.png)
`cat`은 매우 자주 사용하는 명령어 중 하나입니다. `cat`은 "concatenate(연결)"의 약어로, `cat Day15` 명령어를 사용하여 파일 내용을 확인할 수 있습니다. 이 명령어는 구성 파일을 빠르게 읽을 때 유용합니다.
![](/2022/Days/Images/Day15_Linux19.png)
복잡한 구성 파일에서 모든 줄을 읽는 대신에, 특정한 단어를 찾고 싶거나 찾아야 하는 경우 `grep`을 사용할 수 있습니다. 예를 들면 `cat Day15 | grep "#90DaysOfDevOps"`를 입력하여 파일에서 원하는 단어를 검색할 수 있습니다. 이렇게 하면 빠르게 결과를 얻을 수 있습니다.
![](/2022/Days/Images/Day15_Linux20.png)
제가 `clear` 명령을 자주 사용하여 이전에 실행한 일부 명령을 놓칠 수 있기 때문에, `history` 명령을 사용하여 이전에 실행한 모든 명령을 찾을 수 있습니다. `history -c` 명령은 기록을 제거합니다.
`history`를 실행하고 특정 명령을 선택하려는 경우 `!3`을 사용하여 목록에서 세 번째 명령을 선택할 수 있습니다.
또한 `history | grep "Command"`를 사용하여 특정 명령을 검색할 수도 있습니다.
서버에서 명령이 언제 실행되었는지 추적하려면 히스토리 파일의 각 명령에 날짜와 시간을 추가할 수도 있습니다.
다음 시스템 변수가 이 동작을 제어합니다:
```
HISTTIMEFORMAT="%d-%m-%Y %T "
```
bash_profile에 쉽게 추가할 수 있습니다:
```bash
echo 'export HISTTIMEFORMAT="%d-%m-%Y %T "' >> ~/.bash_profile
```
히스토리 파일을 더 크게 만들 수도 있습니다:
```bash
echo 'export HISTSIZE=100000' >> ~/.bash_profile
echo 'export HISTFILESIZE=10000000' >> ~/.bash_profile
```
![](/2022/Days/Images/Day15_Linux21.png)
비밀번호를 변경해야 하나요? `passwd` 명령어를 사용하여 비밀번호를 변경할 수 있습니다. 비밀번호가 숨겨져 있을 때는 이 명령어를 실행해도 `history`에 표시되지 않지만, 명령에 `-p PASSWORD`가 포함되면 `history`에 표시됩니다.
![](/2022/Days/Images/Day15_Linux22.png)
새로운 사용자를 시스템에 추가하고 싶을 경우 `sudo` 명령어를 사용하여 `sudo useradd NewUser`를 입력해야 합니다.
![](/2022/Days/Images/Day15_Linux23.png)
그룹을 재생성하려면 `sudo` 권한이 필요합니다. `sudo groupadd DevOps` 명령을 사용하여 새로운 사용자를 해당 그룹에 추가하려면 `sudo usermod -a -G DevOps` 명령을 실행하세요. `-a`는 추가를, `-G`는 그룹 이름을 나타냅니다.
![](/2022/Days/Images/Day15_Linux24.png)
`sudo` 그룹에 새로운 사용자를 추가하는 것은 드물기는 하지만, 이를 위해서는 `usermod -a -G sudo NewUser` 명령어를 입력하면 됩니다.
### 권한
읽기, 쓰기, 실행 권한은 Linux 시스템의 모든 파일과 폴더에 대한 권한입니다.
전체 목록입니다:
- 0 = 없음 `---`
- 1 = 실행만 `--X`
- 2 = 쓰기만 `-W-`
- 3 = 쓰기 및 실행 `-WX`
- 4 = 읽기 전용 `R--`
- 5 = 읽기 & 실행 `R-X`
- 6 = 읽기 및 쓰기 `RW-`
- 7 = 읽기, 쓰기 및 실행 `RWX`
또한 `777` 또는 `775`로도 표시되며 이는 위 목록과 동일한 숫자를 나타내지만 각각 **User - Group - Everyone**을 나타냅니다.
파일을 살펴봅시다. `ls -al Day15`를 실행하면 위에서 언급한 3개의 그룹을 볼 수 있으며, 사용자와 그룹은 읽기 및 쓰기 권한을 가지고 있지만 모두 읽기 권한만 있습니다.
![](/2022/Days/Images/Day15_Linux25.png)
시스템에서 많은 양의 바이너리를 생성하고 실행할 수 있는 기능을 제공해야 한다면, `chmod`를 사용하여 해당 바이너리에 대한 권한을 변경할 수 있습니다. 예를 들어, `chmod 750 Day15` 명령어를 실행하면 Day15 파일에 대한 권한을 설정할 수 있으며, `ls -al Day15` 명령어로 권한이 설정되었는지 확인할 수 있습니다. 전체 폴더에 대해 이 작업을 실행하려면 `-R` 옵션을 사용하여 재귀적으로(하위 폴더까지) 설정할 수 있습니다.
![](/2022/Days/Images/Day15_Linux26.png)
파일 소유자를 변경하는 것은 어떨까요? 이 작업에는 `chown`을 사용할 수 있습니다. `Day15`의 소유권을 사용자 `vagrant`에서 `NewUser`로 변경하려면 `sudo chown NewUser Day15`를 다시 `-R`로 실행할 수 있습니다.
![](/2022/Days/Images/Day15_Linux27.png)
특정 데이터만 필요한 출력을 얻을 때, 실제로 사용되는 명령어는 `awk`입니다. 예를 들어, `who`를 실행하면 정보가 포함된 줄을 얻을 수 있지만, 이름만 필요한 경우도 있습니다. 이때는 `who | awk '{print $1}'`를 실행하여 첫 번째 열에 해당하는 이름 목록만 가져올 수 있습니다.
![](/2022/Days/Images/Day15_Linux28.png)
데이터 스트림을 표준 입력에서 읽으려면 커맨드라인을 생성하고 실행해야 합니다. 이렇게 하면 명령의 출력을 가져와 다른 명령의 인수로 전달할 수 있습니다. 이러한 사용 사례에 유용한 도구로 `xargs`가 있습니다. 예를 들어, 실행 가능한 시스템에서 모든 Linux 사용자 계정의 목록을 가져오고 싶다면, `cut -d: -f1 < /etc/passwd`를 실행하면 아래와 같은 긴 목록이 생성됩니다.
![](/2022/Days/Images/Day15_Linux29.png)
이 목록을 압축하려면 `cut -d: -f1 < /etc/passwd | sort | xargs`와 같은 명령을 사용하면 됩니다. `xargs`를 추가로 사용합니다.
![](/2022/Days/Images/Day15_Linux30.png)
이미 언급된 것은 아니지만, `cut` 명령어는 파일에서 각 줄의 섹션을 제거하는 데 사용할 수 있습니다. 이 명령어는 바이트 위치, 문자 또는 필드 단위로 줄의 일부를 잘라내는 데 사용됩니다. 예를 들어, `cut -d " " -f 2 list.txt` 명령어를 사용하면 첫 글자를 제거하고 숫자만 표시할 수 있습니다. 많은 조합이 있기 때문에 수동으로 데이터를 추출하는 것보다 이 명령어를 사용하는 것이 더 빠를 수 있습니다.
![](/2022/Days/Images/Day15_Linux31.png)
명령을 입력을 멈추고 때는 컨트롤 + C를 누르면 해당 줄이 취소되고 새로 시작됩니다.
## 자료
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
[Day 16](day16.md)에서 봐요!
목록이 꽤 길지만, 리눅스 서버를 관리하거나 리눅스 데스크톱에서 작업하는 등 일상에서 이 명령어를 모두 활용한다고 자신 있게 말할 수 있습니다. Windows나 macOS에서는 UI를 탐색하는 것이 간단하지만, 터미널을 통해 모든 것이 이루어지는 Linux 서버에서는 그렇지 않습니다.

166
2022/ko/Days/day16.md Normal file
View File

@ -0,0 +1,166 @@
---
title: '#90DaysOfDevOps - Managing your Linux System, Filesystem & Storage - Day 16'
published: false
description: '90DaysOfDevOps - Managing your Linux System, Filesystem & Storage'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048702
---
## Linux 시스템, 파일 시스템 및 스토리지 관리
지금까지 우리는 리눅스와 데브옵스에 대한 간략한 개요를 살펴보았고, [Day 14](day14.md)에서는 실습 환경을 설정하였으며, [Day 15](day15.md)에서는 터미널에서 작업을 수행할 때 자주 사용되는 명령어들을 살펴보았습니다.
여기서는 업데이트, 소프트웨어 설치, 시스템 폴더의 용도와 스토리지에 대해 살펴보겠습니다. 이는 이해해야 할 핵심 영역 세 가지입니다.
## 우분투 및 소프트웨어 관리
가장 먼저 살펴볼 사항은 운영체제 업데이트 방법입니다. 대부분의 사용자는 Windows OS와 macOS에서 이 프로세스에 익숙할 것이며, Linux 데스크톱과 서버에서는 조금 다릅니다.
업데이트 및 소프트웨어 설치를 위해 Ubuntu VM에서 사용할 apt 패키지 관리자를 살펴볼 것입니다.
일반적으로, 개발 워크스테이션에서 소프트웨어를 설치하기 전에 중앙 리포지토리에서 사용 가능한 최신 업데이트가 있는지 확인하기 위해 이 명령을 실행하는 것이 좋습니다.
`sudo apt-get update`
![](/2022/Days/Images/Day16_Linux1.png)
이제 최신 OS 업데이트가 설치된 업데이트된 우분투 가상 머신이 생겼습니다. 이제 여기에 몇 가지 소프트웨어를 설치하려고 합니다.
텍스트 배너를 생성하는 프로그램인 `figlet`을 선택해 보겠습니다.
터미널에 `figlet`을 입력하면 시스템에 이 프로그램이 설치되어 있지 않다는 것을 알 수 있습니다.
![](/2022/Days/Images/Day16_Linux2.png)
위의 내용을 보면 시도해 볼 수 있는 몇 가지 `apt` 설치 옵션이 제공된다는 것을 알 수 있습니다. 기본 리포지토리에는 figlet이라는 프로그램이 있기 때문입니다. `sudo apt install figlet`을 시도해 보겠습니다.
![](/2022/Days/Images/Day16_Linux3.png)
이제 아래에서 볼 수 있듯이 `figlet` 앱을 사용할 수 있습니다.
![](/2022/Days/Images/Day16_Linux4.png)
`apt` 패키지 관리자를 사용하여 해당 소프트웨어나 다른 소프트웨어를 제거할 수도 있습니다.
`sudo apt remove figlet`
![](/2022/Days/Images/Day16_Linux5.png)
시스템에 추가할 수 있는 타사 리포지토리도 있는데, 바로 액세스할 수 있는 리포지토리는 Ubuntu 기본 리포지토리입니다.
Ubuntu 가상 머신에 Vagrant를 설치하려면 현재로서는 불가능합니다. 이를 확인하려면 아래의 첫 번째 명령어를 실행하면 됩니다. 그다음에는 HashiCorp 리포지토리를 신뢰하는 키를 추가하고, 리포지토리를 시스템에 추가해야 합니다.
![](/2022/Days/Images/Day16_Linux6.png)
HashiCorp 리포지토리를 추가했으면 이제 `sudo apt install vagrant`를 실행하여 시스템에 vagrant를 설치할 수 있습니다.
![](/2022/Days/Images/Day16_Linux7.png)
우분투에는 소프트웨어 설치와 관련하여 내장된 패키지 관리자를 사용할 수 있는 다양한 옵션이 있으며, 스냅을 이용한 소프트웨어 설치도 가능합니다.
이 글을 통해 Linux에서 OS 및 소프트웨어 설치를 관리하는 방법에 대한 감을 잡으셨기를 바랍니다.
## 파일 시스템 설명
Linux는 구성 파일들로 이루어져 있으며, 변경하고자 하는 내용이 있다면 해당 구성 파일을 수정하면 됩니다.
Windows 운영체제에서는 C 드라이브가 루트 디렉토리입니다. 반면 Linux 운영체제에서는 `/` 디렉토리가 중요한 위치로, 시스템 내의 여러 폴더를 찾을 수 있는 기본적인 디렉토리입니다.
![](/2022/Days/Images/Day16_Linux8.png)
- `/bin` - 바이너리의 줄임말로, 시스템에서 필요한 실행 파일, 도구 및 바이너리가 있는 폴더입니다.
![](/2022/Days/Images/Day16_Linux9.png)
- `/boot` - 시스템 부팅에 필요한 모든 파일이 위치합니다. 부팅 방법과 부팅할 드라이브를 찾을 수 있습니다.
![](/2022/Days/Images/Day16_Linux10.png)
- `/dev` - 이 폴더에서는 장치 정보를 찾을 수 있으며, 디스크 드라이브에 대한 포인터를 찾을 수 있습니다. 일반적으로 `sda`는 기본 OS 디스크입니다.
![](/2022/Days/Images/Day16_Linux11.png)
- `/etc` - 리눅스 시스템에서 가장 중요한 폴더로, 대부분의 구성 파일이 있는 곳입니다.
![](/2022/Days/Images/Day16_Linux12.png)
- `/home` - 사용자 폴더와 파일이 위치하는 곳입니다. 이 폴더에는 vagrant 사용자 폴더뿐만 아니라 명령어 섹션에서 작업한 `Document``Desktop` 폴더 있습니다.
![](/2022/Days/Images/Day16_Linux13.png)
- `/lib` - `/bin` 폴더가 바이너리 및 실행 파일을 가지고 있다면, 이 폴더는 이러한 파일들에 대한 공유 라이브러리를 가지고 있는 곳입니다.
![](/2022/Days/Images/Day16_Linux14.png)
- `/media` - 이동식 디바이스를 찾을 수 있는 곳입니다.
![](/2022/Days/Images/Day16_Linux15.png)
- `/mnt` - 임시 마운트 지점입니다. 스토리지 섹션에서 자세히 다루겠습니다.
![](/2022/Days/Images/Day16_Linux16.png)
- `/opt` - 옵션 소프트웨어 패키지가 위치하는 폴더입니다. 이 폴더에는 몇 가지 vagrant 및 가상 머신 패키지가 저장되어 있습니다.
![](/2022/Days/Images/Day16_Linux17.png)
- `/proc` - 커널 및 프로세스 정보를 찾을 수 있는 곳으로, `/dev`와 유사합니다.
![](/2022/Days/Images/Day16_Linux18.png)
- `/root` - 액세스 권한을 얻으려면 sudo를 사용해야 하는 루트의 홈 폴더입니다.
![](/2022/Days/Images/Day16_Linux19.png)
- `/run` - 애플리케이션 상태를 위한 자리 표시자입니다.
![](/2022/Days/Images/Day16_Linux20.png)
- `/sbin` - `bin` 폴더와 유사하지만 시스템에서 슈퍼유저 권한이 필요한 도구들이 위치합니다. 즉, `sudo bin`입니다.
![](/2022/Days/Images/Day16_Linux21.png)
- `/tmp` - 임시 파일이 위치하는 폴더입니다.
![](/2022/Days/Images/Day16_Linux22.png)
- `/usr` - 일반 사용자가 소프트웨어 패키지를 설치한 경우, 일반적으로 `/usr/bin` 위치에 설치됩니다.
![](/2022/Days/Images/Day16_Linux23.png)
- `/var` - 애플리케이션은 `bin` 폴더에 설치됩니다. 모든 로그 파일을 저장할 위치가 필요한데, 이 위치가 바로 `/var`입니다.
![](/2022/Days/Images/Day16_Linux24.png)
## 스토리지
Linux 시스템이나 다른 시스템에서도 사용 가능한 디스크와 해당 디스크의 여유 공간을 확인하는 것은 유용합니다. 아래의 명령어 몇 가지는 스토리지를 식별하고 사용 및 관리하는 데 도움이 됩니다.
- `lblk`는 블록 장치를 나열합니다. `sda`는 물리적 디스크이고 `sda1, sda2, sda3`는 해당 디스크의 파티션입니다.
![](/2022/Days/Images/Day16_Linux25.png)
- `df` 명령어는 파티션 정보, 전체 사용량 및 사용 가능한 용량에 대한 더 자세한 정보를 제공합니다. 다른 플래그를 사용하여 구문 분석할 수 있습니다. 일반적으로 `df -h` 명령어를 사용하여 인간이 읽기 쉬운 출력을 생성합니다.
![](/2022/Days/Images/Day16_Linux26.png)
새로운 디스크를 시스템에 추가할 경우, Windows에서와 마찬가지로 디스크 관리에서 디스크를 포맷해야 합니다. 그러나 Linux 터미널에서는 추가된 새 디스크와 관련된 sdb와 함께 `sudo mkfs -t ext4 /dev/sdb` 명령어를 사용하여 포맷할 수 있습니다.
새로 포맷한 디스크를 사용하기 위해서는 `/mnt` 폴더에서 `sudo mkdir NewDisk` 명령어로 디렉토리를 생성한 후, `sudo mount /dev/sdb NewDisk`를 사용하여 해당 위치에 디스크를 마운트해야 합니다.
시스템에서 스토리지를 안전하게 마운트 해제해야 할 때도 있고, 구성에서 그냥 가져와야 할 때도 있습니다. 이 작업은 `sudo umount /dev/sdb` 명령어로 수행할 수 있습니다.
만약에 당신이 해당 디스크를 마운트 해제하고 싶지 않고, 이 디스크를 데이터베이스나 지속적으로 사용할 다른 용도로 사용하려는 경우, 시스템을 재부팅 할 때 그 디스크가 있어야 합니다. 이를 위해, 이 디스크를 `/etc/fstab` 구성 파일에 추가하여 지속성을 유지해야 합니다. 그렇지 않으면 기계가 재부팅될 때 사용할 수 없으며 수동으로 위의 프로세스를 진행해야 합니다. 데이터는 여전히 디스크에 남아 있지만, 이 파일에 구성을 추가하지 않으면 자동으로 마운트되지 않습니다.
`fstab` 구성 파일을 편집한 후 `sudo mount -a` 명령을 실행하여 작동을 확인할 수 있습니다. 오류가 없다면, 이제 변경 사항이 재시작 시에도 지속됩니다.
텍스트 편집기를 사용하여 파일을 편집하는 방법은 다음 세션에서 다루겠습니다.
## 자료
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
[Day 17](day17.md)에서 봐요!

86
2022/ko/Days/day17.md Normal file
View File

@ -0,0 +1,86 @@
---
title: '#90DaysOfDevOps - Text Editors - nano vs vim - Day 17'
published: false
description: 90DaysOfDevOps - Text Editors - nano vs vim
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048703
---
## 텍스트 편집기 - nano vs vim
대부분의 Linux 시스템은 서버로 사용되며, 이러한 시스템에는 GUI가 없습니다. 또한 이전 세션에서 언급했듯이, Linux 시스템은 대부분 구성 파일로 구성되어 있어 변경하려면 이러한 구성 파일을 편집하여 시스템의 모든 것을 변경해야 합니다.
다양한 옵션이 있지만, 가장 일반적으로 사용되는 두 가지 터미널 텍스트 편집기를 소개하고자 합니다. 제 경험상, 빠른 수정 작업에는 `nano`가 더 편리하지만, `vim`은 다양한 기능을 제공하여 더 복잡한 편집 작업을 수행할 수 있습니다.
### nano
- 모든 시스템에서 사용할 수 있는 것은 아닙니다.
- 처음 시작할 때 좋습니다.
`nano 90DaysOfDevOps.txt`를 실행하면 아무 내용도 없는 새 파일이 생성되며, 이 파일에 텍스트를 추가할 수 있습니다. 하단에 도움말 메뉴가 있습니다.
![](/2022/Days/Images/Day17_Linux1.png)
이제 `Ctrl X + enter`를 입력한 다음 `ls`를 실행하면 새 텍스트 파일을 볼 수 있습니다.
![](/2022/Days/Images/Day17_Linux2.png)
이제 해당 파일을 읽기 위해 `cat` 명령어를 실행할 수 있습니다. 그리고 `nano 90DaysOfDevOps.txt` 명령어를 사용하여 파일에 추가 텍스트를 입력하거나 수정할 수 있습니다.
제게 있어서 nano는 구성 파일에 작은 변경 사항을 적용하기 매우 편리한 편집기입니다.
### vim
1976년에 출시된 UNIX 텍스트 편집기인 vi의 형제 버전인 vim은 다양한 기능을 제공하여 가장 일반적인 텍스트 편집기 중 하나일까요?
- 대부분의 Linux 배포판에서 지원됩니다.
- vim만 다루는 7시간짜리 강좌를 찾을 수 있다는 것은 매우 놀랍습니다!
`vim` 명령어를 사용하여 vim 에디터로 이동하거나 새 텍스트 파일을 편집하려면 `vim 90DaysOfDevOps.txt`와 같은 명령어를 실행할 수 있습니다. 그러나 이 경우 하단에 도움말 메뉴가 없음을 확인할 수 있습니다.
첫 번째 질문은 "vim을 어떻게 종료할까요?"일 수 있습니다. 종료 방법으로는 `ESC` 키가 있으며, 변경 사항이 없다면 `:q`를 입력하면 됩니다.
![](/2022/Days/Images/Day17_Linux3.png)
기본적으로 `normal` 모드에서 시작하고 `command, normal, visual, insert` 모드도 있습니다. 텍스트를 추가하려면 `i`를 눌러 `normal` 모드에서 `insert` 모드로 전환해야 합니다. 변경 사항을 저장하고 텍스트를 추가한 후에는 `ESC` 키를 누르고 `:wq`를 입력하면 됩니다.
![](/2022/Days/Images/Day17_Linux4.png)
![](/2022/Days/Images/Day17_Linux5.png)
`cat` 명령으로 변경 사항을 저장했는지 확인할 수 있습니다.
vim은 단축키만 알고 있다면 작은 작업도 매우 빠르게 수행할 수 있는 멋진 기능이 있습니다. 예를 들어, 반복되는 단어 목록을 추가한 후 이를 변경해야 한다고 가정해 봅시다. 구성 파일에서 네트워크 이름이 반복되는 경우, 이를 빠르게 변경하고 싶을 수 있습니다. 이 예시에서는 'day'라는 단어를 사용하고 있습니다.
![](/2022/Days/Images/Day17_Linux6.png)
'day'를 '90DaysOfDevOps'로 변경하려면, `ESC` 키를 누르고 `:%s/Day/90DaysOfDevOps`를 입력하면 됩니다.
![](/2022/Days/Images/Day17_Linux7.png)
이제 Enter 키를 누르면 'day'라는 단어가 '90DaysOfDevOps로' 바뀝니다.
![](/2022/Days/Images/Day17_Linux8.png)
복사 및 붙여넣기는 저에게 정말 큰 도움이 됐습니다. normal 모드에서는 키보드의 `yy`를 사용하여 복사할 수 있으며, 같은 줄에 `p`를 사용하여 붙여넣기하거나, 새 줄에 `P`를 사용하여 붙여넣기할 수 있습니다.
특정 줄을 삭제하려면 삭제할 줄 수를 선택한 후 `dd`를 입력하면 됩니다.
때로는 파일을 검색해야 할 필요가 있습니다. 이전 세션에서 언급한 것처럼 `grep`을 사용할 수 있지만, `/word`를 사용하면 첫 번째 일치 항목을 찾을 수 있으며, `n` 키를 사용하여 다음 항목으로 이동할 수 있습니다.
제가 드릴 수 있는 가장 큰 조언은 가능한 한 직접 사용해 보라는 것입니다.
일반적으로 면접에서 물어보는 질문 중 하나는, "Linux에서 가장 좋아하는 텍스트 편집기는 무엇인가요?" 입니다. 이 질문에 대답하려면 적어도 두 가지 이상의 텍스트 편집기를 알고 있어야 하며, nano에 대한 대답도 괜찮습니다. 이 질문에 대답하는 것은 적어도 텍스트 편집기가 무엇인지 이해했음을 보여주는 것입니다. 하지만 더욱 능숙하게 사용하려면 직접 사용해 보는 것이 좋습니다.
vim에서 방향키로 사용할 수 있는 키는 화살표 키뿐만 아니라 `H,J,K,L`도 사용할 수 있습니다.
## 자료
- [Vim in 100 Seconds](https://www.youtube.com/watch?v=-txKSRn0qeA)
- [Vim tutorial](https://www.youtube.com/watch?v=IiwGbcd8S7I)
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
[Day 18](day18.md)에서 봐요!

213
2022/ko/Days/day18.md Normal file
View File

@ -0,0 +1,213 @@
---
title: '#90DaysOfDevOps - SSH & Web Server - Day 18'
published: false
description: 90DaysOfDevOps - SSH & Web Server
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048733
---
## SSH 및 웹 서버
앞서 언급한 바와 같이, 여러분은 다수의 원격 Linux 서버를 관리할 가능성이 높습니다. 그러므로 이러한 원격 서버와의 연결이 안전한지 확인하는 것이 중요합니다. 본 섹션에서는 원격 시스템과의 보안 터널 구축을 돕기 위해, 모든 사용자가 알아야 할 SSH의 주요 기본 개념들을 살펴볼 것입니다.
- SSH로 연결 설정하기
- 파일 전송하기
- 개인 키 만들기
### SSH 소개
- 보안 shell
- 네트워킹 프로토콜
- 보안 통신 허용
- 모든 네트워크 서비스를 보호
- 일반적으로 원격 command line 액세스에 사용
사실 우린 이미 vagrant 구성과 자동화를 통해 SSH를 사용하고 있었습니다. `vagrant ssh`만 실행해도 원격 가상 머신에 접근할 수 있었습니다.
원격 머신이 워크스테이션과 동일한 시스템이 아니라 원격 위치, 클라우드 기반 시스템이거나 인터넷을 통해서만 접근할 수 있는 데이터 센터에서 실행될 경우, 시스템을 안전하게 관리하기 위한 접근 방법이 필요합니다.
SSH는 클라이언트와 서버 간의 보안 터널을 제공하여 공격자가 정보를 가로챌 수 없게 합니다.
![](/2022/Days/Images/Day18_Linux1.png)
서버에는 항상 특정한 TCP 포트(22)에서 실행되어 대기 중인 서버 측 SSH 서비스가 존재합니다.
올바른 자격증명이나 SSH 키를 가진 클라이언트를 사용하면 해당 서버에 접근할 수 있습니다.
### 시스템에 브리지 네트워크 어댑터 추가하기
현재의 virtual box VM과 함께 사용하려면, 우리 시스템에 브리지 네트워크 어댑터를 추가해야 합니다.
가상 머신을 종료한 다음, Virtual Box 내의 머신을 마우스 우클릭 후 Settings를 선택합니다. 새 창에서 Network를 선택하세요.
![](/2022/Days/Images/Day18_Linux2.png)
이제 가상 머신을 다시 시작하면 로컬 머신에서 IP 주소를 갖게 됩니다. `IP addr` 명령어로 확인할 수 있습니다.
### SSH 서버 실행 확인
우리는 vagrant를 사용해왔기 때문에 SSH가 우리 머신에 이미 설정되어 있다는 것을 알고 있지만, 다음 명령어를 실행하여 확인할 수도 있습니다.
`sudo systemctl status ssh`
![](/2022/Days/Images/Day18_Linux3.png)
시스템에 SSH 서버가 없으면 `sudo apt install OpenSSH-server` 명령어를 사용하여 설치할 수 있습니다.
방화벽이 실행 중인 경우 SSH가 허용되도록 하려면 `sudo ufw allow ssh`를 사용할 수 있습니다. 하지만 vagrant 프로비저닝을 사용하여 자동화했으므로 이 작업은 필요하지 않습니다.
### 원격 접속 - SSH password
이제 SSH 서버가 포트 22에서 들어오는 연결 요청을 수신하도록 설정했고 브리지 네트워킹을 추가했으므로, 로컬 머신의 putty 또는 SSH 클라이언트를 사용하여 SSH로 시스템에 연결할 수 있습니다.
[# PuTTy installation Guide](https://www.cuit.columbia.edu/putty)
![](/2022/Days/Images/Day18_Linux4.png)
Open을 클릭하세요. 이 IP 주소를 통해 처음으로 이 시스템에 연결하는 경우 경고가 표시됩니다. 이 시스템이 우리 것임을 알고 있으므로 Yes를 선택할 수 있습니다.
![](/2022/Days/Images/Day18_Linux5.png)
username(vagrant)과 password(기본 - vagrant)를 입력하라는 메시지가 표시됩니다. 아래에서 SSH 클라이언트(PuTTY)를 사용하여 username과 password로 머신에 연결하는 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day18_Linux6.png)
이제부터 우리의 원격 클라이언트는 VM에 연결되어 있으며, 시스템에서 명령어를 실행할 수 있습니다.
### 원격 접속 - SSH 키
앞서 설명한 방법으로 시스템에 쉽게 액세스할 수 있지만, username과 password에 의존하고 있습니다. 악의적인 사용자가 이 정보와 시스템의 공용 주소 또는 IP를 알게 되면 쉽게 침입할 수 있습니다. 이 때문에 SSH 키가 선호됩니다.
SSH 키를 사용하면, 클라이언트와 서버 모두 이 장치가 신뢰할 수 있는 것임을 알 수 있는 키 쌍을 제공합니다.
키를 생성하는 것은 쉽습니다. 로컬 머신(Windows)에서 다음 명령어를 실행하면 됩니다. 시스템에 SSH 클라이언트가 설치되어 있다면 이 명령어가 작동할 것입니다.
`ssh-keygen -t ed25519`
여기에서 `ed25519`가 무엇인지에 대해 자세히 설명하지는 않겠지만, 암호학에 관심이 있다면 [cryptography](https://en.wikipedia.org/wiki/EdDSA#Ed25519)를 참고해보세요.
![](/2022/Days/Images/Day18_Linux7.png)
생성된 SSH 키는 `C:\Users\micha/.ssh/`에 저장되어 있습니다.
하지만 이 키로 Linux VM에 연결하려면 키를 복사해야 합니다. `ssh-copy-id vagrant@192.168.169.135`를 사용하여 이 작업을 수행할 수 있습니다.
Windows 클라이언트에서 Powershell을 사용하여 키를 생성했지만, Windows에는 `ssh-copy-id`를 실행할 수 없습니다. Windows에서 이 작업을 수행하는 방법이 있으며, 온라인에서 간단한 검색을 통해 대체 방법을 찾을 수 있습니다. 여기서는 Windows 머신에서 git bash를 사용하여 복사하는 것을 보여 드리겠습니다.
![](/2022/Days/Images/Day18_Linux8.png)
이제 Powershell로 돌아와 password 없이 SSH 키로 연결이 작동하는지 테스트할 수 있습니다.
`ssh vagrant@192.168.169.135`
![](/2022/Days/Images/Day18_Linux9.png)
필요한 경우 passphrase를 사용하여 더욱 안전하게 만들 수 있습니다. 또한 password 없이 키 쌍만을 사용하여 SSH를 허용하도록 설정할 수 있습니다. 이렇게 하려면 다음 설정 파일에서 수정하면 됩니다.
`sudo nano /etc/ssh/sshd_config`
여기에 `#` 주석 처리가 되어있는 `PasswordAuthentication yes`라는 줄이 있고, 이를 주석 처리 해제하고 yes를 no로 변경해야 합니다. 그런 다음 `sudo systemctl reload sshd`를 실행해서 SSH 서비스를 다시 로드해야 합니다.
## 웹 서버 설정하기
위에서 설명한 SSH와는 별개로, 이번에는 웹 서버를 구축하는 방법을 다루고자 합니다. 처음에는 조금 어려워 보일 수 있지만, 실제로는 그렇지 않습니다.
리눅스 가상 머신을 이미 구축해 두었다고 가정하고, 이 가상 머신에 apache 웹 서버를 추가하여 내부 네트워크에서 접근할 수 있는 간단한 웹 사이트를 호스팅하려고 합니다. 인터넷에서 접근할 수 있는 웹 사이트는 아니며, 그에 대한 내용은 여기서 다루지 않습니다.
이 과정은 LAMP 스택이라고도 불립니다.
- **L**inux 운영 체제
- **A**pache 웹 서버
- **M**ySQL 데이터베이스
- **P**HP
### Apache2
Apache2는 오픈 소스 HTTP 서버입니다. 아래 명령어를 사용하여 Apache2를 설치할 수 있습니다.
`sudo apt-get install apache2`
Apache2가 정상적으로 설치되었는지 확인하려면 `sudo service apache2 restart`를 실행합니다.
SSH 통합 네트워크 주소를 사용하여 브라우저에서 해당 주소로 이동합니다. 예를 들면 `http://192.168.169.135/`와 같습니다.
![](/2022/Days/Images/Day18_Linux10.png)
### MySQL
MySQL은 웹 사이트의 데이터를 저장하는 데이터베이스입니다. `sudo apt-get install mysql-server` 명령어를 사용하여 MySQL을 설치합니다.
### PHP
PHP는 서버 측 스크립팅 언어로, MySQL 데이터베이스와 상호 작용하기 위해 사용합니다. PHP 및 종속성을 설치하려면 `sudo apt-get install php libapache2-mod-php php-mysql`을 사용합니다.
기본적으로 Apache는 index.html을 사용하지만, 대신 index.php를 사용하도록 설정하려고 합니다.
`sudo nano /etc/apache2/mods-enabled/dir.conf`를 사용하여 index.php를 목록의 첫 번째 항목으로 이동시킵니다.
![](/2022/Days/Images/Day18_Linux11.png)
Apache2 서비스를 다시 시작합니다. `sudo systemctl restart apache2`
이제 PHP가 올바르게 구성되었는지 확인해 보겠습니다. 다음 명령어를 사용하여 새 파일을 생성합니다.
`sudo nano /var/www/html/90Days.php`
아래 내용을 복사한 후 Ctrl + X를 눌러 종료하고 파일을 저장합니다.
```php
<?php
phpinfo();
?>
```
다음 URL로 이동하여 PHP가 올바르게 구성되었는지 확인합니다. `http://192.168.169.135/90Days.php` 이 주소로 이동하면 PHP가 올바르게 설정되었음을 확인할 수 있는 화면이 표시됩니다.
![](/2022/Days/Images/Day18_Linux12.png)
### 워드프레스 설치
LAMP 스택에 워드프레스를 설치하기 위해 [How to install WordPress on Ubuntu with LAMP](https://blog.ssdnodes.com/blog/how-to-install-wordpress-on-ubuntu-18-04-with-lamp-tutorial/)을 참고하였습니다. 이 글에 나와 있는 명령어들은 아래와 같습니다.
`sudo mysql -u root -p`
`CREATE DATABASE wordpressdb;`
`CREATE USER 'admin-user'@'localhost' IDENTIFIED BY 'password';`
`GRANT ALL PRIVILEGES ON wordpressdb.* TO 'admin-user'@'localhost';`
`FLUSH PRIVILEGES;`
`EXIT;`
`sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip`
`sudo systemctl restart apache2`
`cd /var/www`
`sudo curl -O https://wordpress.org/latest.tar.gz`
`sudo tar -xvf latest.tar.gz`
`sudo rm latest.tar.gz`
위 링크의 Step 4에 도달했습니다. 워드프레스 디렉토리에 대한 모든 권한이 올바르게 설정되어 있는지 확인해야 합니다.
내부 네트워크 전용이므로 이 단계에서 "generate security keys"를 할 필요가 없습니다. apache 구성을 워드프레스로 변경하는 Step 5로 이동합니다.
모든 설정이 올바르게 구성되어 있다면, 내부 네트워크 주소를 통해 워드프레스 설치를 진행할 수 있습니다.
## 자료
- [Client SSH GUI - Remmina](https://remmina.org/)
- [The Beginner's guide to SSH](https://www.youtube.com/watch?v=2QXkrLVsRmk)
- [Vim in 100 Seconds](https://www.youtube.com/watch?v=-txKSRn0qeA)
- [Vim tutorial](https://www.youtube.com/watch?v=IiwGbcd8S7I)
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
[Day 19](day19.md)에서 봐요!

310
2022/ko/Days/day19.md Normal file
View File

@ -0,0 +1,310 @@
---
title: '#90DaysOfDevOps - Automate tasks with bash scripts - Day 19'
published: false
description: 90DaysOfDevOps - Automate tasks with bash scripts
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048774
---
## bash 스크립팅을 이용한 작업 자동화
오늘 사용할 shell은 bash이지만, 내일 ZSH에 대해 다룰 때 다른 shell도 다룰 예정입니다.
BASH - **B**ourne **A**gain **Sh**ell
프로그래밍 언어처럼 shell 스크립팅에도 거의 일주일 동안의 섹션을 쓸 수 있습니다. bash는 다른 자동화 도구와 함께 작업하는 기능을 제공합니다.
여전히 많은 사람들이 복잡한 shell 스크립트를 만들어 무언가를 실행하게 하고, 비즈니스에서 가장 중요한 부분을 이 스크립트에 의존하고 있다고 합니다. 하지만 이런 이유로 shell/bash 스크립팅을 이해해야 한다고 말하는 것은 아닙니다. 자동화 도구와 함께 사용하고 ad-hoc(특별한) 작업을 위해 shell/bash 스크립팅을 배워야 합니다.
이 섹션에서 사용한 예로, 매주 월요일 아침에 리눅스 VM을 새로 생성하고, 해당 리눅스 기계에 필요한 모든 소프트웨어 스택을 추가하는 등의 작업을 할 수 있는 간단한 bash 스크립트로 VAGRANTFILE을 감쌀 수 있습니다.
면접에서 스크립팅 경험 관련 질문이 점점 더 많아지고 있다는 소식도 종종 듣고 있습니다.
### 시작하기
이 90일 동안 다루는 많은 것들과 마찬가지로, 진정한 배움은 경험을 통해 알게 됩니다. 실제로 경험을 통해 배우면 기억에 오래 남습니다.
우선, 텍스트 에디터가 필요합니다. [Day 17](day17.md)에 가장 일반적인 텍스트 에디터 두 가지와 그것들을 어떻게 사용하는지에 대해 다뤘습니다.
첫 번째 shell 스크립트를 생성해봅시다.
`touch 90DaysOfDevOps.sh`
그다음 `nano 90DaysOfDevOps.sh`를 입력하면 nano에서 새로운 빈 shell 스크립트가 열립니다. 여기서 원하는 텍스트 에디터를 선택할 수 있습니다.
모든 bash 스크립트의 첫 줄은 다음과 같아야 합니다: `#!/usr/bin/bash`(bash 바이너리의 경로입니다.)
터미널에서 `which bash`를 실행하여 이를 확인해야 합니다. Ubuntu를 사용하지 않는 경우 터미널에서는 `whereis bash`도 시도해 볼 수 있습니다.
그러나 이미 생성된 shell 스크립트는 다른 경로들이 있을 수도 있습니다:
- `#!/bin/bash`
- `#!/usr/bin/env bash`
스크립트의 다음 줄에는 주석을 추가하여 스크립트의 목적이나 스크립트에 대한 정보를 제공합니다. `#`을 사용하면 코드의 특정 줄에 주석을 달고 다가올 명령어가 무엇을 할 것인지 설명할 수 있습니다. 주석을 많이 남길수록 사용자 경험이 향상된다고 생각합니다. 특히 공유할 때 그렇습니다.
리눅스 섹션에서 설치한 figlet 프로그램을 사용하여 스크립트에서 asci 아트를 만들 때도 있습니다.
![](/2022/Days/Images/Day19_Linux1.png)
이 리눅스 섹션에서 앞서 다룬 모든 명령어들([Day 15](day15.md))은 스크립트를 테스트하는 간단한 명령어로 사용할 수 있습니다.
스크립트에 간단한 코드 블록을 추가해 봅시다.
```bash
mkdir 90DaysOfDevOps
cd 90DaysOfDevOps
touch Day19
ls
```
텍스트 에디터를 저장하고 종료한 후, `./90DaysOfDevOps.sh`를 실행하면 권한이 거부되었다는 메시지가 표시됩니다. `ls -al` 명령을 사용하여 이 파일의 권한을 확인할 수 있는데 이 파일에 실행 권한이 없음을 확인할 수 있습니다.
![](/2022/Days/Images/Day19_Linux2.png)
`chmod +x 90DaysOfDevOps.sh`를 사용하여 이를 변경한 다음 `x`인 것을 봤을 때 스크립트를 실행할 수 있음을 확인할 수 있습니다.
![](/2022/Days/Images/Day19_Linux3.png)
`./90DaysOfDevOps.sh`를 사용하여 스크립트를 다시 실행할 수 있습니다. 스크립트를 실행한 후 새 디렉토리가 생성되고 해당 디렉토리로 이동한 다음 새 파일이 생성됩니다.
![](/2022/Days/Images/Day19_Linux4.png)
기본적인 것들이지만, 다른 도구를 호출하여 일상적인 작업을 쉽게 만들고 자동화하는 데 사용할 수 있다는 것을 알 수 있습니다.
### 변수, 조건문
이 섹션의 대부분은 Golang을 배울 때 다룬 것과 중복되지만, 여기에서 다시 살펴볼 가치가 있다고 생각합니다.
- ### 변수
변수를 사용하면 스크립트 내에서 반복되는 특정 용어를 한 번만 정의할 수 있습니다.
스크립트에 변수를 추가하려면 다음과 같이 새로운 줄에 입력하면 됩니다.
`challenge="90DaysOfDevOps"`
이렇게 하면 코드에서 `$challenge`를 사용할 때 변수가 변경되면 전체에 반영됩니다.
![](/2022/Days/Images/Day19_Linux5.png)
이제 `sh` 스크립트를 실행하면 스크립트에 추가된 출력이 표시됩니다.
![](/2022/Days/Images/Day19_Linux6.png)
또한 다음과 같이 사용자 입력을 요청하여 변수를 설정할 수도 있습니다:
```bash
echo "Enter your name"
read name
```
이렇게 하면 입력이 변수 `$name`으로 정의됩니다. 이후에 이를 사용할 수 있습니다.
- ### 조건문
우리는 도전 과제에 참여한 사람과 그들이 완료한 날짜 수를 알아보고 싶을 수도 있습니다. 이를 `if`, `if-else`, `else-if` 조건문을 사용해 정의할 수 있습니다. 아래 스크립트에 이를 정의한 것을 확인할 수 있습니다.
```bash
#!/bin/bash
# ___ ___ ____ ___ __ ____ ___
# / _ \ / _ \| _ \ __ _ _ _ ___ / _ \ / _| _ \ _____ __/ _ \ _ __ ___
#| (_) | | | | | | |/ _` | | | / __| | | | |_| | | |/ _ \ \ / / | | | '_ \/ __|
# \__, | |_| | |_| | (_| | |_| \__ \ |_| | _| |_| | __/\ V /| |_| | |_) \__ \
# /_/ \___/|____/ \__,_|\__, |___/\___/|_| |____/ \___| \_/ \___/| .__/|___/
# |___/ |_|
#
# 이 스크립트는 bash 스크립팅을 시연하기 위한 것입니다!
# 정의할 변수
ChallengeName=#90DaysOfDevOps
TotalDays=90
# 사용자 입력
echo "Enter Your Name"
read name
echo "Welcome $name to $ChallengeName"
echo "How Many Days of the $ChallengeName challenge have you completed?"
read DaysCompleted
if [ $DaysCompleted -eq 90 ]
then
echo "You have finished, well done"
elif [ $DaysCompleted -lt 90 ]
then
echo "Keep going you are doing great"
else
echo "You have entered the wrong amount of days"
fi
```
다음 단계로 이동하기 위해 값을 비교하거나 확인하는 과정을 위에서 볼 수 있습니다. 여기서 주목할 만한 다양한 옵션이 있습니다.
- `eq` - 두 값이 같으면 TRUE 반환
- `ne` - 두 값이 같지 않으면 TRUE 반환
- `gt` - 첫 번째 값이 두 번째 값보다 크면 TRUE 반환
- `ge` - 첫 번째 값이 두 번째 값보다 크거나 같으면 TRUE 반환
- `lt` - 첫 번째 값이 두 번째 값보다 작으면 TRUE 반환
- `le` - 첫 번째 값이 두 번째 값보다 작거나 같으면 TRUE 반환
파일 및 폴더에 대한 정보를 결정하기 위해 bash 스크립팅을 사용할 수도 있습니다. 이를 파일 조건이라고 합니다.
- `-d file` 파일이 디렉토리인 경우 True
- `-e file` 파일이 존재하는 경우 True
- `-f file` 제공된 문자열이 파일인 경우 True
- `-g file` 파일에 그룹 ID가 설정된 경우 True
- `-r file` 파일이 읽을 수 있는 경우 True
- `-s file` 파일의 크기가 0이 아닌 경우 True
```bash
FILE="90DaysOfDevOps.txt"
if [ -f "$FILE" ]
then
echo "$FILE is a file"
else
echo "$FILE is not a file"
fi
```
![](/2022/Days/Images/Day19_Linux7.png)
디렉토리에 파일이 아직 있다면 첫 번째 echo를 반환해야 합니다. 그러나 파일을 제거하면 두 번째 echo를 반환하게 됩니다.
![](/2022/Days/Images/Day19_Linux8.png)
특정 항목을 시스템에서 검색할 때 시간을 절약하는 데 사용할 수 있는 방법을 확인하실 수 있습니다.
GitHub에서 놀라운 저장소를 발견했습니다. 많은 스크립트를 가진 것 같습니다. [DevOps Bash Tools](https://github.com/HariSekhon/DevOps-Bash-tools/blob/master/README.md)
### 예제
**시나리오**: 우리 회사는 "90DaysOfDevOps"라는 이름을 가지고 있으며, 이제 확장할 때가 왔습니다. 1인 팀에서 다음 몇 주 동안 더 많은 사람으로 늘리려고 합니다. 지금까지 나만이 온보딩 과정을 알고 있으므로, 이러한 작업 중 일부를 자동화하여 병목 현상을 줄이고자 합니다.
**요구 사항**:
- 사용자 이름이 커맨드 라인 인수로 전달될 수 있습니다.
- 커맨드 라인 인수의 이름으로 사용자가 생성됩니다.
- password가 커맨드 라인 인수로 전달될 수 있습니다.
- 사용자의 password가 설정됩니다.
- 계정 생성이 성공적으로 이루어졌음을 나타내는 메시지가 표시됩니다.
먼저 `touch create_user.sh`를 사용하여 shell 스크립트를 생성합시다.
계속 진행하기 전에, `chmod +x create_user.sh`를 사용하여 이를 실행 가능하게 만들어줍시다.
그런 다음 `nano create_user.sh`를 사용하여 설정한 시나리오에 대한 스크립트 편집을 시작하겠습니다.
첫 번째 요구 사항인 "사용자 이름이 커맨드 라인 인수로 전달될 수 있습니다."는 다음과 같이 사용할 수 있습니다.
```bash
#! /usr/bin/bash
# 사용자 이름이 커맨드 라인 인수로 전달될 수 있습니다.
echo "$1"
```
![](/2022/Days/Images/Day19_Linux9.png)
이를 실행하려면 `./create_user.sh Michael`을 사용하십시오. Michael 대신에 당신의 이름을 사용하세요.
![](/2022/Days/Images/Day19_Linux10.png)
다음으로 두 번째 요구 사항인 "커맨드 라인 인수의 이름으로 사용자가 생성됩니다."를 처리할 수 있습니다. 이는 `useradd` 명령어를 사용하여 수행할 수 있습니다. `-m` 옵션은 사용자 홈 디렉토리를 /home/username으로 생성하기 위한 것입니다.
```bash
#! /usr/bin/bash
# 사용자 이름이 커맨드 라인 인수로 전달될 수 있습니다.
echo "$1 user account being created."
# 커맨드 라인 인수의 이름으로 사용자가 생성됩니다.
sudo useradd -m "$1"
```
경고: 사용자 계정 이름을 제공하지 않으면 `$1` 변수가 채워지지 않아 오류가 발생합니다.
계정이 생성되었는지 확인하려면 `awk -F: '{ print $1}' /etc/passwd` 명령을 사용합니다.
![](/2022/Days/Images/Day19_Linux11.png)
다음 요구 사항은 "password가 커맨드 라인 인수로 전달될 수 있습니다."입니다. 먼저, 이는 실제 환경에서는 절대 사용하지 않는 것이 좋습니다. 이는 단지 연습을 위한 것이며, 이를 통해 요구 사항을 이해할 수 있습니다.
```bash
#! /usr/bin/bash
# 사용자 이름이 커맨드 라인 인수로 전달될 수 있습니다.
echo "$1 user account being created."
# 커맨드 라인 인수의 이름으로 사용자가 생성됩니다.
sudo useradd -m "$1"
# password가 커맨드 라인 인수로 전달될 수 있습니다.
sudo chpasswd <<< "$1":"$2"
```
두 개의 파라미터로 이 스크립트를 실행하려면 `./create_user.sh 90DaysOfDevOps password`를 사용하세요.
아래 이미지에서 스크립트를 실행하여 사용자와 password를 생성한 다음, 수동으로 해당 사용자로 전환하고 `whoami` 명령으로 확인했다는 것을 알 수 있습니다.
![](/2022/Days/Images/Day19_Linux12.png)
마지막 요구 사항은 "계정 생성이 성공적으로 이루어졌음을 나타내는 메시지가 표시됩니다."입니다. 우리는 이미 코드의 첫 번째 줄에 이를 포함하고 있으며, 위의 스크린샷에서 `90DaysOfDevOps user account being created`라는 메시지가 표시되는 것을 볼 수 있습니다. 이는 `$1` 매개변수로 테스트할 때 남겨진 것입니다.
이제 이 스크립트를 사용하여 리눅스 시스템에 새 사용자를 빠르게 온보딩하고 설정할 수 있습니다. 하지만 기존 사용자 중 몇 명이 이 과정을 거쳐 다른 사람들에게 새 사용자 이름이나 password를 알려주는 대신 앞서 다룬 사용자 입력을 추가하여 변수를 수집할 수 있습니다.
```bash
#! /usr/bin/bash
echo "What is your intended username?"
read username
echo "What is your password"
read password
# 사용자 이름이 커맨드 라인 인수로 전달될 수 있습니다.
echo "$username user account being created."
# 커맨드 라인 인수의 이름으로 사용자가 생성됩니다.
sudo useradd -m $username
# password가 커맨드 라인 인수로 전달될 수 있습니다.
sudo chpasswd <<< $username:$password
```
단계를 더욱 인터랙티브하게 만들면
![](/2022/Days/Images/Day19_Linux14.png)
마무리하기 위해, 새 사용자 계정이 생성되었다는 성공적인 출력을 원할 수도 있습니다.
![](/2022/Days/Images/Day19_Linux15.png)
한 가지 눈에 띄는 점은 입력 시 비밀번호가 표시된다는 점인데, 코드 `read -s password`에서의 `-s` 플래그를 사용하여 이를 숨길 수 있습니다.
![](/2022/Days/Images/Day19_Linux16.png)
실험 목적으로 생성한 사용자를 삭제하려면 `sudo userdel test_user`를 사용할 수 있습니다.
[예제 스크립트](/2022/Days/Linux/create-user.sh)
한 번 더 강조하고 싶은 바는, 이것은 shell 스크립팅이 유연하게 활용될 수 있는 다양한 용도를 갖는다는 것을 강조하기 위해 만들어진 것이라는 것입니다.
매일, 매주, 매월 반복되는 작업이 어떤 것이 있는지 생각해보고, 그것을 어떻게 더 잘 자동화할 수 있을지 생각해보세요. 첫 번째 옵션은 주로 bash 스크립트를 사용하는 것이며, 그 이후에는 더 복잡한 영역으로 이동할 수 있습니다.
저는 제 로컬 머신에서 minikube를 사용하여 쿠버네티스 클러스터를 빠르게 생성하고 데이터 서비스 및 Kasten K10을 사용하여 데이터 관리에 대한 요구 사항과 필요성을 보여주기 위한 매우 간단한 [bash 파일](https://github.com/MichaelCade/project_pace/blob/main/singlecluster_demo.sh)을 생성했습니다만, 아직 쿠버네티스를 다루지 않았기 때문에 여기서 다루는 것이 적절하지 않다고 생각합니다.
## 자료
- [Bash in 100 seconds](https://www.youtube.com/watch?v=I4EWvMFj37g)
- [Bash script with practical examples - Full Course](https://www.youtube.com/watch?v=TPRSJbtfK4M)
- [Client SSH GUI - Remmina](https://remmina.org/)
- [The Beginner's guide to SSH](https://www.youtube.com/watch?v=2QXkrLVsRmk)
- [Vim in 100 Seconds](https://www.youtube.com/watch?v=-txKSRn0qeA)
- [Vim tutorial](https://www.youtube.com/watch?v=IiwGbcd8S7I)
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
[Day 20](day20.md)에서 봐요!

166
2022/ko/Days/day20.md Normal file
View File

@ -0,0 +1,166 @@
---
title: '#90DaysOfDevOps - Dev workstation setup - All the pretty things - Day 20'
published: false
description: 90DaysOfDevOps - Dev workstation setup - All the pretty things
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048734
---
## 개발 워크스테이션 설정 - 예쁜 모든 것들
이 내용은 Linux 서버를 설정하는 것과 혼동되지 않도록 주의해야 하며, Linux 데스크톱의 선택성 및 유연성을 보여주고자 합니다.
저는 거의 일 년 동안 Linux 데스크톱을 사용해 왔고, 외관과 느낌 측면에서 원하는 대로 구성했습니다. Ubuntu VM과 Virtual Box를 이용하여 사용자 지정 맞춤 구성을 해봅시다.
더 쉽게 따라 할 수 있는 분들을 위해 설명 외의 부분에 대한 YouTube 동영상을 준비했습니다.
[![Click to access YouTube Video](/2022/Days/Images/Day20_YouTube.png)](https://youtu.be/jeEslAtHfKc)
기본적으로 시스템은 아래와 같이 표시됩니다.
![](/2022/Days/Images/Day20_Linux1.png)
기본 bash shell은 아래에서 볼 수 있습니다.
![](/2022/Days/Images/Day20_Linux2.png)
이 중 많은 부분이 dotfiles와 관련이 있으며, 이 시리즈의 마지막 Linux 세션에서 다루게 됐습니다.
### dotfiles
먼저 dotfiles에 대해 알아보고 싶습니다. 리눅스가 구성 파일로 구성되어 있다고 이전에 언급했습니다. 이 dotfiles는 리눅스 시스템과 응용 프로그램의 구성 파일입니다.
또한 dotfiles는 데스크톱을 꾸미고 예쁘게 만드는 데 사용되는 것뿐만 아니라 생산성을 돕는 구성 변경 및 설정이 있다고 덧붙입니다.
앞서 언급했듯이 많은 소프트웨어 프로그램들이 이 dotfiles에 구성을 저장합니다. 이 dotfiles는 기능 관리를 돕습니다.
각 dotfile은 `.`으로 시작합니다. 이름이 어떻게 지어졌는지 짐작할 수 있을 것입니다.
지금까지 우리는 shell로서 bash를 사용해 왔으므로 홈 폴더에 .bashrc와 .bash_profile이 있을 것입니다. 아래에서 시스템에 있는 몇 가지 dotfiles를 볼 수 있습니다.
![](/2022/Days/Images/Day20_Linux3.png)
우리는 shell을 변경할 것이므로, 나중에 새로운 `.zshrc` dotfile을 볼 수 있습니다.
dotfiles은 구성 파일임을 알 수 있습니다. 우리는 이것들을 사용하여 명령 프롬프트에 별칭을 추가하거나 다른 위치로 경로를 추가할 수 있습니다. 일부 사람들은 자신의 dotfiles를 공개적으로 사용할 수 있도록 게시합니다. 제 dotfiles는 [MichaelCade/dotfiles](https://github.com/MichaelCade/dotfiles)에서 찾을 수 있습니다. 여기에는 저의 맞춤형 `.zshrc` 파일, 제가 선택한 터미널인 terminator의 구성 파일이 폴더에 있고, 그리고 일부 배경 옵션이 있습니다.
### ZSH
앞에서 언급했듯이, 지금까지의 상호 작용에서 우리는 기본 shell인 Ubuntu와 함께 제공되는 bash shell을 사용했습니다. ZSH는 매우 유사하지만, bash보다 몇 가지 이점이 있습니다.
Zsh에는 대화형 탭 완성, 자동 파일 검색, 정규식 통합, 명령 범위를 정의하는 고급 단축어 및 풍부한 테마 엔진과 같은 기능이 있습니다.
우리는 `apt` 패키지 관리자를 사용하여 시스템에 zsh를 설치할 수 있습니다. bash 터미널에서 `sudo apt install zsh`를 실행해 봅시다. 이 작업은 VM 콘솔 내에서 수행할 예정이며 SSH를 통해 연결하는 대신에 진행합니다.
설치 명령이 완료되면 터미널 내에서 `zsh`를 실행할 수 있으며, 이렇게 하면 shell 구성 스크립트가 시작됩니다.
![](/2022/Days/Images/Day20_Linux4.png)
위 질문에 대해 `1`을 선택했고, 이제 더 많은 옵션을 볼 수 있습니다.
![](/2022/Days/Images/Day20_Linux5.png)
이 메뉴에서 몇 가지 기본 제공 편집을 통해 필요에 따라 ZSH를 구성할 수 있음을 알 수 있습니다.
`0`으로 종료한 다음 `ls -al | grep .zshrc`를 사용하면 새로운 구성 파일이 있는 것을 확인할 수 있습니다.
이제 우리는 터미널을 열 때마다 zsh를 기본 shell로 사용하려고 합니다. 이를 위해 shell을 변경하는 `chsh -s $(which zsh)` 명령을 실행할 수 있습니다. 그런 다음 로그아웃하고 다시 로그인하여 변경 사항이 적용되도록 해야 합니다.
로그인 후 터미널을 열면 아래와 같이 보일 것입니다. 또한 `which $SHELL`을 실행하여 shell이 변경되었음을 확인할 수 있습니다.
![](/2022/Days/Images/Day20_Linux6.png)
일반적으로 저는 각 Ubuntu 데스크톱에서 이 단계를 수행하며, 이 외에도 zsh shell이 bash보다 약간 빠르다고 느낍니다.
### OhMyZSH
다음으로 터미널 내에서 조금 더 나은 모습과 추가 기능을 제공하고자 합니다.
OhMyZSH는 zsh 구성을 관리하기 위한 무료 오픈 소스 프레임워크입니다. 플러그인, 테마 등 많은 것들이 있어 zsh shell과 상호 작용하는 것이 훨씬 재밌습니다.
[ohmyzsh](https://ohmyz.sh/)에 대한 자세한 정보를 확인해보세요.
Oh My ZSH를 설치합시다. `curl`, `wget` 또는 `fetch` 중에서 선택할 수 있는데, 첫 번째 두 가지는 시스템에서 사용 가능하지만, `curl`로 시작하겠습니다.
`sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"`
위 명령을 실행하면 아래와 같은 출력을 볼 수 있습니다.
![](/2022/Days/Images/Day20_Linux7.png)
이제 우리의 경험을 위한 테마를 시작할 수 있습니다. Oh My ZSH에는 100개 이상의 테마가 포함되어 있지만, 저의 모든 애플리케이션과 모든 것에 대한 기본값은 Dracula 테마입니다.
또한 Oh My ZSH를 사용할 때 다음 두 가지 플러그인을 반드시 사용해야 한다고 강조하고 싶습니다.
`git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions`
`git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting`
`nano ~/.zshrc`
플러그인을 편집하여 이제 `plugins=(git zsh-autosuggestions zsh-syntax-highlighting)`를 포함하도록 합니다.
### Gnome Extensions
저는 Gnome Extensions도 사용하며, 특히 아래 목록을 사용합니다.
[Gnome extensions](https://extensions.gnome.org)
- Caffeine
- CPU Power Manager
- Dash to Dock
- Desktop Icons
- User Themes
## 소프트웨어 설치
`apt`를 사용하여 제 컴퓨터에 설치한 프로그램 목록입니다.
- VSCode
- azure-cli
- containerd.io
- docker
- docker-ce
- google-cloud-sdk
- insomnia
- packer
- terminator
- terraform
- vagrant
### Dracula 테마
[Dracula Theme](https://draculatheme.com/)는 제가 유일하게 사용하는 테마입니다. 깔끔하고 명확한 모습이며 모든 것이 훌륭해 보입니다. 이 사이트에서는 컴퓨터에서 사용하는 다양한 프로그램을 지원합니다.
위 링크에서 zsh를 검색하면 최소 두 가지 옵션을 찾을 수 있습니다.
수동 설치 또는 git을 사용하여 설치할 수 있는 지침을 따릅니다. 그런 다음 아래와 같이 `.zshrc` 구성 파일을 편집해야 합니다.
![](/2022/Days/Images/Day20_Linux8.png)
다음으로 [Gnome Terminal Dracula theme](https://draculatheme.com/gnome-terminal)를 원하게 될 텐데, 여기에 모든 지침이 나와 있습니다.
모든 단계를 문서화하는 데 오랜 시간이 걸릴 것이므로, 저는 과정을 동영상으로 제공했습니다.(아래 이미지를 클릭하세요)
[![](/2022/Days/Images/Day20_YouTube.png)](https://youtu.be/jeEslAtHfKc)
여기까지 왔다면, 이제 #90DaysOfDevOps의 Linux 섹션을 완료했습니다. 다시 한번, 피드백과 추가 자료에 대해서는 언제든지 환영입니다.
여기에 적는 것보다 동영상을 통해 많은 단계를 보여드리는 것이 더 쉬울거라고 생각했는데, 이에 대해 어떻게 생각하시나요? 저는 이 글을 다시 읽어보고 가능하면 동영상 연습을 만들어서 우리가 다룬 내용들을 더 잘 설명하고 보여줄 수 있도록 하고자 합니다. 어떻게 생각하시나요?
## 자료
- [Bash in 100 seconds](https://www.youtube.com/watch?v=I4EWvMFj37g)
- [Bash script with practical examples - Full Course](https://www.youtube.com/watch?v=TPRSJbtfK4M)
- [Client SSH GUI - Remmina](https://remmina.org/)
- [The Beginner's guide to SSH](https://www.youtube.com/watch?v=2QXkrLVsRmk)
- [Vim in 100 Seconds](https://www.youtube.com/watch?v=-txKSRn0qeA)
- [Vim tutorial](https://www.youtube.com/watch?v=IiwGbcd8S7I)
- [Learn the Linux Fundamentals - Part 1](https://www.youtube.com/watch?v=kPylihJRG70)
- [Linux for hackers (don't worry you don't need to be a hacker!)](https://www.youtube.com/watch?v=VbEx7B_PTOE)
내일부터 7일간 네트워킹에 대해 알아보는 시간을 가지며, 데브옵스와 관련된 네트워킹에 대한 기초적인 지식과 이해를 쌓을 것입니다.
[Day 21](day21.md)에서 봐요!

115
2022/ko/Days/day21.md Normal file
View File

@ -0,0 +1,115 @@
---
title: '#90DaysOfDevOps - The Big Picture: DevOps and Networking - Day 21'
published: false
description: 90DaysOfDevOps - The Big Picture DevOps and Networking
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048761
---
## 큰 그림: 데브옵스와 네트워킹
모든 섹션과 마찬가지로 공개 및 무료 교육 자료를 사용하고 있으며 많은 콘텐츠가 다른 사람의 저작물일 수 있습니다. 네트워킹 섹션의 경우, 표시된 콘텐츠의 대부분은 [Practical Networking](https://www.practicalnetworking.net/)의 무료 [Networking Fundamentals series](https://www.youtube.com/playlist?list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi)에서 가져온 것입니다. 리소스에도 링크와 함께 언급되어 있지만 커뮤니티의 관점에서 특정 기술 분야에 대한 이해를 돕기 위해 이 과정을 활용했기 때문에 이 점을 강조하는 것이 적절합니다. 이 저장소는 제 메모를 저장하고 커뮤니티가 이 과정과 나열된 리소스로부터 혜택을 받을 수 있도록 하는 저장소입니다.
21일 차에 오신 것을 환영합니다! 앞으로 7일 동안 네트워킹과 데브옵스가 가장 중요한 주제이지만, 네트워킹의 기본에 대해서도 살펴볼 필요가 있을 것입니다.
궁극적으로 앞서 말씀드렸듯이 데브옵스는 조직 내 문화와 프로세스 변화에 관한 것으로, 앞서 논의한 것처럼 가상 머신, 컨테이너 또는 Kubernetes가 될 수도 있지만 네트워크가 될 수도 있습니다. 데브옵스 관점에서 네트워크를 더 많이 포함해야 하는 인프라에 이러한 데브옵스 원칙을 사용한다면 사용 가능한 다양한 Topology 및 네트워킹 도구와 스택에서와 같이 네트워크에 대해서도 알아야 합니다.
저는 코드로 인프라스트럭처의 네트워킹 디바이스를 구성하고 가상 머신처럼 모든 것을 자동화해야 한다고 주장하지만, 그렇게 하려면 무엇을 자동화할지 잘 이해해야 합니다.
### 넷데브옵스 | 네트워크 데브옵스란 무엇인가요?
네트워크 데브옵스 또는 넷데브옵스라는 용어를 들어보셨을 수도 있습니다. 이미 네트워크 엔지니어이고 인프라 내의 네트워크 구성 요소를 잘 파악하고 있다면 DHCP, DNS, NAT 등과 같은 네트워킹에 사용되는 요소를 이해하고 있을 것입니다. 또한 하드웨어 또는 소프트웨어 정의 네트워킹 옵션, 스위치, 라우터 등에 대해서도 잘 이해하고 있을 것입니다.
하지만 네트워크 엔지니어가 아니라면 네트워크 데브옵스의 최종 목표를 이해하려면 이러한 영역 중 일부에 대한 전반적인 기초 지식이 필요할 수 있습니다.
그러나 이러한 용어와 관련하여 NetDevOps 또는 네트워크 데브옵스를 네트워크에 데브옵스 원칙과 관행을 적용하고 버전 제어 및 자동화 도구를 네트워크 생성, 테스트, 모니터링 및 배포에 적용하는 것으로 생각할 수 있습니다.
네트워크 데브옵스를 자동화가 필요한 것으로 생각한다면, 앞서 데브옵스가 팀 간의 사일로를 허무는 것에 대해 언급했습니다. 네트워킹 팀이 유사한 모델과 프로세스로 변경하지 않으면 병목 현상이 발생하거나 전체적으로 장애가 발생할 수 있습니다.
프로비저닝, 구성, 테스트, 버전 제어 및 배포와 관련된 자동화 원칙을 사용하는 것이 좋은 출발점입니다. 자동화는 전반적으로 배포 속도, 네트워킹 인프라의 안정성, 지속적인 개선을 가능하게 할 뿐만 아니라 테스트가 완료되면 여러 환경에서 프로세스를 공유할 수 있습니다. 예를 들어 한 환경에서 완전히 테스트 된 네트워크 정책은 이전에는 수동으로 작성된 프로세스와 달리 코드로 되어 있기 때문에 다른 위치에서도 빠르게 사용할 수 있습니다.
이러한 사고에 대한 좋은 관점과 개요는 여기에서 찾을 수 있습니다. [Network DevOps](https://www.thousandeyes.com/learning/techtorials/network-devops)
## 네트워킹 기본 사항
여기서는 데브옵스 측면은 잠시 접어두고 이제 네트워킹의 기본 사항에 대해 간략히 살펴보겠습니다.
### 네트워크 장치
이 콘텐츠를 동영상으로 보고 싶으시다면 Practical Networking에서 다음 동영상을 확인하세요:
- [Network Devices - Hosts, IP Addresses, Networks - Networking Fundamentals - Lesson 1a](https://www.youtube.com/watch?v=bj-Yfakjllc&list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi&index=1)
- [Network Devices - Hub, Bridge, Switch, Router - Networking Fundamentals - Lesson 1b](https://www.youtube.com/watch?v=H7-NR3Q3BeI&list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi&index=2)
**호스트**는 트래픽을 보내거나 받는 모든 장치입니다.
![](/2022/Days/Images/Day21_Networking1.png)
**IP 주소**는 각 호스트의 신원입니다.
![](/2022/Days/Images/Day21_Networking2.png)
**네트워크**는 호스트 간에 트래픽을 전송하는 역할을 합니다. 네트워크가 없다면 데이터를 수동으로 많이 이동해야 할 것입니다!
비슷한 연결이 필요한 호스트의 논리적 그룹입니다.
![](/2022/Days/Images/Day21_Networking3.png)
**스위치**는 네트워크 내에서 통신을 촉진합니다. 스위치는 호스트 간에 데이터 패킷을 전달합니다. 스위치는 호스트에 직접 패킷을 보냅니다.
- 네트워크: 유사한 연결이 필요한 호스트들의 그룹.
- 네트워크의 호스트는 동일한 IP 주소 공간을 공유합니다.
![](/2022/Days/Images/Day21_Networking4.png)
**라우터**는 네트워크 간의 통신을 용이하게 합니다. 앞서 스위치가 네트워크 내의 통신을 관리한다고 말했듯이 라우터는 이러한 네트워크를 함께 연결하거나 최소한 허용되는 경우 서로에 대한 액세스 권한을 부여할 수 있게 해줍니다.
라우터는 트래픽 제어 지점(보안, 필터링, 리디렉션)을 제공할 수 있습니다. 최근에는 이러한 기능 중 일부를 제공하는 스위치도 점점 더 많아지고 있습니다.
라우터는 자신이 연결된 네트워크를 학습합니다. 이를 라우트라고 하며 라우팅 테이블은 라우터가 알고 있는 모든 네트워크입니다.
라우터는 연결된 네트워크에 IP 주소를 가지고 있습니다. 이 IP는 게이트웨이라고도 하는 각 호스트가 로컬 네트워크에서 나가는 통로가 되기도 합니다.
라우터는 또한 앞서 언급한 네트워크에서 계층 구조를 생성합니다.
![](/2022/Days/Images/Day21_Networking5.png)
## 스위치 대 라우터
**라우팅**은 네트워크 간에 데이터를 이동하는 프로세스입니다.
- 라우터는 라우팅을 주요 목적으로 하는 장치입니다.
**스위칭**은 네트워크 내에서 데이터를 이동하는 프로세스입니다.
- 스위치는 스위칭을 주목적으로 하는 장치입니다.
다음과 같이 다양한 네트워크 장치가 있다는 것을 알고 있으므로 이는 장치에 대한 기본적인 개요입니다:
- 액세스 포인트
- 방화벽
- 로드 밸런서
- 레이어 3 스위치
- IDS/IPS
- 프록시
- 가상 스위치
- 가상 라우터
이러한 모든 장치는 라우팅 및/또는 스위칭을 수행합니다.
앞으로 며칠 동안 이 목록에 대해 조금 더 자세히 알아보도록 하겠습니다.
- OSI 모델
- 네트워크 프로토콜
- DNS(도메인 이름 시스템)
- NAT
- DHCP
- 서브넷
## 자료
- [Networking Fundamentals](https://www.youtube.com/playlist?list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi)
- [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
[Day 22](day22.md)에서 봐요!

111
2022/ko/Days/day22.md Normal file
View File

@ -0,0 +1,111 @@
---
title: '#90DaysOfDevOps - The OSI Model - The 7 Layers - Day 22'
published: false
description: 90DaysOfDevOps - The OSI Model - The 7 Layers
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049037
---
아래 콘텐츠는 대부분 실용적인 네트워킹의 [Networking Fundamentals series](https://www.youtube.com/playlist?list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi)에서 가져온 것입니다. 이 콘텐츠를 동영상으로 보고 싶으시다면 다음 두 동영상을 확인해 보세요:
- [The OSI Model: A Practical Perspective - Layers 1 / 2 / 3](https://www.youtube.com/watch?v=LkolbURrtTs&list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi&index=3)
- [The OSI Model: A Practical Perspective - Layers 4 / 5+](https://www.youtube.com/watch?v=0aGqGKrRE0g&list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi&index=4)
## OSI 모델 - 7개의 Layers
산업으로서 네트워킹의 전반적인 목적은 두 호스트가 데이터를 공유할 수 있도록 하는 것입니다. 네트워킹 이전에는 이 호스트에서 이 호스트로 데이터를 가져오려면 이 호스트에 무언가를 꽂고 다른 호스트에 가서 다른 호스트에 꽂아야 했습니다.
네트워킹을 사용하면 호스트가 유선을 통해 데이터를 자동으로 공유할 수 있으므로 이 작업을 자동화할 수 있으며, 이 작업을 수행하려면 호스트가 일련의 규칙을 따라야 합니다.
이는 모든 언어와 다르지 않습니다. 영어에는 두 명의 영어 사용자가 따라야 하는 일련의 규칙이 있습니다. 스페인어에도 고유한 규칙이 있습니다. 프랑스어에는 고유한 규칙이 있으며, 네트워킹에도 고유한 규칙이 있습니다.
네트워킹에 대한 규칙은 7가지 계층으로 나뉘며, 이러한 계층을 OSI 모델이라고 합니다.
### OSI 모델 소개
OSI 모델(개방형 시스템 상호 연결 모델)은 네트워킹 시스템의 기능을 설명하는 데 사용되는 프레임워크입니다. OSI 모델은 서로 다른 제품과 소프트웨어 간의 상호 운용성을 지원하기 위해 컴퓨팅 기능을 보편적인 규칙과 요구 사항으로 특성화합니다. OSI 참조 모델에서 컴퓨팅 시스템 간의 통신은 7가지 추상화 계층으로 나뉩니다: **물리적, 데이터 링크, 네트워크, 전송, 세션, 프레젠테이션 및 애플리케이션**.
![](/2022/Days/Images/Day22_Networking1.png)
### 물리적
OSI 모델에서 Layer 1은 물리적이라고 하며, 물리적 케이블 등 수단을 통해 한 호스트에서 다른 호스트로 데이터를 전송할 수 있다는 전제하에 이 Layer에서도 Wi-Fi를 고려할 수 있습니다. 또한 한 호스트에서 다른 호스트로 데이터를 전송하기 위해 허브와 중계기 주변에서 더 많은 레거시 하드웨어를 볼 수 있습니다.
![](/2022/Days/Images/Day22_Networking2.png)
### 데이터 링크
Layer 2의 데이터 링크는 데이터가 프레임으로 패키지화되는 노드 간 전송을 가능하게 합니다. 또한 물리 계층에서 발생했을 수 있는 오류를 수정하는 수준도 있습니다. 또한 이 단계에서 MAC 주소가 도입되거나 처음 등장합니다.
네트워킹 첫날인 [Day 21](day21.md)
에서 다룬 스위치에 대한 첫 번째 언급도 여기에서 볼 수 있습니다.
![](/2022/Days/Images/Day22_Networking3.png)
### 네트워크
Layer 3 스위치 또는 Layer 2 스위치라는 용어를 들어보셨을 것입니다. OSI 모델인 Layer 3에서 네트워크는 End to End 전송을 목표로 하며, 첫날 개요에서 언급한 IP 주소가 있는 곳입니다.
라우터와 호스트는 Layer 3에 존재하며, 라우터는 여러 네트워크 간에 라우팅하는 기능이라는 점을 기억하세요. IP가 있는 모든 것은 Layer 3으로 간주할 수 있습니다.
![](/2022/Days/Images/Day22_Networking4.png)
그렇다면 왜 Layer 2와 3 모두에 주소 체계가 필요할까요? (MAC 주소와 IP 주소)
한 호스트에서 다른 호스트로 데이터를 전송하는 것을 생각해 보면, 각 호스트에는 IP 주소가 있지만 그사이에는 여러 개의 스위치와 라우터가 있습니다. 각 장치에는 Layer 2 MAC 주소가 있습니다.
Layer 2 MAC 주소는 호스트에서 스위치/라우터로만 이동하며 hop에 중점을 두는 반면, Layer 3 IP 주소는 데이터 패킷이 최종 호스트에 도달할 때까지 해당 패킷을 유지합니다. (End to End)
IP 주소 - Layer 3 = End to End 전송
MAC 주소 - Layer 2 = Hop to Hop 전송
이제 Layer3와 Layer2 주소를 연결하는 ARP(주소 확인 프로토콜)라는 네트워크 프로토콜이 있지만 오늘은 다루지 않겠습니다.
### 전송
서비스 간 전송, Layer 4는 데이터 스트림을 구분하기 위해 존재합니다. Layer 3과 Layer 2에 주소 체계가 있는 것과 마찬가지로 Layer 4에는 포트가 있습니다.
![](/2022/Days/Images/Day22_Networking5.png)
### 세션, 프레젠테이션, 애플리케이션
Layers 5,6,7의 구분이 다소 모호해졌습니다.
보다 최근의 이해를 돕기 위해 [TCP IP Model](https://www.geeksforgeeks.org/tcp-ip-model/)을 살펴보는 것이 좋습니다.
이제 이 네트워킹 스택을 사용하여 호스트가 서로 통신할 때 어떤 일이 일어나는지 설명해 보겠습니다. 이 호스트에는 다른 호스트로 전송할 데이터를 생성하는 애플리케이션이 있습니다.
소스 호스트는 캡슐화 프로세스라고 하는 과정을 거치게 됩니다. 이 데이터는 먼저 Layer 4로 전송됩니다.
Layer 4는 해당 데이터에 헤더를 추가하여 서비스 간 전송이라는 Layer 4의 목표를 용이하게 할 수 있습니다. 이 헤더는 TCP 또는 UDP를 사용하는 포트가 될 것입니다. 또한 소스 포트와 대상 포트도 포함됩니다.
이를 세그먼트(데이터 및 포트)라고도 합니다.
이 세그먼트는 OSI 스택을 통해 네트워크 계층인 Layer 3으로 전달되고, 네트워크 계층은 이 데이터에 또 다른 헤더를 추가합니다.
이 헤더는 End to End 전송이라는 Layer 3의 목표를 달성하기 위한 것으로, 이 헤더에는 소스 IP 주소와 대상 IP가 있으며, 헤더와 데이터를 합쳐 패킷이라고도 합니다.
그러면 Layer 3이 해당 패킷을 받아 Layer 2로 전달하고, Layer 2는 다시 한번 해당 데이터에 또 다른 헤더를 추가하여 Layer 2의 목표인 Hop to Hop 전송을 달성하게 되는데, 이 헤더에는 소스 및 대상 맥 주소가 포함됩니다.
Layer 2 헤더와 데이터가 있을 때 이를 프레임이라고 합니다.
그런 다음 이 프레임은 1과 0으로 변환되어 Layer 1 물리적 케이블 또는 Wi-Fi를 통해 전송됩니다.
![](/2022/Days/Images/Day22_Networking6.png)
위에서 헤더와 데이터의 각 Layer에 대한 네이밍에 대해 언급했지만, 이것도 그려보기로 했습니다.
![](/2022/Days/Images/Day22_Networking7.png)
데이터를 전송하는 애플리케이션은 어딘가로 데이터를 전송하고 있으므로 수신은 스택을 거슬러 올라가 수신 호스트에 전달하기 위해 다소 역방향으로 이루어집니다.
![](/2022/Days/Images/Day22_Networking8.png)
## 자료
- [Networking Fundamentals](https://www.youtube.com/playlist?list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi)
* [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
[Day 23](day23.md)에서 봐요!

122
2022/ko/Days/day23.md Normal file
View File

@ -0,0 +1,122 @@
---
title: '#90DaysOfDevOps - Network Protocols - Day 23'
published: false
description: 90DaysOfDevOps - Network Protocols
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048704
---
아래 콘텐츠는 대부분 실용적인 네트워킹의 [Networking Fundamentals series](https://www.youtube.com/playlist?list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi)에서 가져온 것입니다. 이 콘텐츠를 동영상으로 보고 싶으시다면 이 동영상을 확인해보세요:
- [Network Protocols - ARP, FTP, SMTP, HTTP, SSL, TLS, HTTPS, DNS, DHCP](https://www.youtube.com/watch?v=E5bSumTAHZE&list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi&index=12)
## 네트워크 프로토콜
인터넷 표준을 구성하는 일련의 규칙과 메시지입니다.
- ARP - 주소 확인 프로토콜
ARP에 대해 자세히 알고 싶으시다면 여기에서 인터넷 표준을 읽어보세요. [RFC 826](https://datatracker.ietf.org/doc/html/rfc826)
Layer 2 네트워크에서 IP 주소를 고정된 물리적 컴퓨터 주소(MAC 주소라고도 함)에 연결합니다.
![](/2022/Days/Images/Day23_Networking1.png)
- FTP - 파일 전송 프로토콜
소스에서 대상으로 파일을 전송할 수 있습니다. 일반적으로 이 프로세스는 인증되지만, 익명 액세스를 사용하도록 구성한 경우 사용할 수 있습니다. 이제 더 나은 보안을 위해 클라이언트에서 FTP 서버로 SSL/TLS 연결을 제공하는 FTPS를 더 자주 보게 될 것입니다. 이 프로토콜은 OSI 모델의 애플리케이션 계층에서 찾을 수 있습니다.
![](/2022/Days/Images/Day23_Networking2.png)
- SMTP - 단순 메일 전송 프로토콜
전자 메일 전송에 사용되는 메일 서버는 SMTP를 사용하여 메일 메시지를 보내고 받습니다. Microsoft 365를 사용하더라도 SMTP 프로토콜이 동일한 용도로 사용된다는 것을 알 수 있습니다.
![](/2022/Days/Images/Day23_Networking3.png)
- HTTP - 하이퍼 텍스트 전송 프로토콜
HTTP는 인터넷과 콘텐츠 탐색의 기초입니다. 우리가 즐겨 찾는 웹사이트에 쉽게 액세스할 수 있게 해줍니다. HTTP는 여전히 많이 사용되고 있지만, 대부분의 즐겨 찾는 사이트에서는 HTTPS가 더 많이 사용되고 있거나 사용되어야 합니다.
![](/2022/Days/Images/Day23_Networking4.png)
- SSL - 보안 소켓 계층 | TLS - 전송 계층 보안
SSL의 뒤를 이어 등장한 TLS는 네트워크를 통해 안전한 통신을 제공하는 **암호화 프로토콜**입니다. 메일, 인스턴트 메시징 및 기타 애플리케이션에서 찾을 수 있지만 가장 일반적으로 HTTPS를 보호하는 데 사용됩니다.
![](/2022/Days/Images/Day23_Networking5.png)
- HTTPS - SSL/TLS로 보호되는 HTTP
네트워크를 통한 보안 통신에 사용되는 HTTP의 확장인 HTTPS는 위에서 언급한 것처럼 TLS로 암호화됩니다. 호스트 간에 데이터가 교환되는 동안 인증, 개인 정보 보호 및 무결성을 제공하는 데 중점을 두었습니다.
![](/2022/Days/Images/Day23_Networking6.png)
- DNS - 도메인 이름 시스템
DNS는 인간 친화적인 도메인 이름을 매핑하는 데 사용됩니다. 예를 들어 우리가 모두 알고 있는 [google.com](https://google.com)은 브라우저를 열고 [8.8.8.8](https://8.8.8.8)을 입력하면 우리가 거의 알고 있는 Google이 표시됩니다. 하지만 모든 웹사이트의 IP 주소를 모두 기억하기란 쉽지 않으며, 일부 웹사이트는 정보를 찾기 위해 구글을 사용하기도 합니다.
호스트, 서비스 및 기타 리소스에 연결할 수 있도록 하는 DNS의 역할이 바로 여기에 있습니다.
모든 호스트에서 인터넷 연결이 필요한 경우 해당 도메인 이름을 확인할 수 있도록 DNS가 있어야 합니다. DNS는 며칠 또는 몇 년을 투자하여 학습할 수 있는 영역입니다. 또한 경험상 네트워킹과 관련된 모든 오류의 일반적인 원인은 대부분 DNS라고 말하고 싶습니다. 하지만 네트워크 엔지니어가 동의할지는 모르겠습니다.
![](/2022/Days/Images/Day23_Networking7.png)
- DHCP - 동적 호스트 구성 프로토콜
인터넷에 액세스하거나 서로 간에 파일을 전송하는 등 호스트가 작동하는 데 필요한 프로토콜에 대해 많이 논의했습니다.
이 두 가지 작업을 모두 수행하기 위해 모든 호스트에 필요한 4가지 사항이 있습니다.
- IP 주소
- 서브넷 마스크
- 기본 게이트웨이
- DNS
IP 주소는 호스트가 위치한 네트워크에서 호스트의 고유 주소로, 집 번호라고 생각하시면 됩니다.
서브넷 마스크는 곧 다루겠지만 우편번호나 우편번호로 생각하시면 됩니다.
기본 게이트웨이는 일반적으로 네트워크에서 Layer 3 연결을 제공하는 라우터의 IP입니다. 이를 우리 동네를 빠져나갈 수 있는 하나의 도로라고 생각할 수 있습니다.
그리고 방금 설명한 DNS는 복잡한 공인 IP 주소를 보다 적합하고 기억하기 쉬운 도메인 이름으로 변환하는 데 도움을 줍니다. 어쩌면 이것을 올바른 게시물을 얻기 위한 거대한 분류 사무실이라고 생각할 수 있습니다.
각 호스트마다 이 네 가지가 필요하다고 말씀드렸듯이 호스트가 1,000개 또는 10,000개라면 이 네 가지를 개별적으로 결정하는 데 매우 오랜 시간이 걸릴 것입니다. 이때 DHCP가 등장하여 네트워크의 범위를 결정하면 이 프로토콜이 네트워크에서 사용 가능한 모든 호스트에 배포됩니다.
또 다른 예로 커피숍에 가서 커피를 마시고 노트북이나 휴대폰을 들고 앉았다고 가정해 봅시다. 호스트를 커피숍 와이파이에 연결하면 인터넷에 접속할 수 있고, 메시지와 메일이 핑을 받기 시작하며, 웹 페이지와 소셜 미디어를 탐색할 수 있습니다. 커피숍 와이파이에 연결했을 때 컴퓨터는 전용 DHCP 서버 또는 DHCP를 처리하는 라우터에서 DHCP 주소를 선택했을 것입니다.
![](/2022/Days/Images/Day23_Networking8.png)
### 서브넷
서브넷은 IP 네트워크의 논리적 세분화입니다.
서브넷은 대규모 네트워크를 더 효율적으로 실행할 수 있는 더 작고 관리하기 쉬운 네트워크로 나눕니다.
각 서브넷은 더 큰 네트워크의 논리적 세분화입니다. 충분한 서브넷을 가진 연결된 장치는 공통 IP 주소 식별자를 공유하여 서로 통신할 수 있습니다.
라우터는 서브넷 간의 통신을 관리합니다.
서브넷의 크기는 연결 요구 사항과 사용되는 네트워크 기술에 따라 달라집니다.
조직은 사용 가능한 주소 공간의 한도 내에서 서브넷의 수와 크기를 결정할 책임이 있습니다.
사용 가능한 주소 공간의 한도 내에서 서브넷의 수와 크기를 결정할 책임이 있으며, 세부 사항은 해당 조직에 로컬로 유지됩니다. 서브넷은 지점 간 링크 또는 몇 개의 디바이스를 지원하는 서브네트워크와 같이 더 작은 서브넷으로 세분화할 수도 있습니다.
무엇보다도 대규모 네트워크를 서브넷으로 세분화하면
네트워크를 서브넷으로 분할하면 IP 주소
재할당을 가능하게 하고 네트워크 혼잡, 간소화, 네트워크 통신 및 효율성을 완화합니다.
서브넷은 네트워크 보안도 향상시킬 수 있습니다.
네트워크의 한 섹션이 손상되면 해당 섹션을 격리하여 악의적인 공격자가 더 큰 네트워크에서 이동하기 어렵게 만들 수 있습니다.
![](/2022/Days/Images/Day23_Networking9.png)
## 자료
- [Networking Fundamentals](https://www.youtube.com/playlist?list=PLIFyRwBY_4bRLmKfP1KnZA6rZbRHtxmXi)
- [Subnetting Mastery](https://www.youtube.com/playlist?list=PLIFyRwBY_4bQUE4IB5c4VPRyDoLgOdExE)
- [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
[Day 24](day24.md)에서 봐요!

147
2022/ko/Days/day24.md Normal file
View File

@ -0,0 +1,147 @@
---
title: '#90DaysOfDevOps - Network Automation - Day 24'
published: false
description: 90DaysOfDevOps - Network Automation
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048805
---
## 네트워크 자동화
### 네트워크 자동화의 기본 사항
네트워크 자동화의 주요 동인
- 민첩성 달성
- 비용 절감
- 오류 제거
- 규정 준수 보장
- 중앙 집중식 관리
자동화 도입 프로세스는 각 비즈니스에 따라 다릅니다. 자동화를 배포하는 데 있어 모든 것에 적합한 방법은 없으며, 조직에 가장 적합한 접근 방식을 파악하고 수용하는 능력은 보다 민첩한 환경을 유지하거나 만드는 데 매우 중요하며, 항상 비즈니스 가치와 최종 사용자 경험에 초점을 맞춰야 합니다. (처음에 DevOps 전체와 문화 변화 및 이로 인한 자동화된 프로세스와 관련하여 비슷한 내용을 말씀드렸습니다.)
이를 세분화하려면 자동화하려는 작업이나 프로세스가 최종 사용자 경험 또는 비즈니스 가치를 어떻게 달성하고 개선할 수 있는지 파악하고 단계별 체계적인 접근 방식을 따라야 합니다.
"어디로 가는지 모르면 어떤 길이라도 그곳에 도달할 수 있습니다."
달성하고자 하는 프레임워크 또는 설계 구조를 통해 최종 목표가 무엇인지 파악한 다음, 비즈니스 결과를 기반으로 다양한 단계에서 자동화 성공 여부를 측정하면서 목표 달성을 위해 단계적으로 작업하세요.
기존 애플리케이션을 중심으로 모델링된 개념 구축 자동화는 애플리케이션, 서비스, 인프라에 적용해야 하기 때문에 거창하게 개념을 설계할 필요가 없으므로 기존 인프라, 즉 기존 애플리케이션을 중심으로 모델링하여 개념을 구축하기 시작하세요.
### 네트워킹 자동화에 대한 접근 방식
작업을 식별하고 네트워크 변경 요청에 대한 검색을 수행하여 솔루션을 자동화할 가장 일반적인 이슈와 문제를 파악해야 합니다.
- 현재 수동으로 처리하고 있는 모든 변경 요청과 workflow의 목록을 작성합니다.
- 가장 일반적이고 시간이 오래 걸리며 오류가 발생하기 쉬운 활동을 파악하세요.
- 비즈니스 중심 접근 방식을 취하여 요청의 우선순위를 정하세요.
- 이는 자동화 프로세스를 구축하기 위한 프레임워크이며, 자동화해야 하는 작업과 자동화하지 않아야 하는 작업을 구분합니다.
그런 다음 작업을 나누고 서로 다른 네트워크 기능이 어떻게 작동하고 상호 작용하는지 분석해야 합니다.
- 인프라/네트워크 팀은 애플리케이션을 배포하기 위해 여러 계층에서 변경 티켓을 받습니다.
- 네트워크 서비스를 기반으로 여러 영역으로 나누고 서로 어떻게 상호 작용하는지 이해합니다.
- 애플리케이션 최적화
- ADC(애플리케이션 전송 컨트롤러)
- 방화벽
- DDI(DNS, DHCP, IPAM 등)
- 라우팅
- 기타
- 다양한 종속성을 파악하여 비즈니스 및 문화적 차이를 해결하고 팀 간 협업을 유도하세요.
재사용 가능한 정책, 재사용 가능한 서비스 작업, 프로세스 및 입출력을 정의하고 단순화하세요.
- 다양한 서비스, 프로세스 및 입출력을 위한 오퍼링을 정의하세요.
- 배포 프로세스를 간소화하면 신규 워크로드와 기존 워크로드 모두의 시장 출시 시간을 단축할 수 있습니다.
- 표준 프로세스가 마련되면, 멀티스레드 접근 방식과 제공을 위해 개별 요청에 따라 프로세스를 순서화 및 조정할 수 있습니다.
정책을 비즈니스별 활동과 결합하세요. 이 정책을 구현하면 비즈니스에 어떤 도움이 되나요? 시간이 절약되나요? 비용이 절감되나요? 더 나은 비즈니스 결과를 제공하나요?
- 서비스 작업이 상호 운용 가능한지 확인하세요.
- 증분 서비스 작업을 연결하여 비즈니스 서비스를 만들 수 있도록 정렬하세요.
- 필요에 따라 서비스 작업을 연결하고 다시 연결할 수 있는 유연성을 제공하세요.
- 셀프 서비스 기능을 배포하고 운영 효율성을 개선할 수 있는 기반을 마련하세요.
- 감독 및 규정 준수에 지속적으로 기여할 수 있도록 다양한 기술 스킬셋을 허용합니다.
가용성과 서비스를 유지하면서 정책과 프로세스를 **반복**하여 추가하고 개선하세요.
- 기존 작업을 자동화하여 작게 시작하세요.
- 자동화 프로세스에 익숙해져서 자동화를 통해 이점을 얻을 수 있는 다른 영역을 식별할 수 있습니다.
- 자동화 이니셔티브를 반복하여 필요한 가용성을 유지하면서 민첩성을 점진적으로 추가합니다.
- 점진적인 접근 방식을 취하면 성공의 길을 열 수 있습니다!
네트워크 서비스를 오케스트레이션하세요!
- 애플리케이션을 신속하게 제공하려면 배포 프로세스의 자동화가 필요합니다.
- 민첩한 서비스 환경을 구축하려면 기술 전반에 걸쳐 관리해야 할 다양한 요소가 필요합니다.
- 자동화와 배포 순서를 제어할 수 있는 End To End 오케스트레이션을 준비하세요.
## 네트워크 자동화 도구
여기서 좋은 소식은 대부분의 경우 네트워크 자동화에 사용하는 도구는 다른 자동화 영역에 사용하거나 지금까지 이미 다룬 내용 또는 향후 세션에서 다룰 내용과 동일하다는 것입니다.
운영 체제 - 이번 챌린지 내내 그랬듯이 저는 대부분의 학습을 Linux OS로 하는 데 집중하고 있으며, 그 이유는 Linux 섹션에서 설명했지만, 크로스 OS 플랫폼이긴 하지만 오늘 다룰 거의 모든 도구는 처음부터 모두 Linux 기반 애플리케이션 또는 도구로 시작되었습니다.
통합 개발 환경(IDE) - 다양한 언어에서 사용할 수 있는 광범위한 플러그인을 기반으로 Visual Studio Code를 IDE로 추천한다는 것 외에는 여기서 더 이상 설명할 것이 없습니다.
구성 관리 - 아직 구성 관리 섹션은 다루지 않았지만, 이 영역에서 구성 관리 및 자동화를 위해 Ansible이 가장 선호되는 것은 분명합니다. Ansible은 Python으로 작성되었지만, Python을 알 필요는 없습니다.
- 에이전트리스
- SSH만 필요
- 대규모 지원 커뮤니티
- 다양한 네트워크 모듈
- 푸시 전용 모델
- YAML로 구성
- 오픈 소스!
[Link to Ansible Network Modules](https://docs.ansible.com/ansible/2.9/modules/list_of_network_modules.html)
구성 관리 섹션에서 **Ansible Tower**에 대해서도 다룰 예정이며, 이를 Ansible의 GUI로 보시면 됩니다.
CI/CD - 이와 관련된 개념과 도구에 대해서는 다시 다룰 예정이지만, 네트워킹뿐만 아니라 서비스 및 플랫폼의 모든 프로비저닝에 걸쳐 있기 때문에 최소한 여기서 언급하는 것이 중요합니다.
특히 Jenkins는 네트워크 자동화를 위한 인기 있는 도구를 제공하거나 제공하는 것으로 보입니다.
- 변경사항이 있는지 git 리포지토리를 모니터링한 다음 변경을 시작합니다.
버전 관리 - 이 역시 나중에 자세히 살펴볼 내용입니다.
- Git은 로컬 디바이스에서 코드의 버전 제어를 제공합니다 - 크로스 플랫폼
- GitHub, GitLab, BitBucket 등은 리포지토리를 정의하고 코드를 업로드할 수 있는 온라인 웹사이트입니다.
언어 | 스크립팅 - 우리가 아직 다루지 않은 Python입니다. 상황에 따라 프로그래밍 언어로 Go를 사용하기로 결정했는데, Golang과 Python이 박빙의 승부를 펼쳤으며 네트워크 자동화에는 Python이 승자가 된 것 같습니다.
- 여기서 언급해야 할 것이 바로 파이썬으로 작성된 자동화 프레임워크인 Nornir입니다. 이것은 Ansible의 역할을 하는 것으로 보이지만 특히 네트워크 자동화를 중심으로 합니다. [Nornir documentation](https://nornir.readthedocs.io/en/latest/)
API 분석 - Postman은 RESTful API를 분석하기 위한 훌륭한 도구입니다. API를 빌드, 테스트 및 수정하는 데 도움이 됩니다.
- POST >>> 리소스 객체를 생성합니다.
- GET >>> 리소스를 검색합니다.
- PUT >>> 리소스를 생성하거나 교체합니다.
- PATCH >>> 리소스 오브젝트를 생성하거나 업데이트합니다.
- DELETE >>> 리소스를 삭제합니다.
[Postman tool Download](https://www.postman.com/downloads/)
### 기타 언급할 도구
[Cisco NSO (Network Services Orchestrator)](https://www.cisco.com/c/en/us/products/cloud-systems-management/network-services-orchestrator/index.html)
[NetYCE - Simplify Network Automation](https://netyce.com/)
[Network Test Automation](https://pubhub.devnetcloud.com/media/genie-feature-browser/docs/#/)
앞으로 3일 동안은 지금까지 다룬 내용 중 몇 가지를 좀 더 실습해보고 Python과 네트워크 자동화에 관한 작업을 해볼 계획입니다.
지금까지 네트워킹 주제를 모두 다루지는 못했지만, 아래에 추가하는 리소스를 통해 계속 학습하면서 따라갈 수 있을 정도로 폭넓게 다루고자 합니다.
## 자료
- [3 Necessary Skills for Network Automation](https://www.youtube.com/watch?v=KhiJ7Fu9kKA&list=WL&index=122&t=89s)
- [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
- [Practical Networking](http://www.practicalnetworking.net/)
- [Python Network Automation](https://www.youtube.com/watch?v=xKPzLplPECU&list=WL&index=126)
[Day 25](day25.md)에서 봐요!

175
2022/ko/Days/day25.md Normal file
View File

@ -0,0 +1,175 @@
---
title: '#90DaysOfDevOps - Python for Network Automation - Day 25'
published: false
description: 90DaysOfDevOps - Python for Network Automation
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049038
---
## 네트워크 자동화를 위한 Python
Python은 자동화된 네트워크 운영에 사용되는 표준 언어입니다.
네트워크 자동화뿐만 아니라 리소스를 찾을 때 어디에나 있는 것 같고, 앞서 언급했듯이 파이썬이 아니라면 일반적으로 파이썬으로도 작성된 Ansible입니다.
이미 언급한 것 같지만 '프로그래밍 언어 배우기' 섹션에서 제가 파이썬 대신 Go를 선택한 이유는 회사에서 Go로 개발 중이어서 배울 수 있는 좋은 이유였지만, 그렇지 않았다면 파이썬을 배우는 데 시간이 더 걸렸을 것입니다.
- 가독성 및 사용 편의성 - 파이썬은 그냥 말이 되는 것 같습니다. 코드에서 블록을 시작하고 끝내기 위해 `{}`에 대한 요구 사항이 없는 것 같습니다. 여기에 VS Code와 같은 강력한 IDE를 결합하면 파이썬 코드를 실행할 때 매우 쉽게 시작할 수 있습니다.
여기서 언급할 만한 또 다른 IDE는 Pycharm일 수 있습니다.
- 라이브러리 - 파이썬의 확장성은 네트워크 자동화뿐만 아니라 실제로 모든 종류의 장치와 구성을 위한 라이브러리가 많이 있다는 점을 앞서 언급했습니다. 여기에서 방대한 양을 확인할 수 있습니다. [PyPi](https://pypi.python.org/pypi)
라이브러리를 워크스테이션에 다운로드하려면 `pip`라는 도구를 사용하여 PyPI에 연결하고 로컬로 다운로드하면 됩니다. Cisco, 주니퍼, 아리스타와 같은 네트워크 벤더는 자사 디바이스에 쉽게 액세스할 수 있도록 라이브러리를 개발했습니다.
- 강력하고 효율적 - Go 파트에서 "Hello World" 시나리오를 진행하면서 6줄 정도의 코드를 작성했던 것을 기억하시나요? Python에서는
```python
print('hello world')
```
위의 모든 사항을 종합하면 자동화 작업 시 파이썬이 언급되는 이유를 쉽게 알 수 있을 것입니다.
몇 년 전에도 네트워크 장치와 상호 작용하여 구성 백업을 자동화하거나 장치에 대한 로그 및 기타 인사이트를 수집하는 스크립트가 있었을 가능성이 있다는 점에 유의하는 것이 중요하다고 생각합니다. 여기서 말하는 자동화는 조금 다른데, 이는 전반적인 네트워킹 환경이 이러한 사고방식에 더 잘 맞도록 변화하여 더 많은 자동화를 가능하게 했기 때문입니다.
- 소프트웨어 정의 네트워크 - SDN 컨트롤러는 네트워크의 모든 디바이스에 컨트롤 플레인 구성을 제공하는 책임을 지므로 네트워크 변경에 대한 단일 접점만 있으면 더 이상 모든 디바이스에 텔넷 또는 SSH로 접속할 필요가 없으며, 사람이 이 작업을 수행해야 하므로 실패 또는 구성 오류의 가능성이 반복적으로 발생할 수 있습니다.
- 높은 수준의 오케스트레이션 - 이러한 SDN 컨트롤러에서 한 단계 더 올라가면 서비스 수준을 오케스트레이션 할 수 있으며, 이 오케스트레이션 계층을 원하는 플랫폼(VMware, Kubernetes, 퍼블릭 클라우드 등)에 통합할 수 있습니다.
- 정책 기반 관리 - 무엇을 원하시나요? 원하는 상태는 무엇인가요? 이를 설명하면 시스템에서 원하는 상태가 되기 위한 모든 세부 사항을 파악합니다.
## 실습 환경 설정하기
모든 사람이 실제 라우터, 스위치 및 기타 네트워킹 장치에 액세스할 수 있는 것은 아닙니다.
저는 앞서 언급한 몇 가지 도구를 살펴보면서 네트워크 구성을 자동화하는 방법을 직접 실습하고 배울 수 있도록 하고 싶었습니다.
옵션에 관해서는 몇 가지를 선택할 수 있습니다.
- [GNS3 VM](https://www.gns3.com/software/download-vm)
- [Eve-ng](https://www.eve-ng.net/)
- [Unimus](https://unimus.net/) 실험실 환경은 아니지만 흥미로운 개념입니다.
앞서 언급했듯이 [Eve-ng](https://www.eve-ng.net/)를 사용하여 랩을 구축할 예정입니다. 가상 환경은 다양한 시나리오를 테스트할 수 있는 샌드박스 환경을 가질 수 있다는 것을 의미하며, 다양한 디바이스와 Topology로 실행 수 있다는 점도 흥미로울 수 있습니다.
저희는 커뮤니티 에디션을 통해 EVE-NG의 모든 것을 보여드리려고 합니다.
### 시작하기
[커뮤니티 에디션](https://www.eve-ng.net/index.php/download/)은 ISO 및 OVF 형식으로 제공됩니다.
저희는 OVF 다운로드를 사용할 예정이지만, ISO를 사용하면 하이퍼바이저 없이 베어메탈 서버에서 빌드할 수 있습니다.
![](/2022/Days/Images/Day25_Networking1.png)
여기서는 vExpert를 통해 라이선스가 있는 VMware Workstation을 사용하지만, [documentation](https://www.eve-ng.net/index.php/documentation/installation/system-requirement/)에 언급된 다른 옵션이나 VMware Player도 동일하게 사용할 수 있습니다. 안타깝게도 이전에 사용하던 가상 박스는 사용할 수 없습니다!
가상 박스가 지원되기는 하지만 GNS3에서 문제가 발생했던 부분이기도 합니다.
[Download VMware Workstation Player - FREE](https://www.vmware.com/uk/products/workstation-player.html)
[VMware Workstation PRO](https://www.vmware.com/uk/products/workstation-pro.html) 역시 무료 평가판 기간이 있다고 합니다!
### VM웨어 워크스테이션 프로에 설치하기
이제 하이퍼바이저 소프트웨어 다운로드 및 설치가 완료되었고, EVE-NG OVF가 다운로드되었습니다. VMware Player를 사용 중이시라면 이 과정이 동일한지 알려주시기 바랍니다.
이제 구성할 준비가 되었습니다.
VMware 워크스테이션을 열고 `file``open`를 선택합니다.
![](/2022/Days/Images/Day25_Networking2.png)
EVE-NG OVF 이미지를 다운로드하면 압축 파일 안에 들어 있습니다. 해당 폴더에 내용을 압축을 풀면 다음과 같은 모양이 됩니다.
![](/2022/Days/Images/Day25_Networking3.png)
EVE-NG OVF 이미지를 다운로드한 위치로 이동하여 가져오기를 시작합니다.
알아볼 수 있는 이름을 지정하고 시스템 어딘가에 가상 머신을 저장합니다.
![](/2022/Days/Images/Day25_Networking4.png)
가져오기가 완료되면 프로세서 수를 4개로 늘리고 할당된 메모리를 8GB로 늘립니다. (최신 버전으로 가져온 후 그렇지 않은 경우 VM 설정을 편집해야 합니다.)
또한 Intel VT-x/EPT 또는 AMD-V/RVI 가상화 확인란이 활성화되어 있는지 확인합니다. 이 옵션은 VMware 워크스테이션이 가상화 플래그를 게스트 OS에 전달하도록 지시합니다(중첩 가상화). CPU가 이를 허용함에도 불구하고 가상 박스가 있는 GNS3에서 이 문제가 발생했습니다.
![](/2022/Days/Images/Day25_Networking5.png)
### 전원 켜기 및 액세스
사이드노트 & Rabbit hole: 가상박스에서는 작동하지 않는다고 말씀드린 것을 기억하세요! 네, VM웨어 워크스테이션과 EVE-NG에서도 같은 문제가 발생했지만, 가상화 플랫폼의 잘못은 아니었습니다!
Windows 머신에서 WSL2를 실행 중이며 이로 인해 환경 내부에 중첩된 모든 것을 실행할 수 있는 기능이 제거된 것 같습니다. WSL2를 사용할 때 CPU의 인텔 VT-d 가상화 측면이 제거되는 것처럼 보이는데 왜 우분투 VM이 실행되는지 혼란스럽습니다.
이 문제를 해결하려면 Windows 시스템에서 다음 명령을 실행하고 시스템을 재부팅 할 수 있으며, 이 명령이 꺼져 있는 동안에는 WSL2를 사용할 수 없다는 점에 유의하세요.
`bcdedit /set hypervisorlaunchtype off`
다시 돌아가서 WSL2를 사용하려면 이 명령을 실행하고 재부팅 해야 합니다.
`bcdedit /set hypervisorlaunchtype auto`
이 두 명령은 모두 관리자 권한으로 실행해야 합니다!
다시 돌아와서, 이제 VMware Workstation에 전원이 켜진 머신이 있어야 하며 다음과 유사한 프롬프트가 표시되어야 합니다.
![](/2022/Days/Images/Day25_Networking6.png)
위의 프롬프트에서 다음을 사용할 수 있습니다:
username = root
password = eve
그러면 루트 password를 다시 입력하라는 메시지가 표시되며, 이 password는 나중에 호스트에 SSH할 때 사용됩니다.
그런 다음 호스트 이름을 변경할 수 있습니다.
![](/2022/Days/Images/Day25_Networking7.png)
다음으로 DNS 도메인 이름을 정의합니다. 저는 아래 이름을 사용했지만, 나중에 변경해야 할지는 아직 모르겠습니다.
![](/2022/Days/Images/Day25_Networking8.png)
그런 다음 네트워킹을 구성하고, 재부팅 후에도 주어진 IP 주소가 영구적으로 유지되도록 정적을 선택합니다.
![](/2022/Days/Images/Day25_Networking9.png)
마지막 단계로 워크스테이션에서 연결할 수 있는 네트워크의 고정 IP 주소를 제공합니다.
![](/2022/Days/Images/Day25_Networking10.png)
여기에는 네트워크, 기본 게이트웨이 및 DNS에 대한 서브넷 마스크를 제공해야 하는 몇 가지 추가 단계가 있습니다.
완료되면 재부팅되고 백업이 완료되면 고정 IP 주소를 가져와 브라우저에 입력할 수 있습니다.
![](/2022/Days/Images/Day25_Networking11.png)
GUI의 기본 username은 `admin`이고 password는 `eve`이며, SSH의 기본 username은 `root`이고 password는 `eve`이지만 설정 중에 변경한 경우 변경되었을 수 있습니다.
![](/2022/Days/Images/Day25_Networking12.png)
다른 콘솔을 탐색할 때 브라우저에 새 탭이 열리므로 콘솔과 네이티브에 대해 HTML5를 선택했습니다.
다음 단계는 다음과 같습니다:
- EVE-NG 클라이언트 팩 설치
- 일부 네트워크 이미지를 EVE-NG에 로드합니다.
- 네트워크 Topology 빌드
- 노드 추가하기
- 노드 연결하기
- 파이썬 스크립트 빌드 시작
- telnetlib, Netmiko, Paramiko, Pexpect 살펴보기
## 자료
- [Free Course: Introduction to EVE-NG](https://www.youtube.com/watch?v=g6B0f_E0NMg)
- [EVE-NG - Creating your first lab](https://www.youtube.com/watch?v=9dPWARirtK8)
- [3 Necessary Skills for Network Automation](https://www.youtube.com/watch?v=KhiJ7Fu9kKA&list=WL&index=122&t=89s)
- [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
- [Practical Networking](http://www.practicalnetworking.net/)
- [Python Network Automation](https://www.youtube.com/watch?v=xKPzLplPECU&list=WL&index=126)
[Day 26](day26.md)에서 봐요!

121
2022/ko/Days/day26.md Normal file
View File

@ -0,0 +1,121 @@
---
title: '#90DaysOfDevOps - Building our Lab - Day 26'
published: false
description: 90DaysOfDevOps - Building our Lab
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048762
---
## 실험실 구축
EVE-NG를 사용하여 에뮬레이트된 네트워크를 계속 설정한 다음 몇 가지 디바이스를 배포하고 이러한 디바이스의 구성을 자동화할 수 있는 방법에 대해 생각해 보겠습니다. [Day 25](day25.md)에서는 VMware Workstation을 사용하여 머신에 EVE-NG를 설치하는 방법을 다루었습니다.
### EVE-NG 클라이언트 설치하기
장치에 SSH를 할 때 사용할 애플리케이션을 선택할 수 있는 클라이언트 팩도 있습니다. 또한 링크 간 패킷 캡처를 위해 Wireshark를 설정합니다. 사용 중인 OS(윈도우, 맥OS, 리눅스)에 맞는 클라이언트 팩을 다운로드할 수 있습니다.
[EVE-NG Client Download](https://www.eve-ng.net/index.php/download/)
![](/2022/Days/Images/Day26_Networking1.png)
빠른 팁: Linux를 클라이언트로 사용하는 경우 이 [client pack](https://github.com/SmartFinn/eve-ng-integration)이 있습니다.
설치는 간단하며, 기본값을 그대로 두는 것이 좋습니다.
### 네트워크 Images 가져오기
이 단계는 어려웠습니다. 마지막에 링크할 몇 가지 동영상을 통해 라우터 및 스위치 이미지를 업로드하는 방법과 위치를 알려주면서 몇 가지 리소스와 다운로드 링크를 제공합니다.
저는 모든 것을 교육 목적으로 사용한다는 점에 유의하는 것이 중요합니다. 네트워크 공급업체에서 공식 이미지를 다운로드하는 것이 좋습니다.
[Blog & Links to YouTube videos](https://loopedback.com/2019/11/15/setting-up-eve-ng-for-ccna-ccnp-ccie-level-studies-includes-multiple-vendor-node-support-an-absolutely-amazing-study-tool-to-check-out-asap/)
[How To Add Cisco VIRL vIOS image to Eve-ng](https://networkhunt.com/how-to-add-cisco-virl-vios-image-to-eve-ng/)
전반적으로 단계가 조금 복잡하고 훨씬 더 쉬울 수도 있지만 위의 블로그와 동영상은 EVE-NG 박스에 이미지를 추가하는 과정을 안내합니다.
저는 FileZilla를 사용하여 SFTP를 통해 qcow2를 VM으로 전송했습니다.
실습에는 Cisco vIOS L2(스위치)와 Cisco vIOS(라우터)가 필요합니다.
### 실습 만들기
EVE-NG 웹 인터페이스 내에서 새로운 네트워크 Topology를 생성하겠습니다. 외부 네트워크에 대한 게이트웨이 역할을 할 스위치 4개와 라우터 1개가 있습니다.
| Node | IP Address |
| ------- | ------------ |
| Router | 10.10.88.110 |
| Switch1 | 10.10.88.111 |
| Switch2 | 10.10.88.112 |
| Switch3 | 10.10.88.113 |
| Switch4 | 10.10.88.114 |
#### EVE-NG에 노드 추가하기
EVE-NG에 처음 로그인하면 아래와 같은 화면이 표시되며, 첫 번째 랩을 생성하는 것부터 시작하겠습니다.
![](/2022/Days/Images/Day26_Networking2.png)
랩 이름을 지정하고 다른 필드는 선택 사항입니다.
![](/2022/Days/Images/Day26_Networking3.png)
그러면 네트워크 생성을 시작할 수 있는 빈 캔버스가 표시됩니다. 캔버스를 마우스 오른쪽 버튼으로 클릭하고 노드 추가를 선택합니다.
여기에서 긴 노드 옵션 목록이 표시되며, 위의 과정을 따라 했다면 아래 표시된 파란색 두 개가 선택되어 있고 나머지는 회색으로 표시되어 선택할 수 없습니다.
![](/2022/Days/Images/Day26_Networking4.png)
실습에 다음을 추가하려고 합니다:
- Cisco vIOS 라우터 1대
- Cisco vIOS 스위치 4개
간단한 마법사를 실행하여 실습에 추가하면 다음과 같은 화면이 나타납니다.
![](/2022/Days/Images/Day26_Networking5.png)
#### 노드 연결하기
이제 라우터와 스위치 사이에 연결을 추가해야 합니다. 장치 위로 마우스를 가져가면 아래와 같이 연결 아이콘이 표시되고 이를 연결하려는 장치에 연결하면 아주 쉽게 연결할 수 있습니다.
![](/2022/Days/Images/Day26_Networking6.png)
환경 연결이 완료되면 마우스 오른쪽 클릭 메뉴에서 찾을 수 있는 상자나 원을 사용하여 물리적 경계나 위치를 정의하는 방법을 추가할 수도 있습니다. 실험실의 이름이나 IP 주소를 정의하고 싶을 때 유용한 텍스트를 추가할 수도 있습니다.
저는 아래와 같이 실험실을 만들었습니다.
![](/2022/Days/Images/Day26_Networking7.png)
위의 실습은 모두 전원이 꺼져 있으며, 모든 것을 선택하고 마우스 오른쪽 버튼을 클릭한 후 선택된 시작을 선택하면 실습을 시작할 수 있습니다.
![](/2022/Days/Images/Day26_Networking8.png)
실습을 시작하고 실행하면 각 장치에 콘솔을 연결할 수 있으며, 이 단계에서는 아무 구성도 하지 않은 상태로 매우 멍청한 상태임을 알 수 있습니다. 각 터미널에서 직접 복사하거나 생성하여 각 노드에 구성을 추가할 수 있습니다.
참조를 위해 리포지토리의 네트워킹 폴더에 구성을 남겨두겠습니다.
| Node | Configuration |
| ------- | -------------------------------- |
| Router | [R1](/2022/Days/Networking/R1) |
| Switch1 | [SW1](/2022/Days/Networking/SW1) |
| Switch2 | [SW2](/2022/Days/Networking/SW2) |
| Switch3 | [SW3](/2022/Days/Networking/SW3) |
| Switch4 | [SW4](/2022/Days/Networking/SW4) |
## 자료
- [Free Course: Introduction to EVE-NG](https://www.youtube.com/watch?v=g6B0f_E0NMg)
- [EVE-NG - Creating your first lab](https://www.youtube.com/watch?v=9dPWARirtK8)
- [3 Necessary Skills for Network Automation](https://www.youtube.com/watch?v=KhiJ7Fu9kKA&list=WL&index=122&t=89s)
- [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
- [Practical Networking](http://www.practicalnetworking.net/)
- [Python Network Automation](https://www.youtube.com/watch?v=xKPzLplPECU&list=WL&index=126)
저는 네트워크 엔지니어가 아니기 때문에 여기서 사용하는 대부분의 예제는 무료는 아니지만 네트워크 자동화를 이해하는 데 도움이 되는 시나리오 중 일부를 이 방대한 책에서 가져온 것입니다.
- [Hands-On Enterprise Automation with Python (Book)](https://www.packtpub.com/product/hands-on-enterprise-automation-with-python/9781788998512)
[Day 27](day27.md)에서 봐요!

139
2022/ko/Days/day27.md Normal file
View File

@ -0,0 +1,139 @@
---
title: '#90DaysOfDevOps - Getting Hands-On with Python & Network - Day 27'
published: false
description: 90DaysOfDevOps - Getting Hands-On with Python & Network
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048735
---
## 파이썬 및 네트워크 실습하기
네트워킹 기초의 마지막 섹션에서는 [Day 26](day26.md)에 만든 실습 환경으로 몇 가지 자동화 작업과 도구를 다뤄보겠습니다.
클라이언트 vs telnet에서 장치에 연결하기 위해 SSH 터널을 사용할 것입니다. 클라이언트와 기기 사이에 생성된 SSH 터널은 암호화됩니다. [Day 18](day18.md)의 Linux 섹션에서도 SSH에 대해 다루었습니다.
## 가상 에뮬레이트 환경에 액세스하기
스위치와 상호 작용하려면 EVE-NG 네트워크 내부에 워크스테이션이 필요하거나 Python이 설치된 Linux 박스를 배포하여 자동화를 수행할 수 있습니다([Resource for setting up Linux inside EVE-NG](https://www.youtube.com/watch?v=3Qstk3zngrY)) 또는 저처럼 워크스테이션에서 액세스할 수 있는 클라우드를 정의할 수 있습니다.
![](/2022/Days/Images/Day27_Networking3.png)
이를 위해 캔버스를 마우스 오른쪽 버튼으로 클릭하고 네트워크를 선택한 다음 "Management(Cloud0)"를 선택하면 홈 네트워크에 연결됩니다.
![](/2022/Days/Images/Day27_Networking4.png)
하지만 이 네트워크 내부에는 아무것도 없으므로 새 네트워크에서 각 장치로 연결을 추가해야 합니다. (제 네트워킹 지식이 더 필요한데, 다음 단계로 최상위 라우터에 이 작업을 수행한 다음, 이 하나의 케이블을 통해 나머지 네트워크에 연결할 수 있을 것 같나요?)
그런 다음 각 장치에 로그온하고 클라우드가 들어오는 위치에 적용되는 인터페이스에 대해 다음 명령을 실행했습니다.
```
enable
config t
int gi0/0
IP add DHCP
no sh
exit
exit
sh ip int br
```
마지막 단계에서는 홈 네트워크의 DHCP 주소를 제공합니다. 내 장치 네트워크 목록은 다음과 같습니다:
| Node | IP Address | Home Network IP |
| ------- | ------------ | --------------- |
| Router | 10.10.88.110 | 192.168.169.115 |
| Switch1 | 10.10.88.111 | 192.168.169.178 |
| Switch2 | 10.10.88.112 | 192.168.169.193 |
| Switch3 | 10.10.88.113 | 192.168.169.125 |
| Switch4 | 10.10.88.114 | 192.168.169.197 |
### 네트워크 장치에 SSH
위의 설정이 완료되었으므로 이제 워크스테이션을 사용하여 홈 네트워크의 장치에 연결할 수 있습니다. 저는 Putty를 사용하고 있지만 장치에 SSH를 할 수 있는 git bash와 같은 다른 터미널에도 액세스할 수 있습니다.
아래에서 라우터 장치에 대한 SSH 연결을 확인할 수 있습니다. (R1)
![](/2022/Days/Images/Day27_Networking5.png)
### 파이썬을 사용하여 장치에서 정보 수집하기
Python을 활용하는 첫 번째 예는 모든 장치에서 정보를 수집하는 것이며, 특히 각 장치에 연결하여 간단한 명령을 실행하여 인터페이스 구성 및 설정을 제공할 수 있기를 원합니다. 이 스크립트를 여기에 저장해 두었습니다. [netmiko_con_multi.py](/2022/Days/Networking/netmiko_con_multi.py)
이제 이 스크립트를 실행하면 모든 장치에서 각 포트 구성을 볼 수 있습니다.
![](/2022/Days/Images/Day27_Networking6.png)
다양한 장치를 많이 사용하는 경우 이 스크립트를 작성하면 한 곳에서 모든 구성을 중앙에서 빠르게 제어하고 이해할 수 있어 편리합니다.
### Python을 사용하여 디바이스 구성하기
위의 내용은 유용하지만 Python을 사용하여 장치를 구성하는 것은 어떻습니까? 시나리오에서 `SW1``SW2` 사이에 트렁크 포트가 있습니다. 이 작업을 여러 개의 동일한 스위치에서 자동화하고 각 스위치에 수동으로 연결하여 구성을 변경할 필요가 없다고 다시 상상해 보겠습니다.
이를 위해 [netmiko_sendchange.py](/2022/Days/Networking/netmiko_sendchange.py)를 사용할 수 있습니다. 이렇게 하면 SSH를 통해 연결되고 `SW1`에서 해당 변경을 수행하여 `SW2`로 변경됩니다.
![](/2022/Days/Images/Day27_Networking7.png)
이제 코드를 보면 `sending configuration to device`이라는 메시지가, 이것이 발생했는지 확인되지 않은 경우 스크립트에 추가 코드를 추가하여 스위치에서 해당 확인 및 유효성 검사를 수행하거나 이전에 스크립트를 수정하여 이를 표시할 수 있습니다. [netmiko_con_multi_vlan.py](/2022/Days/Networking/netmiko_con_multi_vlan.py)
![](/2022/Days/Images/Day27_Networking8.png)
### 디바이스 구성 백업하기
또 다른 사용 사례는 네트워크 구성을 캡처하여 백업하는 것이지만, 네트워크에 있는 모든 장치에 연결하고 싶지는 않으므로 [backup.py](/2022/Days/Networking/backup.py)를 사용하여 이 작업을 자동화할 수도 있습니다. 또한 백업하려는 IP 주소로 [backup.txt](/2022/Days/Networking/backup.txt)를 채워야 합니다.
스크립트를 실행하면 아래와 같은 내용이 표시됩니다.
![](/2022/Days/Images/Day27_Networking9.png)
파이썬으로 간단한 인쇄 스크립트를 작성했기 때문에 백업 파일도 함께 보여드릴 수 있습니다.
![](/2022/Days/Images/Day27_Networking10.png)
### Paramiko
SSH를 위해 널리 사용되는 Python 모듈입니다. 자세한 내용은 [공식 GitHub 링크](https://github.com/paramiko/paramiko)에서 확인할 수 있습니다.
이 모듈은 `pip install paramiko` 명령어를 사용하여 설치할 수 있습니다.
![](/2022/Days/Images/Day27_Networking1.png)
파이썬 셸에 들어가서 Paramiko 모듈을 가져와서 설치가 완료되었는지 확인할 수 있습니다.
![](/2022/Days/Images/Day27_Networking2.png)
### Netmiko
Netmiko 모듈은 네트워크 디바이스만을 대상으로 하지만, Paramiko는 SSH 연결 전반을 처리하는 더 광범위한 도구입니다.
위에서 Paramiko와 함께 사용한 Netmiko는 `pip install netmiko`를 사용하여 설치할 수 있습니다.
Netmiko는 다양한 네트워크 벤더와 디바이스를 지원하며, 지원 디바이스 목록은 [GitHub Page](https://github.com/ktbyers/netmiko#supports)에서 확인할 수 있습니다.
### 기타 모듈
우리가 살펴볼 기회가 없었지만, 네트워크 자동화와 관련하여 훨씬 더 많은 기능을 제공하는 몇 가지 다른 모듈도 언급할 가치가 있습니다.
`netaddr`은 IP 주소 작업 및 조작에 사용되며, 설치는 `pip install netaddr`로 간단합니다.
스위치 구성을 엑셀 스프레드시트에 많이 저장하고 싶을 때, `xlrd`를 사용하면 스크립트가 엑셀 통합 문서를 읽고 행과 열을 행렬로 변환할 수 있습니다. `pip install xlrd`를 실행하면 모듈을 설치할 수 있습니다.
제가 미처 살펴보지 못한 네트워크 자동화를 사용할 수 있는 더 많은 사용 사례는 [여기](https://github.com/ktbyers/pynet/tree/master/presentations/dfwcug/examples)에서 확인할 수 있습니다.
네트워킹은 제가 한동안 다루지 않았던 분야이고 다뤄야 할 내용이 훨씬 더 많지만, 제가 작성한 노트와 이 글에서 공유한 리소스가 누군가에게 도움이 되기를 바랍니다.
## 자료
- [Free Course: Introduction to EVE-NG](https://www.youtube.com/watch?v=g6B0f_E0NMg)
- [EVE-NG - Creating your first lab](https://www.youtube.com/watch?v=9dPWARirtK8)
- [3 Necessary Skills for Network Automation](https://www.youtube.com/watch?v=KhiJ7Fu9kKA&list=WL&index=122&t=89s)
- [Computer Networking full course](https://www.youtube.com/watch?v=IPvYjXCsTg8)
- [Practical Networking](http://www.practicalnetworking.net/)
- [Python Network Automation](https://www.youtube.com/watch?v=xKPzLplPECU&list=WL&index=126)
저는 네트워크 엔지니어가 아니기 때문에 여기서 사용하는 대부분의 예제는 무료는 아니지만 네트워크 자동화를 이해하는 데 도움이 되는 시나리오 중 일부를 이 방대한 책에서 가져온 것입니다.
- [Hands-On Enterprise Automation with Python (Book)](https://www.packtpub.com/product/hands-on-enterprise-automation-with-python/9781788998512)
클라우드 컴퓨팅에 대해 알아보고 주제에 대한 이해와 기초 지식을 쌓을 수 있는 [Day 28](day28.md)에서 봐요!

105
2022/ko/Days/day28.md Normal file
View File

@ -0,0 +1,105 @@
---
title: '#90DaysOfDevOps - The Big Picture: DevOps & The Cloud - Day 28'
published: false
description: 90DaysOfDevOps - The Big Picture DevOps & The Cloud
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048737
---
## 큰 그림: 데브옵스와 클라우드
클라우드 컴퓨팅과 제공되는 서비스는 데브옵스 정신 및 프로세스와 매우 잘 어울립니다. 클라우드 컴퓨팅은 기술과 서비스를 제공하는 것으로 생각할 수 있지만, 앞서 여러 번 언급했듯이 데브옵스는 프로세스와 프로세스 개선에 관한 것입니다.
그러나 클라우드 학습 여정은 가파른 여정이며 모든 요소를 알고 이해하거나 적절한 가격대에 가장 적합한 서비스를 선택하는 것은 혼란스러운 일입니다.
![](/2022/Days/Images/Day28_Cloud1.png)
퍼블릭 클라우드에 데브옵스 마인드셋이 필요한가요? 제 대답은 '아니다'이지만, 클라우드 컴퓨팅을 제대로 활용하고 많은 사람이 겪었던 막대한 클라우드 비용을 피하려면 클라우드 컴퓨팅과 데브옵스를 함께 생각하는 것이 중요합니다.
퍼블릭 클라우드의 의미를 40,000피트 상공에서 보면, 관리형 서비스에 대한 책임을 일부 제거하여 여러분과 여러분의 팀이 애플리케이션과 최종 사용자라는 더 중요한 측면에 집중할 수 있도록 하는 것입니다. 결국 퍼블릭 클라우드는 다른 사람의 컴퓨터일 뿐입니다.
![](/2022/Days/Images/Day28_Cloud2.png)
이 첫 번째 섹션에서는 퍼블릭 클라우드가 무엇인지, 그리고 전체적으로 퍼블릭 클라우드라고 불리는 몇 가지 구성 요소에 대해 조금 더 자세히 설명하고자 합니다.
### SaaS
첫 번째로 다룰 영역은 서비스로서의 소프트웨어로, 이 서비스는 온-프레미스에서 실행하던 서비스의 거의 모든 관리 오버헤드를 제거합니다. 이메일용 Microsoft Exchange를 예로 들어 보겠습니다. 예전에는 데이터 센터나 계단 아래 찬장에 있는 물리적 상자였습니다. 이 서버에 먹이를 주고 물을 주어야 했습니다. 즉, 서버 하드웨어를 구입하고, 운영 체제를 설치하고, 필요한 애플리케이션을 설치한 다음 패치를 유지해야 하며, 문제가 발생하면 문제를 해결하고 다시 실행해야 합니다.
또한 데이터를 백업하고 있는지 확인해야 하지만, 대부분의 경우 SaaS를 사용한다고 해서 달라지지는 않습니다.
SaaS의 기능, 특히 Microsoft 365의 경우 앞서 Exchange를 언급했듯이 관리 오버헤드를 없애고 메일을 통해 Exchange 기능뿐만 아니라 다른 많은 생산성(Office 365) 및 저장소 옵션(OneDrive)을 제공하는 서비스를 제공하여 전반적으로 최종 사용자에게 훌륭한 경험을 제공합니다.
Salesforce, SAP, Oracle, Google, Apple과 같은 다른 SaaS 애플리케이션도 널리 채택되고 있습니다. 모두 더 많은 스택을 관리해야 하는 부담을 덜어줍니다.
DevOps와 SaaS 기반 애플리케이션에 대한 이야기가 있을 거라고 확신하지만, 그 내용을 파악하는 데 어려움을 겪고 있습니다. Azure DevOps에 Microsoft 365와의 훌륭한 통합 기능이 있다는 것을 알고 있으므로 살펴보고 다시 보고할 수 있습니다.
![](/2022/Days/Images/Day28_Cloud3.png)
### 퍼블릭 클라우드
다음은 퍼블릭 클라우드입니다. 대부분의 사람들은 퍼블릭 클라우드를 몇 가지 다른 방식으로 생각할 수 있으며, 일부는 Microsoft Azure, Google Cloud Platform 및 AWS와 같은 하이퍼 스케일러로만 볼 수 있습니다.
![](/2022/Days/Images/Day28_Cloud4.png)
또한 퍼블릭 클라우드를 이러한 하이퍼 스케일러뿐만 아니라 전 세계 수천 개의 MSP를 포함하는 훨씬 더 광범위한 서비스로 보는 사람도 있을 것입니다. 이 글에서는 하이퍼 스케일러와 MSP를 포함한 퍼블릭 클라우드를 고려할 예정이지만, 나중에 하이퍼 스케일러 중 하나 이상을 구체적으로 살펴봄으로써 기초적인 지식을 얻도록 하겠습니다.
![](/2022/Days/Images/Day28_Cloud5.png)
_수천 개의 더 많은 회사가 이 서비스를 이용할 수 있지만, 저는 제가 함께 일했고 알고 있는 로컬, 지역, 통신사 및 글로벌 브랜드 중에서 골랐을 뿐입니다_.
앞서 SaaS 섹션에서 클라우드가 시스템의 일부를 관리해야 하는 책임이나 부담을 덜어준다고 언급했습니다. SaaS의 경우 물리적 시스템, 네트워크, 스토리지, 운영 체제, 애플리케이션 등 많은 추상화 계층이 어느 정도 제거되었습니다. 클라우드의 경우 요구 사항에 따라 제거하거나 유지할 수 있는 추상화 수준이 다양합니다.
이미 SaaS에 대해 언급했지만, 퍼블릭 클라우드와 관련하여 최소 두 가지를 더 언급할 수 있습니다.
IaaS(Infrastructure as a Service) - 이 계층을 가상 머신으로 생각할 수 있지만, 온프레미스에서는 클라우드의 물리적 계층을 관리해야 하는 반면, 클라우드에서는 물리적 계층은 클라우드 제공업체의 책임이며 운영 체제, 데이터, 실행하려는 애플리케이션을 관리 및 운영하게 됩니다.
PaaS(Platform as a Service) - 계층의 책임이 계속 제거되며, 사용자가 데이터와 애플리케이션을 제어하지만, 기반이 되는 하드웨어나 운영 체제에 대해 걱정할 필요가 없습니다.
다른 많은 aaS 제품이 있지만, 이 두 가지가 기본입니다. 스토리지 계층을 제공하지만, 그 밑에 있는 하드웨어에 대해 걱정할 필요가 없는 StaaS(Storage as a service) 관련 제품을 볼 수 있습니다. 또는 컨테이너를 위한 CaaS에 대해 들어보셨을 수도 있고, 앞으로 7일 동안 다룰 또 다른 aaS는 시스템을 항상 가동할 필요가 없고 필요할 때만 함수를 실행하기를 원하는 경우에 사용할 수 있는 FaaS(Functions as a Service입니다.
퍼블릭 클라우드는 사용자가 원하는 제어 계층의 추상화 계층을 제공하고 비용을 지불할 수 있는 여러 가지 방법이 있습니다.
![](/2022/Days/Images/Day28_Cloud6.png)
### 프라이빗 클라우드
자체 데이터 센터를 보유하는 것은 과거의 일이 아닙니다. 퍼블릭 클라우드를 사용하는 것만으로는 기술뿐만 아니라 운영 비용 모델을 관리하기 어렵다는 것을 알게 된 많은 기업들 사이에서 다시 부상하고 있다고 생각합니다.
여기서 주목해야 할 중요한 점은 퍼블릭 클라우드는 이제 기업의 책임이 될 가능성이 높으며, 온프레미스 환경이 될 것이라는 점입니다.
가상화 시대와 온프레미스 인프라 환경을 지배했던 VMware뿐만 아니라 이 분야에서도 흥미로운 일들이 일어나고 있습니다. 퍼블릭 클라우드의 온프레미스 버전을 제공하는 하이퍼 스케일러도 있습니다.
![](/2022/Days/Images/Day28_Cloud7.png)
### 하이브리드 클라우드
앞서 언급한 퍼블릭 클라우드와 프라이빗 클라우드에 이어서, 퍼블릭 클라우드에서 제공되는 서비스를 활용하면서 온프레미스 환경의 기능을 활용하거나 규제에 따라 데이터를 로컬에 저장해야 하는 경우 두 환경 간에 유연성을 제공할 수 있는 하이브리드 클라우드도 있습니다.
![](/2022/Days/Images/Day28_Cloud8.png)
이 모든 것을 종합하면 워크로드를 저장하고 실행하는 위치에 대한 선택의 폭이 넓어집니다.
![](/2022/Days/Images/Day28_Cloud9.png)
구체적인 하이퍼스케일에 들어가기 전에 트위터의 힘에 우리가 어디로 가야 할지를 물어봤습니다.
![](/2022/Days/Images/Day28_Cloud10.png)
[트위터 설문조사 링크](https://twitter.com/MichaelCade1/status/1486814904510259208?s=20&t=x2n6QhyOXSUs7Pq0itdIIQ)
어느 쪽이 가장 높은 비율을 얻든 제품에 대해 더 자세히 살펴볼 것이지만, 중요한 것은 모든 서비스의 서비스가 상당히 유사하다는 점이며, 제가 하나부터 시작하라고 말하는 이유는 하나의 기초와 가상 머신 생성, 네트워킹 설정 방법 등을 알기 때문이라고 생각하기 때문입니다. 다른 서비스로 이동하여 해당 영역에서 빠르게 성장할 수 있었습니다.
어느 쪽이든, 저는 세 가지 하이퍼 스케일러를 모두 다루는 훌륭한 **무료** 리소스를 공유하려고 합니다.
또한 다른 섹션에서 그랬던 것처럼 시나리오를 작성하여 며칠 동안 진행하면서 무언가를 구축 할 수 있습니다.
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
[Day 29](day29.md)에서 봐요!

141
2022/ko/Days/day29.md Normal file
View File

@ -0,0 +1,141 @@
---
title: '#90DaysOfDevOps - Microsoft Azure Fundamentals - Day 29'
published: false
description: 90DaysOfDevOps - Microsoft Azure Fundamentals
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048705
---
## Microsoft Azure 기초
시작하기 전에 트위터 투표의 승자는 Microsoft Azure였으며, 따라서 페이지의 제목도 그렇게 정해졌습니다. 박빙의 승부가 펼쳐졌고 24시간 동안의 결과가 꽤 흥미로웠습니다.
![](/2022/Days/Images/Day29_Cloud1.png)
이 주제를 다루면서 Microsoft Azure에서 사용할 수 있는 서비스에 대해 더 잘 이해하고 업데이트할 수 있다는 측면에서 저는 오늘 하루는 Amazon AWS에 기대고 있습니다. 하지만 세 가지 주요 클라우드 제공업체 모두에 대해 준비해 둔 리소스를 남겨 두었습니다.
설문조사에는 이 세 가지 서비스만 포함되었고 특히 오라클 클라우드에 대한 의견도 몇 개 있었습니다. 실제 사용 중인 다른 클라우드 제공업체에 대한 의견을 더 듣고 싶습니다.
### 기본 사항
- 퍼블릭 클라우드 서비스 제공
- 지리적으로 분산되어 있음(전 세계 60개 이상의 지역)
- 인터넷 및/또는 개인 연결을 통해 액세스
- 멀티 테넌트 모델
- 사용량 기반 청구 - (종량제 및 사용량 증가에 따른 과금)
- 다양한 요구 사항에 맞는 다양한 서비스 유형 및 제품.
- [Microsoft Azure 글로벌 인프라](https://infrastructuremap.microsoft.com/explore)
SaaS 및 하이브리드 클라우드에 대해 많이 이야기했지만 여기서는 해당 주제를 다루지 않을 계획입니다.
시작하고 따라 하는 가장 좋은 방법은 링크를 클릭하여 [Microsoft Azure 무료 계정](https://azure.microsoft.com/en-gb/free/)을 생성하는 것입니다.
### 지역
위의 인터랙티브 지도를 링크했는데, 아래 이미지에서 전 세계 Microsoft Azure 플랫폼에서 제공되는 다양한 지역을 확인할 수 있습니다.
![](/2022/Days/Images/Day29_Cloud2.png)
[Microsoft 문서](https://docs.microsoft.com/en-us/azure/networking/microsoft-global-network)에서 가져온 이미지 - _01/05/2021_
또한 다른 지역과 연결되지 않거나 다른 지역과 대화할 수 없음을 의미하는 여러 "sovereign" 클라우드를 볼 수 있는데, 예를 들어 `AzureUSGovernment`, `AzureChinaCloud` 등과 같은 정부와 관련된 클라우드가 있습니다.
Microsoft Azure 내에서 서비스를 배포할 때 거의 모든 것에 대해 지역을 선택합니다. 하지만 모든 지역에서 모든 서비스를 이용할 수 있는 것은 아니라는 점에 유의해야 합니다. 이 글을 쓰는 시점에 [지역별 사용 가능한 제품](https://azure.microsoft.com/en-us/global-infrastructure/services/?products=all)을 보면 미국 중서부 지역에서는 Azure Databricks을 사용할 수 없다는 것을 알 수 있습니다.
또한 위에서 "거의 모든 것"이라고 언급했는데, Azure Bot Services, Bing Speech, Azure Virtual Desktop, Static Web Apps 등과 같이 지역과 연결된 특정 서비스가 있습니다.
이면에서는 region이 둘 이상의 데이터 센터로 구성될 수 있습니다. 이를 가용 영역이라고 합니다.
아래 이미지에서 볼 수 있듯이 이 이미지는 Microsoft 공식 문서에서 가져온 것으로, region이란 무엇이며 region이 가용 영역으로 어떻게 구성되는지 설명합니다. 그러나 모든 지역에 가용 영역이 여러 개 있는 것은 아닙니다.
![](/2022/Days/Images/Day29_Cloud3.png)
Microsoft 설명서는 매우 훌륭하며 [여기](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview)에서 지역 및 가용 영역에 대한 자세한 내용을 읽을 수 있습니다.
### 구독
Microsoft Azure는 모든 주요 클라우드 공급자가 이 모델을 따르는 소비 모델 클라우드라고 언급했음을 기억하세요.
엔터프라이즈인 경우 회사에서 이러한 Azure 서비스를 사용할 수 있도록 Microsoft와 엔터프라이즈 계약을 원하거나 이미 설정했을 수 있습니다.
저와 같이 교육용으로 Microsoft Azure를 사용하는 경우 몇 가지 다른 옵션이 있습니다.
일반적으로 일정 기간 동안 Azure에서 사용할 수 있는 몇 가지 무료 클라우드 크레딧을 제공하는 [Microsoft Azure 무료 계정](https://azure.microsoft.com/en-gb/free/)이 있습니다.
또한 Visual Studio 연간 구독과 함께 매달 몇 가지 무료 크레딧을 제공하는 [Visual Studio](https://azure.microsoft.com/en-us/pricing/member-offers/credit-for-visual-studio-subscribers/) 구독을 사용할 수도 있습니다(몇 년 전에는 일반적으로 MSDN으로 알려짐).
마지막으로 신용카드를 건네고 [종량제](https://azure.microsoft.com/en-us/pricing/purchase-options/pay-as-you-go/) 모델을 사용하는 방법이 있습니다.
구독은 잠재적으로 비용 중심이지만 완전히 다른 환경을 가진 서로 다른 구독 간의 경계로 볼 수 있습니다. 구독은 리소스가 생성되는 곳입니다.
### 관리 그룹
관리 그룹을 사용하면 Azure AD(Active Directory) 또는 테넌트 환경 전반에서 제어를 분리할 수 있습니다. 관리 그룹을 통해 정책, RBAC(역할 기반 액세스 제어) 및 예산을 제어할 수 있습니다.
구독은 이러한 관리 그룹에 속하므로 Azure AD 테넌트에 많은 구독을 보유할 수 있으며, 이러한 구독은 정책, RBAC 및 예산도 제어할 수 있습니다.
### 리소스 관리자 및 리소스 그룹
#### Azure 리소스 관리자
- 리소스 공급자를 기반으로 구축된 JSON 기반 API입니다.
- 리소스는 리소스 그룹에 속하며 공통 수명 주기를 공유합니다.
- 병렬 처리
- JSON 기반 배포는 선언적이고 비독립적이며 리소스 간의 종속성을 이해하여 생성 및 순서를 관리합니다.
#### 리소스 그룹
- 모든 Azure Resource Manager 리소스는 하나의 리소스 그룹에만 존재합니다!
- 리소스 그룹은 지역 외부의 리소스를 포함할 수 있는 지역에서 만들어집니다.
- 리소스 그룹 간에 리소스 이동 가능
- 리소스 그룹은 다른 리소스 그룹과 차단되지 않으며, 리소스 그룹 간에 통신할 수 있습니다.
- 리소스 그룹은 정책, RBAC 및 예산도 제어할 수 있습니다.
### 실습
이제 연결하여 **Subscription**을 사용할 수 있는지 확인해 보겠습니다. 기본 제공되는 간단한 **Management Group**을 확인한 다음, 원하는 **Region**에 새로운 전용 **Resource Group**을 만들 수 있습니다.
[Azure 포털](https://portal.azure.com/#home)에 처음 로그인하면 상단에 리소스, 서비스 및 문서를 검색할 수 있는 기능이 표시됩니다.
![](/2022/Days/Images/Day29_Cloud4.png)
먼저 구독을 살펴보겠습니다. 여기에서는 매달 무료 크레딧을 제공하는 Visual Studio Professional 구독을 사용하고 있음을 알 수 있습니다.
![](/2022/Days/Images/Day29_Cloud5.png)
더 넓은 화면으로 이동하여 구독으로 어떤 일이 일어나고 있는지 또는 무엇을 할 수 있는지 살펴보면 왼쪽에 IAM 액세스 제어를 정의할 수 있는 제어 기능과 함께 청구 정보를 볼 수 있으며 더 아래로 내려가면 더 많은 리소스를 사용할 수 있습니다.
![](/2022/Days/Images/Day29_Cloud6.png)
여러 개의 구독이 있고 이를 모두 하나의 구독으로 관리하려는 시나리오가 있을 수 있는데, 이때 관리 그룹을 사용하여 책임 그룹을 분리할 수 있습니다. 아래 제 경우에는 구독이 있는 테넌트 루트 그룹만 있는 것을 볼 수 있습니다.
또한 이전 이미지에서 상위 관리 그룹이 테넌트 루트 그룹에 사용된 아이디와 동일한 것을 볼 수 있습니다.
![](/2022/Days/Images/Day29_Cloud7.png)
다음으로 리소스 그룹이 있는데, 여기에서 리소스를 결합하여 한 곳에서 쉽게 관리할 수 있습니다. 저는 다른 여러 프로젝트를 위해 몇 개를 만들었습니다.
![](/2022/Days/Images/Day29_Cloud8.png)
앞으로 며칠 동안 할 작업을 위해 리소스 그룹을 만들고 싶습니다. 이 콘솔에서 이전 이미지의 생성 옵션을 누르면 쉽게 할 수 있습니다.
![](/2022/Days/Images/Day29_Cloud9.png)
유효성 검사 단계가 수행된 후 생성한 내용을 검토한 다음 생성할 수 있습니다. 또한 하단에 "Download a template for automation"가 표시되는데, 이를 통해 JSON 형식을 가져와서 나중에 원할 경우, 이 간단한 작업을 자동화 방식으로 수행할 수 있으며, 이에 대해서도 나중에 다룰 것입니다.
![](/2022/Days/Images/Day29_Cloud10.png)
생성 버튼을 누르면 리소스 그룹 목록에 다음 세션에서 수행할 작업을 위한 "90DaysOfDevOps" 그룹이 준비됩니다.
![](/2022/Days/Images/Day29_Cloud11.png)
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
[Day 30](day30.md)에서 봐요!

175
2022/ko/Days/day30.md Normal file
View File

@ -0,0 +1,175 @@
---
title: '#90DaysOfDevOps - Microsoft Azure Security Models - Day 30'
published: false
description: 90DaysOfDevOps - Microsoft Azure Security Models
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049039
---
## Microsoft Azure 보안 모델
Microsoft Azure 개요에 이어서 Azure 보안부터 시작하여 일상적인 업무에 어떤 도움이 될 수 있는지 살펴보겠습니다. 대부분의 경우 기본 제공 역할로도 충분하지만, 다양한 인증 및 구성 영역을 만들고 작업할 수 있다는 것을 알게 되었습니다. 다른 퍼블릭 클라우드에 비해 Microsoft Azure의 Active Directory 배경이 상당히 발전되어 있다는 것을 알았습니다.
Microsoft Azure가 다른 퍼블릭 클라우드 공급자와 다르게 작동하는 것처럼 보이는 영역 중 하나는 Azure에는 항상 Azure AD가 있다는 것입니다.
### 디렉토리 서비스
- Azure Active Directory는 Microsoft Azure 및 기타 Microsoft 클라우드 서비스에서 사용하는 보안 원칙을 호스팅합니다.
- 인증은 SAML, WS-Federation, OpenID Connect 및 OAuth2와 같은 프로토콜을 통해 수행됩니다.
- 쿼리는 Microsoft Graph API라는 REST API를 통해 수행됩니다.
- 테넌트는 tenant.onmicrosoft.com을 기본 이름으로 사용하지만 사용자 지정 도메인 이름을 사용할 수도 있습니다.
- 구독은 Azure Active Directory 테넌트와 연결됩니다.
AWS와 비교하기 위해 AWS를 생각해보면 여전히 매우 다르지만, AWS IAM(ID 및 액세스 관리)이 동등한 오퍼링이 될 것입니다.
Azure AD Connect는 AD에서 Azure AD로 계정을 복제하는 기능을 제공합니다. 여기에는 그룹과 때로는 개체가 포함될 수도 있습니다. 이는 세분화 및 필터링할 수 있습니다. 여러 포리스트 및 도메인을 지원합니다.
Microsoft Azure AD(Active Directory)에서 클라우드 계정을 만들 수 있지만 대부분의 조직은 이미 온-프레미스에 있는 자체 Active Directory에서 사용자를 계정화하고 있습니다.
Azure AD Connect를 사용하면 Windows AD 서버뿐만 아니라 다른 Azure AD, Google 및 기타 서버도 볼 수 있습니다. 또한 외부 사람 및 조직과 공동 작업할 수 있는 기능을 제공하는데, 이를 Azure B2B라고 합니다.
액티브 디렉토리 도메인 서비스와 Microsoft Azure 액티브 디렉토리 간의 인증 옵션은 암호 해시와 ID 동기화를 통해 모두 가능합니다.
![](/2022/Days/Images/Day30_Cloud1.png)
암호 해시 전달은 선택 사항이며, 암호 해시를 사용하지 않는 경우 통과 인증이 필요합니다.
아래에 링크된 비디오에서 패스스루 인증에 대해 자세히 설명합니다.
[Azure Active Directory 패스스루 인증을 사용한 사용자 로그인](https://docs.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-pta)
![](/2022/Days/Images/Day30_Cloud2.png)
### 페더레이션
Microsoft 365, Microsoft Dynamics 및 온-프레미스 Active Directory를 사용하는 경우 페더레이션을 위해 Azure AD를 이해하고 통합하는 것은 매우 쉽습니다. 하지만 Microsoft 에코시스템 외부의 다른 서비스를 사용하고 있을 수도 있습니다.
Azure AD는 이러한 다른 타사 앱 및 기타 디렉토리 서비스에 대한 페더레이션 브로커 역할을 할 수 있습니다.
이는 Azure 포털에서 다양한 옵션이 있는 엔터프라이즈 애플리케이션으로 표시됩니다.
![](/2022/Days/Images/Day30_Cloud3.png)
엔터프라이즈 애플리케이션 페이지에서 아래로 스크롤 하면 추천 애플리케이션의 긴 목록을 볼 수 있습니다.
![](/2022/Days/Images/Day30_Cloud4.png)
이 옵션을 사용하면 개발 중인 애플리케이션이나 갤러리 이외의 애플리케이션을 "직접 가져와서" 통합할 수도 있습니다.
이전에 이 기능을 살펴본 적은 없지만 다른 클라우드 제공업체 및 기능과 비교할 때 상당한 기능 집합이라는 것을 알 수 있습니다.
### 역할 기반 액세스 제어
여기서 다룰 범위는 이미 [Day 29](day29.md)에서 다뤘으며, 이러한 영역 중 하나에 따라 역할 기반 액세스 제어를 설정할 수 있습니다.
- 구독
- 관리 그룹
- 리소스 그룹
- 리소스
역할은 세 가지로 나눌 수 있으며, Microsoft Azure에는 많은 기본 제공 역할이 있습니다. 이 세 가지 역할은 다음과 같습니다:
- 소유자
- 기여자
- 리더
소유자와 기여자는 범위가 매우 유사하지만, 소유자가 권한을 변경할 수 있습니다.
다른 역할은 특정 유형의 Azure 리소스 및 사용자 지정 역할에 따라 다릅니다.
그룹과 사용자에 대한 사용 권한 할당에 중점을 두어야 합니다.
사용 권한은 상속됩니다.
다시 돌아가서 우리가 만든 "90DaysOfDevOps" 리소스 그룹을 살펴보고 그 안의 액세스 제어(IAM)를 확인하면 기여자 목록과 고객 사용자 액세스 관리자 목록이 있고 소유자 목록이 있는 것을 볼 수 있습니다(하지만 이 목록은 표시할 수 없습니다).
![](/2022/Days/Images/Day30_Cloud5.png)
또한 여기에서 할당된 역할이 빌트인 역할인지 여부와 해당 역할이 어떤 카테고리에 속하는지 확인할 수 있습니다.
![](/2022/Days/Images/Day30_Cloud6.png)
이 리소스 그룹에 대해 계정을 확인하고 해당 액세스 권한을 갖고자 하는 계정에 올바른 권한이 있는지 확인하거나 사용자가 너무 많은 액세스 권한을 갖고 있는지 확인하려는 경우 액세스 확인 탭을 사용할 수도 있습니다.
![](/2022/Days/Images/Day30_Cloud7.png)
### 클라우드용 Microsoft Defender
- 클라우드용 Microsoft Defender(이전의 Azure Security Center)는 전체 Azure 환경의 보안에 대한 인사이트를 제공합니다.
- 단일 대시보드를 통해 모든 Azure 및 비 Azure 리소스의 전반적인 보안 상태를 파악할 수 있으며(Azure Arc를 통해) 보안 강화 지침을 제공합니다.
- 프리티어에는 지속적인 평가 및 보안 권장 사항이 포함됩니다.
- 보호되는 리소스 유형(예: Servers, AppService, SQL, Storage, Containers, KeyVault)에 대한 유료 플랜.
다른 구독으로 전환하여 Azure 보안 센터를 확인했으며, 여기에서 몇 가지 리소스를 기반으로 한 곳에서 몇 가지 권장 사항을 확인할 수 있습니다.
![](/2022/Days/Images/Day30_Cloud8.png)
### Azure 정책
- Azure Policy는 조직 표준을 적용하고 대규모로 규정 준수를 평가하는 데 도움이 되는 Azure 기본 서비스입니다.
- 클라우드용 Microsoft Defender에 통합됩니다. Azure Policy는 규정을 준수하지 않는 리소스를 감사하고 수정 사항을 적용합니다.
- 리소스 일관성, 규정 준수, 보안, 비용 및 관리 표준을 관리하는 데 일반적으로 사용됩니다.
- JSON 형식을 사용하여 평가 로직을 저장하고 리소스의 규정 준수 여부와 규정 미준수 시 취할 조치(예: 감사, AuditIfNotExists, 거부, 수정, DeployIfNotExists)를 결정합니다.
- 무료로 사용할 수 있습니다. 단, Azure 정책 게스트 구성 사용량에 대해 서버/월당 청구되는 Azure Arc 연결 리소스는 예외입니다.
### 실습
www.90DaysOfDevOps.com 도메인을 구입했는데 이 도메인을 내 Azure Active Directory 포털에 추가하고 싶습니다. [Azure Active Directory 포털을 사용하여 사용자 지정 도메인 이름 추가](https://docs.microsoft.com/en-us/azure/active-directory/fundamentals/add-custom-domain)
![](/2022/Days/Images/Day30_Cloud9.png)
이제 새 Active Directory 도메인에 새 사용자를 만들 수 있습니다.
![](/2022/Days/Images/Day30_Cloud10.png)
이제 모든 새로운 90DaysOfDevOps 사용자를 하나의 그룹으로 묶는 그룹을 만들고 싶습니다. 아래와 같이 그룹을 만들 수 있으며, Azure AD가 사용자 계정을 쿼리하여 동적으로 추가하는 "Dynamic User"와 수동으로 사용자를 그룹에 추가하는 "Assigned"를 사용하고 있음을 알 수 있습니다.
![](/2022/Days/Images/Day30_Cloud11.png)
쿼리를 작성할 때 많은 옵션이 있지만, 저는 단순히 대표 이름을 찾아 이름에 @90DaysOfDevOps.com이 포함되어 있는지 확인하려고 합니다.
![](/2022/Days/Images/Day30_Cloud12.png)
이제 michael.cade@90DaysOfDevOps.com 에 대한 사용자 계정을 이미 만들었으므로 규칙이 작동하는지 확인할 수 있습니다. 비교를 위해 다른 도메인에 연결한 다른 계정도 여기에 추가했는데, 이 규칙으로 인해 사용자가 이 그룹에 속하지 않는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day30_Cloud13.png)
그 후 user1@90DaysOfDevOps.com 을 새로 추가했고 그룹을 확인하면 회원을 볼 수 있습니다.
![](/2022/Days/Images/Day30_Cloud14.png)
이 요구 사항이 많아진다면, 콘솔에서 이 모든 작업을 수행하지 않고 대량 옵션을 사용하여 사용자를 만들고, 초대하고, 삭제하거나 PowerShell을 사용하여 자동화된 확장 방식을 사용하고 싶을 것입니다.
이제 리소스 그룹으로 이동하여 90DaysOfDevOps 리소스 그룹에서 소유자가 방금 만든 그룹이 되도록 지정할 수 있습니다.
![](/2022/Days/Images/Day30_Cloud15.png)
마찬가지로 여기로 이동하여 리소스 그룹에 대한 할당 액세스를 거부할 수도 있습니다.
이제 새 사용자 계정으로 Azure Portal에 로그인하면 액세스 권한이 없기 때문에 이전 그림에서 볼 수 있는 다른 리소스 그룹에는 액세스 권한이 없고 90DaysOfDevOps 리소스 그룹에만 액세스 권한이 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day30_Cloud16.png)
모든 사용자가 포털을 알고 있을 필요는 없지만, 액세스 권한을 확인하기 위해 [앱 포털](https://myapps.microsoft.com/)을 사용하여 테스트할 수 있는 싱글 사인온 포털입니다.
![](/2022/Days/Images/Day30_Cloud17.png)
이 포털을 브랜딩으로 사용자 지정할 수 있으며, 이 부분은 나중에 다시 다룰 수 있습니다.
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
[Day 31](day31.md)에서 봐요!

114
2022/ko/Days/day31.md Normal file
View File

@ -0,0 +1,114 @@
---
title: '#90DaysOfDevOps - Microsoft Azure Compute Models - Day 31'
published: false
description: 90DaysOfDevOps - Microsoft Azure Compute Models
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049040
---
## Microsoft Azure 컴퓨팅 모델
어제 Microsoft Azure의 보안 모델에 대한 기본 사항을 다룬 데 이어 오늘은 Azure에서 사용할 수 있는 다양한 컴퓨팅 서비스에 대해 살펴보겠습니다.
### 서비스 가용성 옵션
이 섹션은 데이터 관리에서 제 역할을 고려할 때 제 마음에 와닿는 부분입니다. 온-프레미스와 마찬가지로 서비스의 가용성을 보장하는 것이 중요합니다.
- 고가용성(지역 내 보호)
- 재해 복구(지역 간 보호)
- 백업(특정 시점으로부터의 복구)
Microsoft는 지정학적 경계 내에 여러 지역을 배포합니다.
서비스 가용성을 위한 Azure의 두 가지 개념엔 Sets와 영역이 있습니다.
가용성 Sets - 데이터 센터 내에서 복원력 제공
가용성 영역 - 지역 내 데이터 센터 간에 복원력을 제공합니다.
### 가상 머신
퍼블릭 클라우드의 시작점일 가능성이 높습니다.
- 다양한 기능을 갖춘 다양한 계열 및 [크기](https://docs.microsoft.com/en-us/azure/virtual-machines/sizes)의 가상 머신을 제공합니다(때로는 압도적일 수 있음).
- 고성능, 짧은 지연 시간, 높은 메모리 옵션의 VM에 이르기까지 다양한 옵션과 초점이 있는 VM을 제공합니다.
- 또한 B-Series에서 찾을 수 있는 burstable VM 유형도 있습니다. 이는 대부분의 경우 CPU 요구 사항이 낮지만, 한 달에 한 번 정도 성능 급증이 필요한 워크로드에 적합합니다.
- 가상 머신은 모든 네트워크에 연결을 제공할 수 있는 가상 네트워크에 배치됩니다.
- Windows 및 Linux 게스트 OS 지원.
- 특정 Linux 배포판의 경우 [Azure 튜닝된 커널](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/endorsed-distros#azure-tuned-kernels)도 있습니다.
### 템플릿
앞서 마이크로소프트 애저의 이면이나 밑에 있는 모든 것이 JSON이라고 언급했습니다.
리소스를 생성하는 데 사용할 수 있는 여러 가지 관리 포털과 콘솔이 있지만, 가장 선호하는 경로는 JSON 템플릿을 통한 것입니다.
증분 또는 전체 모드, 즉 반복 가능한 원하는 상태의 무동력 배포.
배포된 리소스 정의를 내보낼 수 있는 다양한 템플릿이 있습니다. 저는 이 템플릿 기능을 AWS CloudFormation과 같은 것에 적용하거나 멀티클라우드 옵션을 위한 Terraform이 될 수 있다고 생각하고 있습니다. Terraform에 대해서는 IaC 섹션에서 자세히 다루겠습니다.
### 스케일링
자동 확장은 사용하지 않는 리소스를 스핀다운 하거나 필요할 때 스핀업할 수 있는 퍼블릭 클라우드의 큰 기능입니다.
Azure에는 IaaS용 VMSS(Virtual Machine Scale Sets)라는 것이 있습니다. 이를 통해 일정 및 메트릭을 기반으로 골드 스탠다드 이미지를 자동으로 생성하고 확장할 수 있습니다.
이는 윈도우를 업데이트하는 데 이상적이므로 이미지를 업데이트하고 최소한의 영향을 미치면서 배포할 수 있습니다.
Azure 앱 서비스와 같은 다른 서비스에는 자동 확장 기능이 내장되어 있습니다.
### 컨테이너
컨테이너를 사용 사례로 다루지 않았고 DevOps 학습 여정에서 컨테이너가 필요한 이유와 방법을 다루지 않았지만, Azure에는 몇 가지 특정 컨테이너 중심 서비스가 있다는 점을 언급할 필요가 있습니다.
Azure Kubernetes Service(AKS) - 기반 클러스터 관리의 control plane이나 관리에 대해 걱정할 필요가 없는 관리형 Kubernetes 솔루션을 제공합니다. 나중에 Kubernetes에 대해 자세히 알아보세요.
Azure Container Instances - 초당 과금 방식의 서비스형 컨테이너. 컨테이너 오케스트레이션이 필요 없이 이미지를 실행하고 가상 네트워크와 통합할 수 있습니다.
Service Fabric - 많은 기능을 제공하지만, 컨테이너 인스턴스에 대한 오케스트레이션이 포함되어 있습니다.
Azure에는 Docker 이미지, Helm 차트, OCI 아티팩트 및 이미지에 대한 비공개 레지스트리를 제공하는 컨테이너 레지스트리도 있습니다. 이에 대해서는 컨테이너 섹션에서 다시 자세히 설명하겠습니다.
또한 많은 컨테이너 서비스가 실제로 컨테이너를 내부적으로 활용할 수도 있지만 이는 관리 요구 사항에서 추상화되어 있다는 점도 언급해야 합니다.
앞서 언급한 컨테이너 중심 서비스는 다른 모든 퍼블릭 클라우드에서도 비슷한 서비스를 찾을 수 있습니다.
### 애플리케이션 서비스
- Azure Application Services는 서비스를 쉽게 설정할 수 있는 애플리케이션 호스팅 솔루션을 제공합니다.
- 자동 배포 및 확장.
- Windows 및 Linux 기반 솔루션을 지원합니다.
- 서비스는 유형과 크기가 지정된 앱 서비스 플랜에서 실행됩니다.
- 웹 앱, API 앱, 모바일 앱 등 다양한 서비스를 지원합니다.
- 안정적인 테스트 및 홍보를 위한 배포 슬롯 지원.
### 서버리스 컴퓨팅
저에게 서버리스는 더 배우고 싶은 흥미진진한 다음 단계입니다.
서버리스의 목표는 함수의 런타임에 대해서만 비용을 지불하고 가상 머신이나 PaaS 애플리케이션을 항상 실행할 필요가 없다는 것입니다. 필요할 때 함수를 실행하기만 하면 사라집니다.
Azure Functions - 서버리스 코드를 제공합니다. 퍼블릭 클라우드에 대해 처음 살펴본 것을 기억한다면 관리의 추상화 계층을 기억할 수 있는데, 서버리스 함수를 사용하면 코드만 관리하게 됩니다.
대규모의 이벤트 기반은 나중에 실습을 하게 되면 무언가를 구축할 계획이 있습니다.
많은 Azure 및 타사 서비스에 대한 입력 및 출력 바인딩을 제공합니다.
다양한 프로그래밍 언어를 지원합니다. (C#, NodeJS, Python, PHP, batch, bash, Golang 및 Rust. 또는 모든 실행 파일)
Azure Event Grid를 사용하면 서비스 및 이벤트에서 로직을 트리거할 수 있습니다.
Azure Logic App은 그래픽 기반 workflow 및 통합을 제공합니다.
또한 일관된 관리 및 예약을 통해 Windows 및 Linux 노드 모두에서 대규모 작업을 실행할 수 있는 Azure Batch도 살펴볼 수 있습니다.
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
[Day 32](day32.md)에서 봐요!

191
2022/ko/Days/day32.md Normal file
View File

@ -0,0 +1,191 @@
---
title: '#90DaysOfDevOps - Microsoft Azure Storage Models - Day 32'
published: false
description: 90DaysOfDevOps - Microsoft Azure Storage Models
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048775
---
## Microsoft Azure 스토리지 모델
### 스토리지 서비스
- Azure 스토리지 서비스는 스토리지 계정으로 제공됩니다.
- 스토리지 계정은 주로 REST API를 통해 액세스합니다.
- 스토리지 계정은 DNS 이름(`<Storage Account name>.core.windows.net`)의 일부인 고유한 이름을 가져야 합니다.
- 다양한 복제 및 암호화 옵션.
- 리소스 그룹 내에 위치
Azure Portal 상단의 검색 창에서 저장소 그룹을 검색하여 저장소 그룹을 만들 수 있습니다.
![](/2022/Days/Images/Day32_Cloud1.png)
그런 다음 이 이름은 고유해야 하며 공백 없이 모두 소문자이어야 하지만 숫자를 포함할 수 있다는 점을 기억하고 스토리지 계정을 만들기 위한 단계를 실행할 수 있습니다.
![](/2022/Days/Images/Day32_Cloud2.png)
또한 스토리지 계정과 여기에 저장하는 모든 항목에 대해 원하는 중복성 수준을 선택할 수 있습니다. 목록에서 아래로 내려갈수록 옵션은 더 비싸지만, 데이터는 더 많이 분산됩니다.
기본 중복 옵션조차도 데이터의 사본 3개를 제공합니다.
[Azure 스토리지 이중화](https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy)
위 링크의 요약은 아래와 같습니다:
- **Locally-redundant storage** - 기본 지역의 단일 데이터 센터 내에서 데이터를 세 번 복제합니다.
- **Geo-redundant storage** - LRS를 사용하여 기본 지역의 단일 물리적 위치 내에서 데이터를 세 번 동기식으로 복사합니다.
- **Zone-redundant storage** - 기본 지역의 Azure 가용성 영역 3개에 걸쳐 Azure 스토리지 데이터를 동기식으로 복제합니다.
- **Geo-zone-redundant storage** - 가용성 영역 간 중복으로 제공되는 고가용성과 지리적 복제를 통해 제공되는 지역 중단으로부터의 보호를 결합합니다. GZRS 스토리지 계정의 데이터는 기본 지역의 Azure 가용 영역 3개에 복사되며, 지역 재해로부터 보호하기 위해 두 번째 지리적 영역에도 복제됩니다.
![](/2022/Days/Images/Day32_Cloud3.png)
다시 성능 옵션으로 이동합니다. 스탠다드와 프리미엄 중에서 선택할 수 있습니다. 여기서는 스탠다드를 선택했지만, 프리미엄은 몇 가지 구체적인 옵션을 제공합니다.
![](/2022/Days/Images/Day32_Cloud4.png)
드롭다운에서 다음 세 가지 옵션 중에서 선택할 수 있습니다.
![](/2022/Days/Images/Day32_Cloud5.png)
스토리지 계정에 사용할 수 있는 고급 옵션은 훨씬 더 많지만, 지금은 이러한 영역에 대해 자세히 설명할 필요가 없습니다. 이러한 옵션은 암호화와 데이터 보호에 관한 것입니다.
### 관리 디스크
몇 가지 방법으로 스토리지에 액세스할 수 있습니다.
인증된 액세스를 통한 액세스:
- 전체 제어를 위한 공유키.
- 위임된 세분화된 액세스를 위한 공유 액세스 서명.
- Azure Active Directory(사용 가능한 경우)
공용 액세스:
- 공용 액세스를 부여하여 HTTP를 통한 익명 액세스를 활성화할 수도 있습니다.
- 예를 들어 기본 콘텐츠와 파일을 블록 블롭에 호스팅하여 브라우저가 이 데이터를 보고 다운로드할 수 있도록 할 수 있습니다.
다른 Azure 서비스에서 스토리지에 액세스하는 경우 트래픽은 Azure 내에 유지됩니다.
스토리지 성능에는 두 가지 유형이 있습니다:
- **Standard** - 최대 IOPS 수
- **Premium** - 보장된 IOPS 수
IOPS => 초당 입/출력 작업 수.
작업에 적합한 스토리지를 선택할 때 고려해야 할 비관리형 디스크와 관리형 디스크의 차이점도 있습니다.
### 가상 머신 스토리지
- 가상 머신 OS 디스크는 일반적으로 persistent 스토리지에 저장됩니다.
- 일부 상태 비저장 워크로드에는 persistent 스토리지가 필요하지 않으며 레이턴시 감소가 더 큰 이점이 됩니다.
- 노드-로컬 스토리지에 생성되는 임시 OS 관리 디스크를 지원하는 VM이 있습니다.
- 이러한 디스크는 VM 스케일 세트와 함께 사용할 수도 있습니다.
관리 디스크는 Azure Virtual 머신과 함께 사용할 수 있는 내구성 있는 블록 스토리지입니다. Ultra Disk Storage, Premium SSD, Standard SSD 또은 Standard HDD를 사용할 수 있습니다. 또한 몇 가지 특징이 있습니다.
- 스냅샷 및 이미지 지원
- SKU 간 간단한 이동
- 가용성 세트와 결합하여 가용성 향상
- 사용한 스토리지가 아닌 디스크 크기를 기준으로 요금이 청구됩니다.
## 아카이브 스토리지
- **Cool Tier** - 블롭을 차단하고 추가할 수 있는 쿨 티어 스토리지를 사용할 수 있습니다.
- 스토리지 비용 절감
- 트랜잭션 비용이 더 높습니다.
- **Archive Tier** - 블록 블롭에 아카이브 스토리지를 사용할 수 있습니다.
- 이것은 블롭 단위로 구성됩니다.
- 더 저렴한 비용, 더 긴 데이터 검색 대기 시간.
- 일반 Azure 스토리지와 동일한 데이터 내구성.
- 필요에 따라 사용자 지정 데이터 계층화를 사용하도록 설정할 수 있습니다.
### 파일 공유
위에서 스토리지 계정을 만들었으므로 이제 파일 공유를 만들 수 있습니다.
![](/2022/Days/Images/Day32_Cloud6.png)
이렇게 하면 Azure에서 SMB2.1 및 3.0 파일 공유가 제공됩니다.
Azure 내부에서 사용할 수 있으며 인터넷에 연결된 SMB3 및 포트 445를 통해 외부에서도 사용할 수 있습니다.
Azure에서 공유 파일 스토리지를 제공합니다.
REST API 외에 표준 SMB 클라이언트를 사용하여 매핑할 수 있습니다.
[Azure NetApp Files](https://vzilla.co.uk/vzilla-blog/azure-netapp-files-how)(SMB 및 NFS)도 참조하세요.
### 캐싱 및 미디어 서비스
Azure 콘텐츠 전송 네트워크는 전 세계에 위치한 정적 웹 콘텐츠의 캐시를 제공합니다.
Azure 미디어 서비스는 재생 서비스 외에 미디어 트랜스코딩 기술을 제공합니다.
## Microsoft Azure 데이터베이스 모델
지난 [Day 28](day28.md)에서 다양한 서비스 옵션에 대해 다뤘습니다. 그중 하나는 많은 양의 인프라와 운영 체제를 추상화하고 애플리케이션 또는 이 경우 데이터베이스 모델만 제어할 수 있는 PaaS(서비스형 플랫폼)였습니다.
### 관계형 데이터베이스
Azure SQL 데이터베이스는 Microsoft SQL Server를 기반으로 하는 서비스로서의 관계형 데이터베이스를 제공합니다.
이는 특정 기능 버전이 필요한 경우 데이터베이스 호환성 수준을 사용할 수 있는 최신 SQL 브랜치를 실행하는 SQL입니다.
이를 구성하는 방법에는 몇 가지 옵션이 있는데, 인스턴스에서 하나의 데이터베이스를 제공하는 단일 데이터베이스를 제공할 수 있으며, 탄력적 풀을 사용하면 용량 풀을 공유하고 집합적으로 확장하는 여러 데이터베이스를 사용할 수 있습니다.
이러한 데이터베이스 인스턴스는 일반 SQL 인스턴스처럼 액세스할 수 있습니다.
MySQL, PostgreSQL 및 MariaDB를 위한 추가 관리형 제품.
![](/2022/Days/Images/Day32_Cloud7.png)
### NoSQL 솔루션
Azure Cosmos DB는 스키마에 구애받지 않는 NoSQL 구현입니다.
99.99% SLA
자동 유도를 통해 전 세계 어디서나 99번째 백분위수에서 한 자릿수 지연 시간을 제공하는 전 세계에 분산된 데이터베이스입니다.
데이터의 partitioning/sharding/distribution에 파티션 키를 활용합니다.
다양한 데이터 모델 지원(documents, key-value, graph, column-friendly)
다양한 API 지원(DocumentDB SQL, MongoDB, Azure Table Storage, Gremlin)
![](/2022/Days/Images/Day32_Cloud9.png)
[CAP 정리](https://en.wikipedia.org/wiki/CAP_theorem)를 기반으로 다양한 정합성 모델을 제공합니다.
![](/2022/Days/Images/Day32_Cloud8.png)
### 캐싱
Redis와 같은 캐싱 시스템에 대한 자세한 설명은 생략하고 Microsoft Azure에는 Azure Cache for Redis라는 서비스가 있다는 점을 말씀드리고 싶었습니다.
Azure Cache for Redis는 Redis 소프트웨어를 기반으로 하는 인메모리 데이터 저장소를 제공합니다.
- 이 서비스는 오픈 소스 Redis Cache를 구현한 것입니다.
- 호스팅된 보안 Redis 캐시 인스턴스입니다.
- 다양한 티어를 사용할 수 있습니다.
- 캐시를 활용하려면 애플리케이션을 업데이트해야 합니다.
- 쓰기에 비해 읽기 요구 사항이 높은 애플리케이션을 대상으로 합니다.
- 키-값 저장소 기반.
![](/2022/Days/Images/Day32_Cloud10.png)
지난 며칠 동안 Microsoft Azure에 대해 많은 메모를 하고 이론을 공부했지만, 이러한 구성 요소가 어떻게 결합되고 작동하는지에 대한 실무적인 측면으로 들어가기 전에 기본 구성 요소를 다루고 싶었습니다.
시나리오 기반 서비스 배포를 시작하고 실행하기 전에 네트워킹과 관련된 이론이 한 가지 더 남아 있습니다. 또한 지금까지 사용하던 포털을 사용할 때와 Microsoft Azure와 상호 작용할 수 있는 몇 가지 다른 방법도 살펴보고자 합니다.
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
[Day 33](day33.md)에서 봐요!

190
2022/ko/Days/day33.md Normal file
View File

@ -0,0 +1,190 @@
---
title: '#90DaysOfDevOps - Microsoft Azure Networking Models + Azure Management - Day 33'
published: false
description: 90DaysOfDevOps - Microsoft Azure Networking Models + Azure Management
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048706
---
## Microsoft Azure 네트워킹 모델 + Azure 관리
오늘이 Microsoft Azure의 12번째 생일을 기념하는 날인 것 같습니다! (2022년 2월 1일) 아무튼, 이번 포스팅에서는 Microsoft Azure 내의 네트워킹 모델과 Azure 관리 옵션에 대해 알아보려고 합니다. 지금까지는 Azure 포털만 사용했지만, 플랫폼 내에서 리소스를 구동하고 생성하는 데 사용할 수 있는 다른 영역에 대해서도 언급했습니다.
## Azure 네트워크 모델
### 가상 네트워크
- 가상 네트워크는 Azure에서 생성된 구조입니다.
- 가상 네트워크에는 하나 이상의 IP 범위가 할당됩니다.
- 가상 네트워크는 지역 내 구독 내에 존재합니다.
- 가상 서브넷은 네트워크 범위를 분할하기 위해 가상 네트워크에 생성됩니다.
- 가상 머신은 가상 서브넷에 배치됩니다.
- 가상 네트워크 내의 모든 가상 머신은 통신할 수 있습니다.
- 가상 네트워크당 65,536개의 프라이빗 IP.
- 리전으로부터의 송신 트래픽에 대해서만 비용을 지불합니다. (리전을 벗어나는 데이터)
- IPv4 및 IPv6 지원.
- 퍼블릭 대면 및 가상 네트워크 내 IPv6.
Azure 가상 네트워크는 AWS VPC에 비유할 수 있습니다. 하지만 몇 가지 주의해야 할 차이점이 있습니다:
- AWS에서는 기본 VNet이 생성되지만 Microsoft Azure에서는 그렇지 않으므로 요구 사항에 맞게 첫 번째 가상 네트워크를 생성해야 합니다.
- Azure의 모든 가상 머신은 기본적으로 인터넷에 대한 NAT 액세스 권한을 갖습니다. AWS에 따른 NAT 게이트웨이가 없습니다.
- Microsoft Azure에는 사설 또는 공용 서브넷의 개념이 없습니다.
- 공용 IP는 vNIC 또는 로드 밸런서에 할당할 수 있는 리소스입니다.
- 가상 네트워크와 서브넷에는 서브넷 수준 위임을 가능하게 하는 자체 ACL이 있습니다.
- AWS에서는 가용 영역별로 서브넷이 있는 반면, 가상 네트워크에서는 가용 영역 전체에 걸쳐 서브넷이 있습니다.
또한 가상 네트워크 피어링도 있습니다. 이를 통해 테넌트 및 리전 전반의 가상 네트워크를 Azure 백본을 사용하여 연결할 수 있습니다. 전이되지는 않지만, 허브 가상 네트워크의 Azure 방화벽을 통해 활성화할 수 있습니다. 게이트웨이 트랜짓을 사용하면 피어링된 가상 네트워크가 연결된 네트워크에 연결할 수 있으며, 그 예로 ExpressRoute to On-Premises를 들 수 있습니다.
### 액세스 제어
- Azure는 네트워크 보안 그룹을 활용하며, 이는 stateful합니다.
- 규칙을 만든 다음 네트워크 보안 그룹에 할당할 수 있습니다.
- 네트워크 보안 그룹은 서브넷 또는 VM에 적용됩니다.
- 서브넷에 적용되는 경우에도 가상 머신 NIC에서는 여전히 "Edge" 디바이스가 아닌 것으로 적용됩니다.
![](/2022/Days/Images/Day33_Cloud1.png)
- 규칙은 네트워크 보안 그룹에 결합됩니다.
- 우선순위에 따라 유연한 구성이 가능합니다.
- 우선순위 숫자가 낮을수록 우선순위가 높습니다.
- 대부분의 로직은 IP 주소로 구축되지만, 일부 태그와 레이블도 사용할 수 있습니다.
| Description | Priority | Source Address | Source Port | Destination Address | Destination Port | Action |
| ---------------- | -------- | ------------------ | ----------- | ------------------- | ---------------- | ------ |
| Inbound 443 | 1005 | \* | \* | \* | 443 | Allow |
| ILB | 1010 | Azure LoadBalancer | \* | \* | 10000 | Allow |
| Deny All Inbound | 4000 | \* | \* | \* | \* | DENY |
또한 애플리케이션 보안 그룹(ASG)도 있습니다.
- NSG가 성장하는 환경에서 유지 관리가 어려울 수 있는 IP 주소 범위에 초점을 맞추는 경우.
- ASG를 사용하면 다양한 애플리케이션 역할(웹서버, DB 서버, WebApp1 등)에 대한 실제 이름(Monikers)을 정의할 수 있습니다.
- 가상 머신 NIC는 하나 이상의 ASG의 멤버가 됩니다.
그런 다음 ASG는 네트워크 보안 그룹의 일부인 규칙에서 통신 흐름을 제어하는 데 사용할 수 있으며 서비스 태그와 같은 NSG 기능을 계속 사용할 수 있습니다.
| Action | Name | Source | Destination | Port |
| ------ | ------------------ | ---------- | ----------- | ------------ |
| Allow | AllowInternettoWeb | Internet | WebServers | 443(HTTPS) |
| Allow | AllowWebToApp | WebServers | AppServers | 443(HTTPS) |
| Allow | AllowAppToDB | AppServers | DbServers | 1443 (MSSQL) |
| Deny | DenyAllinbound | Any | Any | Any |
### 로드 밸런싱
Microsoft Azure에는 두 가지 로드 밸런싱 솔루션이 있습니다. (퍼스트 파티, Azure 마켓플레이스에서 사용할 수 있는 타사도 있습니다.) 두 솔루션 모두 외부 또는 내부 엔드포인트에서 작동할 수 있습니다.
- Load Balancer (Layer 4)는 해시 기반 배포 및 포트 포워딩을 지원합니다.
- App Gateway (Layer 7)는 SSL offload, 쿠키 기반 세션 선호도, URL 기반 콘텐츠 라우팅과 같은 기능을 지원합니다.
또한 앱 게이트웨이를 사용하면 선택적으로 웹 애플리케이션 방화벽 구성 요소를 사용할 수 있습니다.
## Azure 관리 도구
대부분의 이론 시간을 Azure 포털을 살펴보는 데 할애했는데, 데브옵스 문화를 따르고 이러한 작업, 특히 프로비저닝과 관련된 많은 작업을 처리할 때 API 또는 커맨드라인 도구를 통해 수행한다고 제안하고 싶습니다. Azure 환경의 프로비저닝을 자동화할 때 이를 알아야 하므로 사용할 수 있는 다른 관리 도구 몇 가지를 언급하고 싶었습니다.
### Azure 포털
Microsoft Azure Portal은 커맨드라인 도구의 대안을 제공하는 웹 기반 콘솔입니다. Azure 포털에서 구독을 관리할 수 있습니다. 간단한 웹 앱부터 복잡한 클라우드 배포까지 모든 것을 빌드, 관리 및 모니터링할 수 있습니다. 포털 내에서 찾을 수 있는 또 다른 것은 이러한 이동 경로이며, 앞서 언급했듯이 JSON은 모든 Azure 리소스의 기반이며, 포털에서 시작하여 기능, 서비스 및 기능을 이해한 다음 나중에 자동화된 workflow에 통합하기 위해 그 아래에 있는 JSON을 이해할 수 있습니다.
![](/2022/Days/Images/Day33_Cloud2.png)
Azure Preview Portal도 있으며, 이 포털을 사용하여 새로운 서비스 및 향후 개선 사항을 보고 테스트할 수 있습니다.
![](/2022/Days/Images/Day33_Cloud3.png)
### PowerShell
Azure PowerShell을 살펴보기 전에 PowerShell에 대해 먼저 소개할 필요가 있습니다. PowerShell은 작업 자동화 및 구성 관리 프레임워크, 커맨드라인 셸 및 스크립팅 언어입니다. Linux 섹션에서 셸 스크립팅에 대해 다룬 것과 비슷하다고 감히 말할 수 있습니다. PowerShell은 Windows OS에서 처음 발견되었지만, 이제는 크로스 플랫폼입니다.
Azure PowerShell은 PowerShell 커맨드라인에서 직접 Azure 리소스를 관리하기 위한 cmdlets의 집합입니다.
아래에서 PowerShell 명령 `Connect-AzAccount`를 사용하여 구독에 연결할 수 있음을 확인할 수 있습니다.
![](/2022/Days/Images/Day33_Cloud4.png)
그런 다음 Azure VM과 관련된 특정 명령을 찾으려면 다음 명령을 실행하면 됩니다. 이 PowerShell 프로그래밍 언어에 대해 더 많이 배우고 이해하는 데 몇 시간을 투자할 수 있습니다.
![](/2022/Days/Images/Day33_Cloud5.png)
[여기](https://docs.microsoft.com/en-us/powershell/azure/get-started-azureps?view=azps-7.1.0)에서 PowerShell에서 서비스를 시작하고 프로비저닝하는 방법에 대한 Microsoft의 훌륭한 빠른 시작 가이드를 확인하세요.
### Visual Studio Code
많은 분들께서 보셨듯이 제가 자주 사용하는 IDE는 Visual Studio Code입니다.
Visual Studio Code는 Microsoft에서 Windows, Linux 및 macOS용으로 만든 무료 소스 코드 편집기입니다.
아래에서 Visual Studio Code에 내장된 많은 통합 및 도구를 사용하여 Microsoft Azure 및 그 안의 서비스와 상호 작용할 수 있음을 확인할 수 있습니다.
![](/2022/Days/Images/Day33_Cloud6.png)
### Cloud Shell
Azure Cloud Shell은 Azure 리소스를 관리하기 위한 대화형, 인증된 브라우저 액세스 가능 셸입니다. 작업 방식에 가장 적합한 셸 환경을 선택할 수 있는 유연성을 제공합니다.
![](/2022/Days/Images/Day33_Cloud7.png)
아래에서 볼 수 있듯이 포털 내에서 Cloud Shell을 처음 실행하면 Bash와 PowerShell 중에서 선택할 수 있습니다.
![](/2022/Days/Images/Day33_Cloud8.png)
Cloud Shell을 사용하려면 구독에 약간의 저장 공간을 제공해야 합니다.
Cloud Shell을 사용하도록 선택하면 머신이 스핀업되며, 이러한 머신은 일시적이지만 파일은 디스크 이미지와 마운트된 파일 공유를 통해 두 가지 방식으로 유지됩니다.
![](/2022/Days/Images/Day33_Cloud9.png)
- Cloud Shell은 세션별, 사용자별로 제공되는 임시 호스트에서 실행됩니다.
- 대화형 활동이 없으면 20분 후에 Cloud Shell이 시간 초과됨
- Cloud Shell을 사용하려면 Azure 파일 공유를 마운트해야 함
- Cloud Shell은 Bash와 PowerShell 모두에 동일한 Azure 파일 공유를 사용합니다.
- Cloud Shell은 사용자 계정당 하나의 머신이 할당됨
- Cloud Shell은 파일 공유에 보관된 5GB 이미지를 사용하여 $HOME을 유지합니다.
- 권한은 Bash에서 일반 Linux 사용자로 설정됨
위 내용은 [Cloud Shell 개요](https://docs.microsoft.com/en-us/azure/cloud-shell/overview)에서 복사한 것입니다.
### Azure CLI
마지막으로 Azure CLI에 대해 알아보겠습니다. Azure CLI는 윈도우, 리눅스, 맥OS에서 설치할 수 있습니다. 설치가 완료되면 `az`를 입력한 후 다른 명령어를 입력해 Azure 리소스를 생성, 업데이트, 삭제, 조회할 수 있습니다.
처음 Azure 학습에 들어갔을 때 Azure PowerShell과 Azure CLI가 있어서 약간 혼란스러웠습니다.
이에 대한 커뮤니티의 피드백이 있으면 좋겠습니다. 하지만 제가 알기로 Azure PowerShell은 Windows PowerShell 또는 PowerShell Core에 추가된 모듈(다른 OS에서도 사용 가능하지만 전부는 아님)인 반면, Azure CLI는 Azure에 연결하여 해당 명령을 실행하는 크로스 플랫폼 커맨드라인 프로그램이라고 알고 있습니다.
이 두 옵션 모두 구문은 다르지만, 제가 보기에는 매우 유사한 작업을 수행할 수 있습니다.
예를 들어 PowerShell에서 가상 머신을 만들려면 `New-AzVM` cmdlet을 사용하는 반면, Azure CLI는 `az VM create`를 사용합니다.
앞서 시스템에 Azure PowerShell 모듈이 설치되어 있고 Windows 컴퓨터에서 PowerShell을 통해 호출할 수 있는 Azure CLI도 설치되어 있는 것을 보았습니다.
![](/2022/Days/Images/Day33_Cloud10.png)
이미 언급했듯이 여기서 중요한 점은 올바른 도구를 선택하는 것입니다. Azure는 자동화를 기반으로 실행됩니다. 포털 내에서 수행하는 모든 작업은 리소스를 읽거나, 만들거나, 수정하거나, 삭제하기 위해 실행되는 코드로 변환됩니다.
Azure CLI
- Windows, macOS, Linux에 설치할 수 있는 크로스 플랫폼 커맨드라인 인터페이스
- Windows PowerShell, Cmd, Bash 및 기타 Unix 셸에서 실행됩니다.
Azure PowerShell
- 크로스 플랫폼 PowerShell 모듈, Windows, macOS, Linux에서 실행됨
- Windows PowerShell 또는 PowerShell 필요
사용 중인 환경에서 PowerShell을 사용할 수 없지만 .mdor bash를 사용할 수 있는 경우 Azure CLI를 선택하는 것이 좋습니다.
다음으로 지금까지 살펴본 모든 이론을 바탕으로 몇 가지 시나리오를 만들어 Azure에서 실습해 보겠습니다.
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
[Day 34](day34.md)에서 봐요!

197
2022/ko/Days/day34.md Normal file
View File

@ -0,0 +1,197 @@
---
title: '#90DaysOfDevOps - Microsoft Azure Hands-On Scenarios - Day 34'
published: false
description: 90DaysOfDevOps - Microsoft Azure Hands-On Scenarios
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048763
---
## Microsoft Azure 실습 시나리오
지난 6일 동안 Microsoft Azure와 퍼블릭 클라우드 전반에 대해 집중적으로 살펴봤는데요, Azure의 빌딩 블록을 이해하기 위해서는 많은 이론이 필요했지만, 다른 주요 클라우드 제공업체에도 잘 적용될 수 있을 것입니다.
처음에 퍼블릭 클라우드에 대한 기초 지식을 얻고 최소한 한 공급자를 선택하는 것에 대해 언급했는데, 여러 클라우드를 얕게 다룰 경우 길을 잃기 쉽지만, 한 공급자를 선택한 후 기본 사항을 이해하면 다른 클라우드로 이동하여 학습을 가속화하는 것이 매우 쉽다고 생각됩니다.
이번 마지막 세션에서는 Microsoft에서 만든 참고 자료로 [AZ-104 Microsoft Azure Administrator](https://microsoftlearning.github.io/AZ-104-MicrosoftAzureAdministrator/) 시험 준비에 사용되는 이 페이지에서 실습 시나리오를 골라보겠습니다.
여기에는 컨테이너와 쿠버네티스와 같이 아직 자세히 다루지 않은 내용도 있으므로 아직은 여기에 뛰어들지 않겠습니다.
이전 포스팅에서 Module 1,2,3의 대부분을 만들었습니다.
### 가상 네트워킹
[Module 04](https://microsoftlearning.github.io/AZ-104-MicrosoftAzureAdministrator/Instructions/Labs/LAB_04-Implement_Virtual_Networking.html) 따라 하기:
위의 내용을 살펴보고 #90DaysOfDevOps의 이름을 몇 가지 변경했습니다. 또한 클라우드 셸을 사용하는 대신 Windows 머신에서 Azure CLI를 사용하여 전날 생성한 새 사용자로 로그인했습니다.
브라우저를 열고 계정에 인증할 수 있는 `az login`을 사용하여 이 작업을 수행할 수 있습니다.
그런 다음 아래 작업 중 일부를 빌드하는 데 사용할 PowerShell 스크립트와 Module에서 몇 가지 참조를 만들었습니다. 관련 파일은 이 폴더에서 찾을 수 있습니다.
(/2022/Days/Cloud/01VirtualNetworking)
스크립트의 파일 위치를 사용자 환경에 맞게 변경해야 합니다.
첫 번째 단계에서는 환경에 가상 네트워크나 가상 머신이 생성되어 있지 않고 리소스 그룹에 클라우드 셸 스토리지 위치만 구성되어 있습니다.
먼저 [PowerShell 스크립트](/2022/Days/Cloud/01VirtualNetworking/Module4_90DaysOfDevOps.ps1)를 실행합니다.
![](/2022/Days/Images/Day34_Cloud1.png)
- Task 1: 가상 네트워크 생성 및 구성
![](/2022/Days/Images/Day34_Cloud2.png)
- Task 2: 가상 네트워크에 가상 머신 배포
![](/2022/Days/Images/Day34_Cloud3.png)
- Task 3: Azure VM의 프라이빗 및 퍼블릭 IP 주소 구성
![](/2022/Days/Images/Day34_Cloud4.png)
- Task 4: 네트워크 보안 그룹 구성
![](/2022/Days/Images/Day34_Cloud5.png)
![](/2022/Days/Images/Day34_Cloud6.png)
- Task 5: 내부 이름 확인을 위한 Azure DNS 구성
![](/2022/Days/Images/Day34_Cloud7.png)
![](/2022/Days/Images/Day34_Cloud8.png)
### 네트워크 트래픽 관리
[Module 06](https://microsoftlearning.github.io/AZ-104-MicrosoftAzureAdministrator/Instructions/Labs/LAB_06-Implement_Network_Traffic_Management.html)에 이어서
다음 단계에서는 지난번 리소스 그룹으로 이동하여 리소스를 삭제했는데, 저처럼 사용자 계정을 해당 리소스 그룹에만 접근하도록 설정하지 않았다면 Module 이름을 '90Days\*'로 변경하여 모든 리소스와 리소스 그룹을 삭제할 수 있습니다. 이것이 다음 실습 각각에 대한 제 프로세스입니다.
이 실습에서는 아래 작업 중 일부를 구축하는 데 사용할 Module의 일부 참조와 PowerShell 스크립트도 만들었습니다. 관련 파일은 이 폴더에서 찾을 수 있습니다.
(/2022/Days/Cloud/02TrafficManagement)
- Task 1: 실습 환경 프로비저닝
먼저 [PowerShell 스크립트](/2022/Days/Cloud/02TrafficManagement/Mod06_90DaysOfDevOps.ps1)를 실행합니다.
![](/2022/Days/Images/Day34_Cloud9.png)
- Task 2: 허브 및 스포크 네트워크 Topology 구성
![](/2022/Days/Images/Day34_Cloud10.png)
- Task 3: 가상 네트워크 피어링의 전이성 테스트
이 작업의 경우 90DaysOfDevOps 그룹은 권한 때문에 네트워크 감시자에 액세스할 수 없었는데, 이는 네트워크 감시자가 리소스 그룹에 묶여 있지 않은 리소스 중 하나이기 때문인 것으로 예상됩니다(이 사용자에 대해 RBAC이 적용된 곳). 미국 동부 네트워크 감시자 기여자 역할을 90DaysOfDevOps 그룹에 추가했습니다.
![](/2022/Days/Images/Day34_Cloud11.png)
![](/2022/Days/Images/Day34_Cloud12.png)
![](/2022/Days/Images/Day34_Cloud13.png)
두 개의 스포크 가상 네트워크가 서로 피어링되지 않기 때문에 예상되는 현상입니다(가상 네트워크 피어링은 전이적이지 않음).
- Task 4: 허브 및 스포크 Topology에서 라우팅 구성하기
여기서 제 계정이 90DaysOfDevOps 그룹 내에서 제 사용자로 스크립트를 실행할 수 없는 또 다른 문제가 있었는데, 잘 모르겠으므로 다시 기본 관리자 계정으로 이동했습니다. 90DaysOfDevOps 그룹은 90DaysOfDevOps 리소스 그룹의 모든 소유자이므로 VM 내에서 명령을 실행할 수 없는 이유를 알고 싶습니다.
![](/2022/Days/Images/Day34_Cloud14.png)
![](/2022/Days/Images/Day34_Cloud15.png)
그런 다음 michael.cade@90DaysOfDevOps.com 계정으로 돌아가서 이 섹션을 계속할 수 있었습니다. 여기서 동일한 테스트를 다시 실행하고 있지만 이제 결과에 도달할 수 있습니다.
![](/2022/Days/Images/Day34_Cloud16.png)
- Task 5: Azure 로드밸런싱 장치 구현하기
![](/2022/Days/Images/Day34_Cloud17.png)
![](/2022/Days/Images/Day34_Cloud18.png)
- Task 6: Azure 애플리케이션 게이트웨이 구현
![](/2022/Days/Images/Day34_Cloud19.png)
![](/2022/Days/Images/Day34_Cloud20.png)
### Azure 스토리지
[Module 07](https://microsoftlearning.github.io/AZ-104-MicrosoftAzureAdministrator/Instructions/Labs/LAB_07-Manage_Azure_Storage.html)에 이어서 진행합니다:
이 실습에서는 아래 작업 중 일부를 빌드하는 데 사용할 PowerShell 스크립트와 Module의 일부 참조도 만들었습니다. 관련 파일은 이 폴더에서 찾을 수 있습니다.
(/2022/Days/Cloud/03Storage)
- Task 1: 실습 환경 프로비저닝
먼저 [PowerShell 스크립트](/2022/Days/Cloud/03Storage/Mod07_90DaysOfDeveOps.ps1)를 실행합니다.
![](/2022/Days/Images/Day34_Cloud21.png)
- Task 2: Azure Storage 계정 만들기 및 구성
![](/2022/Days/Images/Day34_Cloud22.png)
- Task 3: 블롭 스토리지 관리
![](/2022/Days/Images/Day34_Cloud23.png)
- Task 4: Azure 스토리지에 대한 인증 및 권한 부여 관리
![](/2022/Days/Images/Day34_Cloud24.png)
![](/2022/Days/Images/Day34_Cloud25.png)
이 기능이 허용되기를 기다리는 동안 조금 조바심이 났지만 결국 작동했습니다.
![](/2022/Days/Images/Day34_Cloud26.png)
- Task 5: Azure 파일 공유 만들기 및 구성하기
실행 명령에서 michael.cade@90DaysOfDevOps.com 에서는 작동하지 않아서 승격된 계정을 사용했습니다.
![](/2022/Days/Images/Day34_Cloud27.png)
![](/2022/Days/Images/Day34_Cloud28.png)
![](/2022/Days/Images/Day34_Cloud29.png)
- Task 6: Azure 스토리지에 대한 네트워크 액세스 관리
![](/2022/Days/Images/Day34_Cloud30.png)
### 서버리스(웹 앱 구현)
[Module 09a](https://microsoftlearning.github.io/AZ-104-MicrosoftAzureAdministrator/Instructions/Labs/LAB_09a-Implement_Web_Apps.html)를 따릅니다:
- Task 1: Azure 웹 앱 만들기
![](/2022/Days/Images/Day34_Cloud31.png)
- Task 2: 스테이징 배포 슬롯 만들기
![](/2022/Days/Images/Day34_Cloud34.png)
- Task 3: 웹 앱 배포 설정 구성
![](/2022/Days/Images/Day34_Cloud33.png)
- Task 4: 스테이징 배포 슬롯에 코드 배포
![](/2022/Days/Images/Day34_Cloud32.png)
- Task 5: 스테이징 슬롯 교체
![](/2022/Days/Images/Day34_Cloud35.png)
- Task 6: Azure 웹 앱의 자동 확장 구성 및 테스트
제가 사용하는 이 스크립트는 (/2022/Days/Cloud/04Serverless)에서 찾을 수 있습니다.
![](/2022/Days/Images/Day34_Cloud36.png)
이것으로 Microsoft Azure와 퍼블릭 클라우드 전반에 대한 섹션을 마무리합니다. 이 시나리오를 작업하는 것이 매우 즐거웠다고 말씀드리고 싶습니다.
## 자료
- [Hybrid Cloud and MultiCloud](https://www.youtube.com/watch?v=qkj5W98Xdvw)
- [Microsoft Azure Fundamentals](https://www.youtube.com/watch?v=NKEFWyqJ5XA&list=WL&index=130&t=12s)
- [Google Cloud Digital Leader Certification Course](https://www.youtube.com/watch?v=UGRDM86MBIQ&list=WL&index=131&t=10s)
- [AWS Basics for Beginners - Full Course](https://www.youtube.com/watch?v=ulprqHHWlng&t=5352s)
다음으로 버전 관리 시스템, 특히 git과 코드 저장소 개요에 대해 살펴볼 것이며, 제가 선호하는 옵션인 GitHub를 선택하겠습니다.
[Day 35](day35.md)에서 봐요!

140
2022/ko/Days/day35.md Normal file
View File

@ -0,0 +1,140 @@
---
title: '#90DaysOfDevOps - The Big Picture: Git - Version Control - Day 35'
published: false
description: 90DaysOfDevOps - The Big Picture Git - Version Control
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049041
---
## 큰 그림: Git - 버전 관리
Git을 시작하기 전에 버전 관리가 무엇이며 왜 필요한지 이해해야 하나요? 이번 Git 시작 단계에서는 버전 관리가 무엇인지, 그리고 Git의 기본 사항에 대해 살펴보겠습니다.
### 버전 제어란 무엇인가요?
Git이 유일한 버전 관리 시스템은 아니므로 여기서는 버전 관리와 관련하여 어떤 옵션과 방법론을 사용할 수 있는지 살펴보고자 합니다.
버전 관리의 가장 분명하고 큰 장점은 프로젝트의 이력을 추적할 수 있다는 것입니다. 우리는 `git log`를 사용하여 이 리포지토리를 되돌아보고 많은 커밋과 많은 코멘트가 있으며 프로젝트에서 지금까지 무슨 일이 일어났는지 확인할 수 있습니다. 명령어에 대해서는 나중에 설명할 테니 걱정하지 마세요. 이제 이것이 소스 코드로 가득 찬 실제 소프트웨어 프로젝트이고 여러 사람이 서로 다른 시간에 소프트웨어에 커밋하고, 다른 작성자와 검토자가 모두 여기에 기록되어 무슨 일이 언제, 누가, 누가 검토했는지 알 수 있다고 생각해보세요.
![](/2022/Days/Images/Day35_Git1.png)
과거 버전 제어는 변경을 하기 전에 수동으로 버전 복사본을 만드는 것과 같은 방식이었을 것입니다. 또한 혹시 모른다는 생각으로 쓸모없는 오래된 코드를 주석 처리했을 수도 있습니다.
![](/2022/Days/Images/Day35_Git2.png)
저는 소스 코드뿐만 아니라 거의 모든 프로젝트에 버전 관리를 사용하기 시작했고, 이와 같은 프로젝트에 대해 이야기합니다(90DaysOfDevOps). 진행된 모든 것을 롤백하고 기록하는 기능을 받아들이는 것은 어떨까요?
그러나 **버전 제어는 백업이 아닙니다!**
버전 관리의 또 다른 이점은 프로젝트의 여러 버전을 관리할 수 있다는 점입니다. 예를 들어 모든 운영 체제에서 사용할 수 있는 무료 앱이 있고 모든 운영 체제에서 사용할 수 있는 유료 앱이 있다고 가정해 봅시다. 대부분의 코드는 두 애플리케이션 간에 공유됩니다. 각 앱에 코드를 복사하여 붙여 넣을 수도 있지만, 개발 인원이 한 명 이상으로 늘어나면 매우 지저분해지고 실수도 발생할 수 있습니다.
프리미엄 앱에는 추가 기능을 프리미엄 커밋이라고 부르고 무료 버전에는 일반 커밋만 포함할 수 있습니다.
버전 관리에서 이를 달성하는 방법은 branch를 사용하는 것입니다.
![](/2022/Days/Images/Day35_Git3.png)
branch를 사용하면 위에서 설명한 것처럼 동일한 앱에 대해 두 개의 코드 스트림을 사용할 수 있습니다. 하지만 소스 코드가 없는 버전에 포함된 새로운 기능이 프리미엄 버전에 포함되기를 원하며, 이를 위해 Merge라는 기능을 사용합니다.
![](/2022/Days/Images/Day35_Git4.png)
무료 버전에서 작업하는 팀과 프리미엄 유료 버전에서 작업하는 팀이 있을 수 있고, 둘 다 전체 코드의 일부에 영향을 주는 코드를 변경하면 어떻게 될지 모르기 때문에 merge는 복잡할 수 있습니다. 변수가 업데이트되어 무언가를 망가뜨릴 수도 있습니다. 그러면 기능 중 하나가 중단되는 충돌이 발생합니다. 버전 관리로는 이러한 충돌을 해결할 수 없습니다. 하지만 버전 제어를 사용하면 이를 쉽게 관리할 수 있습니다.
지금까지 버전 관리를 선택하지 않았다면 일반적으로 가장 큰 이유는 공동 작업 기능입니다. 개발자 간에 코드를 공유할 수 있는 기능, 그리고 앞서 말씀드린 대로 코드라고 하면 동료와 함께 작업하는 공동 프레젠테이션이나 프로젝트 전반에 걸쳐 커뮤니티가 수정 및 업데이트를 제공하는 90DaysOfDevOps 챌린지 등 다른 이유로 소스 제어를 사용하는 사례가 점점 더 많아지고 있습니다.
버전 관리가 없다면 소프트웨어 개발자 팀은 어떻게 이런 일을 처리할 수 있을까요? 저는 프로젝트를 진행하면서 상황을 추적하는 것만으로도 충분히 힘들다는 것을 느낍니다. 저는 그들이 코드를 각 기능 모듈로 분리할 것이라고 예상합니다. 아마도 퍼즐 조각을 한데 모은 다음 릴리스하기 전에 문제와 이슈를 파악했을 것입니다.
버전 관리를 통해 우리는 단일 소스를 확보할 수 있습니다. 여전히 서로 다른 모듈에서 작업할 수 있지만 협업이 더 잘 이루어질 수 있습니다.
![](/2022/Days/Images/Day35_Git5.png)
여기서 한 가지 더 언급할 것은 버전 관리의 이점을 누릴 수 있는 것은 개발자뿐만 아니라 모든 팀원이 가시성을 확보할 수 있을 뿐만 아니라 프로젝트 관리 도구도 여기에 연결하여 작업을 추적할 수 있다는 것입니다. 다른 모듈에서 다룰 Jenkins와 같은 빌드 머신도 있을 수 있습니다. 시스템을 빌드하고 패키징하여 배포 테스트와 메트릭을 자동화하는 도구입니다.
### Git이란 무엇인가요?
Git은 소스 코드 또는 모든 파일의 변경 사항을 추적하는 도구이며, 오픈소스 분산 버전 관리 시스템이라고도 할 수 있습니다.
시스템에서 Git을 사용할 수 있는 방법은 여러 가지가 있는데, 가장 일반적으로는 커맨드라인에서 사용하는 것이 가장 일반적이지만, GUI와 Visual Studio Code와 같은 도구에서도 Git을 인식하는 작업을 활용할 수 있습니다.
이제 로컬 머신에 Git을 설치하기 전에 개략적인 개요를 살펴보겠습니다.
앞서 만든 폴더를 살펴보겠습니다.
![](/2022/Days/Images/Day35_Git2.png)
이 폴더를 버전 제어에 사용하려면 먼저 `git init` 명령을 사용하여 이 디렉토리를 초기화해야 합니다. 지금은 이 명령이 디렉토리를 컴퓨터 어딘가에 있는 데이터베이스의 리포지토리로 저장한다고 생각하면 됩니다.
![](/2022/Days/Images/Day35_Git6.png)
이제 몇 가지 파일과 폴더를 만들 수 있으며 소스 코드가 시작될 수도 있고 이미 여기에 무언가가 있을 수도 있습니다. 우리는 `git add .` 명령을 사용하여 디렉토리의 모든 파일과 폴더를 스냅샷에 넣을 수 있지만 아직 해당 데이터베이스에 아무것도 커밋하지 않았습니다. 우리는 단지 `.`가 있는 모든 파일을 추가할 준비가 되었다고 말하는 것입니다.
![](/2022/Days/Images/Day35_Git7.png)
이제 파일을 커밋하고 싶으면 `git commit -m "My First Commit"` 명령으로 이 작업을 수행합니다. 커밋에 대한 설명을 할 수 있으며 각 커밋에 대해 무슨 일이 일어났는지 알 수 있도록 도와줍니다.
![](/2022/Days/Images/Day35_Git8.png)
이제 프로젝트의 히스토리에서 어떤 일이 일어났는지 확인할 수 있습니다. `git log` 명령어를 사용합니다.
![](/2022/Days/Images/Day35_Git9.png)
`samplecode.ps1`라는 파일을 추가로 생성하면 상태가 달라집니다. 또한 `git status`를 사용하여 리포지토리의 상태를 확인할 수 있는데, 커밋할 항목이 없음을 보여주며 samplecode.ps1이라는 새 파일을 추가할 수 있습니다. 그런 다음 동일한 `git status`를 실행하면 커밋할 파일이 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day35_Git10.png)
`git add samplecode.ps1`명령을 사용하여 새 파일을 추가한 다음`git status`를 다시 실행하면 파일이 커밋될 준비가 된 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day35_Git11.png)
그런 다음 `git commit -m "My Second Commit"` 명령을 실행합니다.
![](/2022/Days/Images/Day35_Git12.png)
`git status`를 한 번 더 입력하면, 모든 것이 다시 깨끗해졌음을 확인할 수 있습니다.
![](/2022/Days/Images/Day35_Git13.png)
이제 최신 변경 사항과 첫 번째 커밋을 보여주는 `git log` 명령을 사용할 수 있습니다.
![](/2022/Days/Images/Day35_Git14.png)
커밋 사이의 변경 사항, 즉 어떤 파일이 추가되거나 수정되었는지 확인하려면 `git diff b8f8 709a`를 사용하면 됩니다.
![](/2022/Days/Images/Day35_Git15.png)
그러면 새 파일을 추가한 경우 변경된 내용이 표시됩니다.
![](/2022/Days/Images/Day35_Git16.png)
나중에 더 자세히 설명하겠지만 커밋을 이동하면서 시간 여행을 할 수 있습니다! 커밋 번호를 사용하면 `git checkout 709a` 명령을 사용하여 새 파일을 잃지 않고 시간을 거슬러 올라갈 수 있습니다.
![](/2022/Days/Images/Day35_Git17.png)
마찬가지로 커밋 번호와 같은 방법으로 앞으로 이동하고 싶을 수도 있고, 여기서 `git switch -` 명령을 사용하여 작업을 취소할 수도 있습니다.
![](/2022/Days/Images/Day35_Git18.png)
TLDR;
- 프로젝트 히스토리 추적하기
- 프로젝트의 여러 버전 관리
- 개발자 및 더 넓은 범위의 팀과 도구 간에 코드 공유
- 팀워크 조정
- 아, 그리고 시간 여행!
너무 많은 내용을 설명한 것 같지만, 어떤 명령어를 사용하는지 몰라도 버전 관리의 큰 그림을 이해할 수 있기를 바랍니다.
다음에는 로컬 머신에 Git을 설치 및 설정하고 Git을 통해 얻을 수 있는 다른 사용 사례와 명령어에 대해 좀 더 자세히 살펴보겠습니다.
## 자료
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
[Day 36](day36.md)에서 봐요!

154
2022/ko/Days/day36.md Normal file
View File

@ -0,0 +1,154 @@
---
title: '#90DaysOfDevOps - Installing & Configuring Git - Day 36'
published: false
description: 90DaysOfDevOps - Installing & Configuring Git
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048738
---
## Git 설치 및 구성
Git은 버전 관리를 위한 오픈 소스 크로스 플랫폼 도구입니다. 저처럼 우분투 또는 대부분의 Linux 환경을 사용하는 경우 이미 Git이 설치되어 있을 수 있지만 설치 및 구성 과정을 살펴보겠습니다.
시스템에 이미 git이 설치되어 있더라도 최신 버전인지 확인하는 것도 좋은 방법입니다.
### Git 설치하기
이미 언급했듯이 Git은 크로스 플랫폼이므로 Windows와 Linux를 통해 실행할 것이지만 [여기](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)에서 macOS도 찾을 수 있습니다.
[Windows](https://git-scm.com/download/win)의 경우 공식 사이트에서 설치할 수 있습니다.
Windows 컴퓨터에서 `winget`을 사용할 수도 있는데, 이것을 Windows 애플리케이션 패키지 관리자라고 생각하면 됩니다.
설치하기 전에 Windows 머신에 어떤 버전이 있는지 확인해 보겠습니다. PowerShell 창을 열고 `git --version`을 실행합니다.
![](/2022/Days/Images/Day36_Git1.png)
WSL 우분투 버전의 Git도 확인할 수 있습니다.
![](/2022/Days/Images/Day36_Git2.png)
이 글을 쓰는 시점에 최신 Windows 릴리스는 `2.35.1`이므로 업데이트해야 할 사항이 몇 가지 있는데 이를 살펴보겠습니다. 리눅스도 마찬가지일 것으로 예상합니다.
저는 최신 설치 프로그램을 다운로드하고 마법사를 실행했으며 여기에 이를 문서화할 것입니다. 주의해야 할 중요한 점은 최신 버전을 설치하기 전에 git이 이전 버전을 제거한다는 것입니다.
즉, 아래에 표시된 프로세스도 대부분 git을 사용하지 않고 설치하는 것과 동일한 프로세스입니다.
매우 간단한 설치입니다. 다운로드가 완료되면 두 번 클릭하고 시작하세요. GNU 라이선스 계약을 읽어보세요. 하지만 이 소프트웨어는 무료 오픈소스 소프트웨어라는 점을 기억하세요.
![](/2022/Days/Images/Day36_Git3.png)
이제 추가로 설치할 컴포넌트를 선택해 git과 연결할 수 있습니다. 저는 Windows에서 bash 스크립트를 실행할 수 있는 Git Bash를 항상 설치합니다.
![](/2022/Days/Images/Day36_Git4.png)
그런 다음 사용할 SSH 실행 파일을 선택할 수 있습니다. 리눅스 섹션에서 보셨을 번들 OpenSSH를 그대로 두겠습니다.
![](/2022/Days/Images/Day36_Git5.png)
그다음에는 실험적인 기능을 활성화할 수 있는데, 저는 필요하지 않으므로 활성화하지 않고 나중에 설치를 통해 돌아와서 언제든지 활성화할 수 있습니다.
![](/2022/Days/Images/Day36_Git6.png)
설치가 완료되었으므로 이제 Git Bash 및 최신 릴리스 노트를 열도록 선택할 수 있습니다.
![](/2022/Days/Images/Day36_Git7.png)
마지막 확인은 PowerShell 창에서 현재 어떤 버전의 git이 있는지 살펴보는 것입니다.
![](/2022/Days/Images/Day36_Git8.png)
매우 간단하며 이제 최신 버전을 사용하고 있습니다. 리눅스 머신에서는 업데이트가 조금 늦은 것 같아서 업데이트 과정을 안내해 드리겠습니다.
`sudo apt-get install git` 명령을 실행하기만 하면 됩니다.
![](/2022/Days/Images/Day36_Git9.png)
다음을 실행하여 소프트웨어 설치를 위한 git 저장소를 추가할 수도 있습니다.
```
sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get install git -y
git --version
```
### Git 구성하기
처음 git을 사용할 때는 몇 가지 설정을 정의해야 합니다,
- Name
- Email
- 기본 에디터
- Line Ending
이 설정은 세 가지 수준에서 수행할 수 있습니다.
- System = 모든 사용자
- Global = 현재 사용자의 모든 리포지토리
- Local = 현재 리포지토리
예제
`git config --global user.name "Michael Cade"`
`git config --global user.email Michael.Cade@90DaysOfDevOPs.com"`
운영 체제에 따라 기본 텍스트 편집기가 결정됩니다. 다음 명령을 설정하지 않은 제 우분투 머신에서는 Nano를 사용하고 있습니다. 아래 명령은 이를 비주얼 스튜디오 코드로 변경합니다.
`git config --global core.editor "code --wait"`
이제 모든 git 구성을 보려면 다음 명령을 사용하면 됩니다.
`git config --global -e`
![](/2022/Days/Images/Day36_Git10.png)
어떤 머신에서든 이 파일의 이름은 `.gitconfig`입니다. 제 Windows 머신에서는 사용자 계정 디렉토리에서 이 파일을 찾을 수 있습니다.
![](/2022/Days/Images/Day36_Git11.png)
### Git 이론
어제 포스트에서 다른 버전 관리 유형이 있으며 이를 두 가지 유형으로 나눌 수 있다고 언급했습니다. 하나는 "클라이언트-서버"이고 다른 하나는 "분산"입니다.
### 클라이언트-서버 버전 제어
git이 등장하기 전에는 클라이언트-서버가 버전 관리를 위한 사실상 유일한 방법이었다. 그 예로 2000년에 설립된 오픈소스 버전 관리 시스템인 [Apache Subversion](https://subversion.apache.org/)을 들 수 있습니다.
이 클라이언트-서버 버전 제어 모델에서는 개발자가 서버에서 소스 코드와 실제 파일을 다운로드하는 것이 첫 번째 단계입니다. 이렇게 한다고 해서 충돌이 예방되는 것은 아니지만 충돌의 복잡성과 해결 방법이 예방됩니다.
![](/2022/Days/Images/Day36_Git12.png)
예를 들어 두 명의 개발자가 같은 파일을 작업하고 있는데 한 개발자가 새로운 변경 사항을 먼저 커밋하거나 서버에 파일을 다시 업로드한다고 가정해 보겠습니다. 두 번째 개발자가 업데이트를 하려고 할 때 충돌이 발생합니다.
![](/2022/Days/Images/Day36_Git13.png)
이때, 첫 번째 개발자의 코드 변경 사항을 가져와서 자신의 작업과 충돌하는 부분을 모두 처리한 다음, 커밋해야 합니다.
![](/2022/Days/Images/Day36_Git15.png)
### 분산 버전 제어
Git이 유일한 분산 버전 제어 시스템은 아닙니다. 하지만 사실상 거의 유일한 시스템입니다.
Git의 주요 이점은 다음과 같습니다:
- 빠름
- 스마트
- 유연함
- 안전 및 보안
클라이언트-서버 버전 제어 모델과 달리 각 개발자는 커밋 히스토리, 모든 branch 등을 의미하는 소스 리포지토리를 다운로드합니다.
![](/2022/Days/Images/Day36_Git16.png)
## 자료
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
[Day 37](day37.md)에서 봐요!

170
2022/ko/Days/day37.md Normal file
View File

@ -0,0 +1,170 @@
---
title: '#90DaysOfDevOps - Gitting to know Git - Day 37'
published: false
description: 90DaysOfDevOps - Gitting to know Git
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048707
---
## Gitting to know Git(Git에 대해 알아보기)
제목과 글 전체에 끔찍한 말장난이 들어가서 죄송합니다. Git을 아재 개그로 바꾼 사람이 제가 처음은 아닐 겁니다!
지난 두 번의 포스팅에서 버전 관리 시스템과 버전 관리 시스템으로서의 Git의 기본적인 workflow에 대해 배웠고, [Day 35](day35.md)에서는 시스템에 Git을 설치하고 업데이트와 구성을 했습니다. 또한 클라이언트-서버 버전 관리 시스템과 분산 버전 관리 시스템인 Git [Day 36](day36.md) 사이의 이론에 대해 조금 더 자세히 알아보았습니다.
이제 Git에서 흔히 볼 수 있는 몇 가지 명령어와 사용 사례를 살펴보겠습니다.
### git은 어디에서 도움을 받을 수 있나요?
git으로 작업을 완료하는 데 필요한 명령이 기억나지 않거나 모를 때가 있을 것입니다. 도움이 필요할 것입니다.
Google이나 검색 엔진이 도움을 찾을 때 가장 먼저 찾을 수 있는 곳일 것입니다.
두 번째는 공식 git 사이트와 문서입니다. [git-scm.com/docs](http://git-scm.com/docs) 여기에서 사용 가능한 모든 명령어에 대한 확실한 정보뿐만 아니라 다양한 리소스를 찾을 수 있습니다.
![](/2022/Days/Images/Day37_Git1.png)
터미널에 연결할 수 없는 경우에도 동일한 문서에 액세스할 수 있어 매우 유용합니다. 예를 들어 `git add` 명령어를 선택했다면 `git add --help`를 실행하면 아래에 설명서가 표시됩니다.
![](/2022/Days/Images/Day37_Git2.png)
셸에서 `git add -h`를 사용하면 사용 가능한 옵션에 대한 요약을 볼 수 있습니다.
![](/2022/Days/Images/Day37_Git3.png)
### Git을 둘러싼 오해
"Git에는 액세스 제어 기능이 없다." - 리더에게 소스 코드를 유지 관리할 수 있는 권한을 부여할 수 있습니다.
"Git은 너무 무겁다." - Git은 대규모 프로젝트의 경우 기록을 줄여주는 얕은(shallow) 저장소를 제공할 수 있습니다.
### 실제 단점
바이너리 파일에는 적합하지 않습니다. 소스 코드에는 적합하지만 실행 파일이나 동영상 등에는 적합하지 않습니다.
도구의 명령어와 기능에 대해 설명하는 데 시간을 할애해야 한다는 점이 사용자 친화적이지 않다는 것을 보여주는 대표적인 예입니다.
하지만 전반적으로 Git은 배우기는 어렵지만 사용하기는 쉽습니다.
### git 생태계
여기서는 git과 관련된 생태계를 간략하게 다루되 일부 영역에 대해 깊이 있게 다루지는 않겠지만 개략적인 수준에서 알아두는 것이 중요하다고 생각합니다.
거의 모든 최신 개발 도구는 Git을 지원합니다.
- 개발자 도구 - 이미 비주얼 스튜디오 코드에 대해 언급했지만, 서브블룸 텍스트 및 기타 텍스트 편집기 및 IDE에 대한 git 플러그인 및 통합을 찾을 수 있습니다.
- 팀 도구 - CI/CD 관점에서의 Jenkins, 메시징 프레임워크의 Slack, 프로젝트 관리 및 이슈 추적을 위한 Jira와 같은 도구에 대해서도 언급했습니다.
- 클라우드 제공업체 - 모든 대형 클라우드 제공업체는 git, Microsoft Azure, Amazon AWS 및 Google Cloud Platform을 지원합니다.
- Git 기반 서비스 - 나중에 더 자세히 다룰 GitHub, GitLab 및 BitBucket이 있습니다. 이러한 서비스는 코드를 위한 소셜 네트워크입니다!
### Git 치트시트
대부분의 명령어를 다루지는 않았지만, 온라인에서 제공되는 몇 가지 치트 시트를 살펴본 후 몇 가지 git 명령어와 그 용도를 문서화하고 싶었습니다. 이 명령어들을 모두 기억할 필요는 없으며, 더 많은 실습과 사용을 통해 최소한 git 기본 명령어 정도는 익힐 수 있을 것입니다.
[Atlassian](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)에서 가져온 것이지만, 적어두고 설명을 읽어보면 명령이 무엇인지 알 수 있을 뿐만 아니라 일상적인 작업에서 실습을 해볼 수 있는 좋은 방법입니다.
### Git 기본 사항
| Command | Example | Description |
| ------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| git init | `git init <directory>` | 지정한 디렉토리에 빈 git 리포지토리를 만듭니다. |
| git clone | `git clone <repo>` | \<repo>에 있는 리포지토리를 로컬 머신에 복제합니다. |
| git config | `git config user.name` | 현재 리포지토리 `system`, `global`, `local` 플래그의 모든 commit에 사용할 작성자 이름을 정의하여 구성 옵션을 설정합니다. |
| git add | `git add <directory>` | 다음 commit을 위해 \<directory>의 모든 변경 사항을 스테이징합니다. 모든 항목에 대해 \<files>와 \<.>을 추가할 수도 있습니다. |
| git commit -m | `git commit -m "<message>"` | 스테이징된 스냅샷을 commit하고, \<message>를 사용하여 commit되는 내용을 자세히 설명합니다. |
| git status | `git status` | 스테이징된 파일, 스테이징되지 않은 파일 및 추적되지 않은 파일을 나열합니다. |
| git log | `git log` | 기본 형식을 사용하여 모든 commit 기록을 표시합니다. 이 명령에는 추가 옵션이 있습니다. |
| git diff | `git diff` | 인덱스와 작업 디렉토리 사이의 스테이징되지 않은 변경 내용을 표시합니다. |
### Git 변경사항 되돌리기
| Command | Example | Description |
| ---------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| git revert | `git revert <commit>` | \<commit>의 모든 변경 사항을 취소하는 새 commit을 만든 다음 현재 branch에 적용합니다. |
| git reset | `git reset <file>` | 스테이징 영역에서 \<file>을 제거하지만 작업 디렉토리는 변경하지 않고 그대로 둡니다. 이렇게 하면 변경 내용을 덮어쓰지 않고 파일을 스테이징 해제할 수 있습니다. |
| git clean | `git clean -n` | 작업 디렉토리에서 어떤 파일을 제거할지 표시합니다. clean을 실행하려면 `-n` 대신 `-f`를 사용해야 합니다. |
### Git 수정 기록
| Command | Example | Description |
| ---------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| git commit | `git commit --amend` | 마지막 commit을 단계적 변경 사항과 마지막 commit을 결합한 것으로 바꿉니다. 아무것도 준비하지 않은 상태에서 사용하면 마지막 commit의 메시지를 편집할 수 있습니다. |
| git rebase | `git rebase <base>` | 현재 branch를 \<base>로 rebase합니다. \<base>는 commit ID, branch 이름, 태그 또는 HEAD에 대한 레퍼런스가 될 수 있습니다. |
| git reflog | `git reflog` | 로컬 리포지토리의 HEAD에 대한 변경 로그를 표시합니다. 날짜 정보를 표시하려면 --relative-date 플래그를 추가해야 하고, 모든 레퍼런스를 표시하려면 --all을 추가해야 합니다. |
### Git Branchs
| Command | Example | Description |
| ------------ | -------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| git branch | `git branch` | 리포지토리에 있는 모든 branch를 나열합니다. \<branch> 인수를 추가하여 \<branch>라는 이름의 새 branch를 만듭니다. |
| git checkout | `git checkout -b <branch>` | \<branch>라는 이름의 새 branch를 생성하고 checkout합니다. 기존 branch를 checkout하려면 -b 플래그를 지웁니다. |
| git merge | `git merge <branch>` | \<branch>를 현재 branch에 merge합니다. |
### Git 원격 리포지토리
| Command | Example | Description |
| -------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| git remote add | `git remote add <name> <url>` | 원격 리포지토리에 대한 새 연결을 생성합니다. 리모트를 추가한 후 \<name>을 다른 명령에서 \<url>에 대한 바로 가기로 사용할 수 있습니다. |
| git fetch | `git fetch <remote> <branch>` | 리포지토리에서 특정 \<branch>를 가져옵니다. 모든 원격 레퍼런스를 가져오려면 \<branch>를 생략하세요. |
| git pull | `git pull <remote>` | 지정된 리모트의 현재 branch 복사본을 가져와서 로컬 복사본에 즉시 merge합니다. |
| git push | `git push <remote> <branch>` | branch를 필요한 commit 및 오브젝트와 함께 \<remote>로 push합니다. 원격 리포지토리에 이름이 지정된 branch가 없는 경우 branch를 생성합니다. |
### Git Diff
| Command | Example | Description |
| ----------------- | ------------------- | ----------------------------------------------------- |
| git diff HEAD | `git diff HEAD` | 작업 디렉토리와 마지막 commit의 diff를 표시합니다. |
| git diff --cached | `git diff --cached` | 단계적 변경 사항과 마지막 commit의 diff를 표시합니다. |
### Git Config
| Command | Example | Description |
| ------------------------------------------------------ | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| git config --global user.name \<name> | `git config --global user.name <name>` | 현재 사용자가 모든 commit에 사용할 작성자 이름을 정의합니다. |
| git config --global user.email \<email> | `git config --global user.email <email>` | 현재 사용자가 모든 commit에 사용할 작성자 이메일을 정의합니다. |
| git config --global alias \<alias-name> \<git-command> | `git config --global 별칭 <alias-name> <git-command>` | git 명령에 대한 단축어를 만듭니다. |
| git config --system core.editor \<editor> | `git config --system core.editor <editor>` | 컴퓨터의 모든 사용자에 대한 명령에서 사용할 텍스트 편집기를 설정합니다. \<editor> 인수는 원하는 편집기를 실행하는 명령이어야 합니다. |
| git config --global --edit | `git config --global --edit ` | 수동 편집을 위해 텍스트 편집기에서 전역 구성 파일을 엽니다. |
### Git Rebase
| Command | Example | Description |
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| git rebase -i \<base> | `git rebase -i <base>` | 현재 branch를 \<base>로 rebase합니다. 편집기를 사용하여 각 commit을 새 저장소로 옮기는 방법에 대한 명령을 입력해야 합니다. |
### Git Pull
| Command | Example | Description |
| --------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| git pull --rebase \<remote> | `git pull --rebase <remote>` | 현재 branch의 리모트 복사본을 가져와서 로컬 복사본으로 rebase합니다. branch를 통합하기 위해 merge 대신 git rebase를 사용합니다. |
### Git Reset
| Command | Example | Description |
| -------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| git reset | `git reset` | 스테이징 영역을 가장 최근 commit과 일치하도록 reset하되 작업 디렉토리는 변경하지 않습니다. |
| git reset --hard | `git reset --hard` | 스테이징 영역과 작업 디렉토리를 가장 최근 commit과 일치하도록 reset하고 작업 디렉토리의 모든 변경 내용을 덮어씁니다. |
| git reset \<commit> | `git reset <commit>` | 현재 branch 끝을 \<commit> 뒤로 이동하고 스테이징 영역을 일치하도록 reset하되 작업 디렉토리는 그대로 둡니다 |
| git reset --hard \<commit> | `git reset --hard <commit>` | 이전과 동일하지만 스테이징 영역과 작업 디렉토리를 모두 일치하도록 reset합니다. commit되지 않은 변경 사항과 \<commit> 이후의 모든 commit을 삭제합니다. |
### Git Push
| Command | Example | Description |
| -------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| git push \<remote> --force | `git push <remote> --force` | non-fast-forward merge가 아닌 경우에도 git push를 강제로 수행합니다. 자신이 무엇을 하고 있는지 확실하지 않으면 --force 플래그를 사용하지 말아야 합니다. |
| git push \<remote> --all | `git push <remote> --all` | 모든 로컬 branch를 지정한 리모트로 push 합니다. |
| git push \<remote> --tags | `git push <remote> --tags` | branch를 push하거나 --all 플래그를 사용하면 태그가 자동으로 push되지 않습니다. tags 플래그는 모든 로컬 태그를 원격 리포지토리에 보냅니다. |
## 자료
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
[Day 38](day38.md)에서 봐요!

127
2022/ko/Days/day38.md Normal file
View File

@ -0,0 +1,127 @@
---
title: '#90DaysOfDevOps - Staging & Changing - Day 38'
published: false
description: 90DaysOfDevOps - Staging & Changing
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049042
---
## 스테이징 및 변경
이미 몇 가지 기본 사항을 다뤘지만, 이렇게 연습을 해보면 어떻게 그리고 왜 이런 방식으로 작업하는지 더 잘 이해하고 배울 수 있습니다. GitHub와 같은 git 기반 서비스에 들어가기 전에 로컬 워크스테이션에서 활용할 수 있는 git의 강력한 기능을 살펴봅시다.
git 세션을 시작할 때 만든 프로젝트 폴더를 가지고 git으로 할 수 있는 몇 가지 간단한 예제를 보여드리겠습니다. 로컬 머신에 폴더를 생성하고 `git init` 명령으로 초기화했습니다.
![](/2022/Days/Images/Day38_Git1.png)
이제 폴더를 초기화했으므로 디렉토리에 숨겨진 폴더가 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day38_Git2.png)
이 폴더에는 branch 및 커밋에 관한 정보뿐만 아니라 git 저장소의 세부 정보가 저장됩니다.
### 스테이징 파일
그런 다음 빈 폴더에서 작업을 시작하고 작업 첫날에 소스 코드를 추가할 수 있습니다. README.md 파일을 생성하면 디렉토리에서 해당 파일을 볼 수 있고, 다음으로 `git status`를 확인하면 새 README.md 파일이 보이지만, 아직 그 파일을 커밋하지는 않은 상태입니다.
![](/2022/Days/Images/Day38_Git3.png)
이제 `git add README.md` 명령으로 README.md 파일을 스테이징하면 이전에 없던 변경 사항과 초록색으로 표시되는 새 파일을 커밋할 수 있는 상태가 됩니다.
![](/2022/Days/Images/Day38_Git4.png)
다음으로 프로젝트의 첫 번째 커밋 또는 첫 번째 스냅샷인 이 파일을 커밋하고 싶습니다. 각 커밋에 대해 변경된 내용을 쉽게 확인할 수 있도록 `git commit -m "의미 있는 메시지"` 명령을 사용하여 이 작업을 수행할 수 있습니다. 또한 노란색 십자가가 이제 녹색 체크 표시로 바뀐 것을 확인할 수 있습니다. 이것은 제가 터미널에서 사용하는 테마로, 리눅스 섹션에서 다룬 내용입니다.
![](/2022/Days/Images/Day38_Git5.png)
### 변경 사항 커밋
파일을 더 추가하거나 디렉토리에 있는 파일을 변경하고 싶을 때가 많습니다. 위에서 이미 첫 번째 커밋을 했습니다. 하지만 이제 더 많은 세부 사항으로 더 많은 파일을 추가하겠습니다.
이전 프로세스를 반복하여 파일을 만들거나 수정한 다음 `git add .`를 실행하여 모든 파일을 스테이징 영역에 추가한 다음 `git commit -m "의미 있는 메시지"`를 실행하면 정상적으로 작동할 수 있습니다. 그러나 커밋에 변경된 내용에 대한 의미 있는 메시지를 제공하려면 `git commit -m "음, 일부 코드가 작동하지 않아서 변경했으며, 이를 수정할 때 모든 사람이 사용자 경험에 대해 알 수 있도록 README.md에 새로운 내용을 추가했습니다."`와 같이 설명적인 내용을 작성하는 것도 가능하지만 여기서는 텍스트 편집기를 사용하여 추가하는 것이 더 바람직할 수 있습니다.
`git add`를 실행한 후 `git commit`을 실행하면 기본 텍스트 편집기(여기서는 nano)가 열립니다. 다음은 파일에 몇 가지 변경 사항을 추가하기 위해 수행한 단계이며, `git status`를 실행하여 스테이징된 항목과 스테이징되지 않은 항목을 표시합니다. 그런 다음 `git add`를 사용하여 파일을 스테이징 영역에 추가한 다음 `git commit`을 실행하여 nano를 열었습니다.
![](/2022/Days/Images/Day38_Git6.png)
Nano가 열리면 설명을 추가한 다음 파일을 저장할 수 있습니다.
![](/2022/Days/Images/Day38_Git7.png)
### 커밋 모범 사례
커밋 시기와 커밋 횟수 사이에는 균형이 필요합니다. 프로젝트가 끝날 때까지 기다렸다가 커밋하는 것은 바람직하지 않으며, 각 커밋은 의미가 있어야 하고 서로 관련 없는 작업들은 함께 커밋해서는 안 됩니다. 버그 수정과 오타를 해결한 경우, 두 가지 커밋을 분리하여 커밋하는 것이 좋습니다.
커밋 메시지에 의미를 부여하세요.
문구 측면에서, 팀이나 본인이 각 커밋에 대해 동일한 문구를 사용해야 합니다.
### 스테이징 영역 건너뛰기
변경 사항을 커밋하기 전에 항상 스테이징해야 할까요?
정답은 '예'이지만, 롤백할 스냅샷이 필요하지 않다는 것을 100% 확신해야 하며, 이는 위험할 수 있습니다.
![](/2022/Days/Images/Day38_Git8.png)
### 파일 제거
프로젝트에서 파일을 제거하는 것은 어떨까요? 디렉토리에 커밋했지만 이제 프로젝트에 더 이상 필요하지 않거나 사용하지 않는 다른 파일이 있는 경우, 파일을 제거해야 합니다.
디렉토리에서 파일을 제거해도 git은 여전히 이 파일을 인식하므로 리포지토리에서도 파일을 제거해야 합니다. 아래에서 이를 위한 workflow를 확인할 수 있습니다.
![](/2022/Days/Images/Day38_Git9.png)
이동하는 파일과 폴더가 많은 대규모 프로젝트의 경우 기억하거나 처리하는 것이 다소 번거로울 수 있습니다. 이 작업은 `git rm oldcode.ps1` 명령 하나로 수행할 수 있습니다.
![](/2022/Days/Images/Day38_Git10.png)
### 파일 이름 바꾸기 또는 이동
운영 체제 내에서 파일 이름을 바꾸고 이동할 수 있습니다. 프로젝트에서 때때로 이 작업을 해야 할 때가 있을 것입니다. 2단계 프로세스가 있지만 제거와 유사하게, OS에서 파일을 변경한 다음 스테이징 영역이나 파일이 올바르게 추가되었는지 수정하고 확인해야 합니다. 단계는 다음과 같습니다:
![](/2022/Days/Images/Day38_Git11.png)
그러나 운영 체제에서 파일을 제거한 다음 git 리포지토리에서 파일을 제거하는 것과 마찬가지로 git 명령을 사용하여 이름 변경을 할 수 있습니다.
![](/2022/Days/Images/Day38_Git12.png)
### 파일 무시하기
프로젝트 내 로컬에서만 사용 중이거나 전체 프로젝트에 공유되면 공간 낭비일 수 있는 파일이나 폴더를 무시해야 하는 경우가 있는데, 그 좋은 예로 로그를 들 수 있습니다. 또한 공개적으로 또는 팀 간에 공유하고 싶지 않은 비밀에 대해서도 이 기능을 사용할 수 있다고 생각합니다.
프로젝트 디렉토리의 `.gitignore` 파일에 폴더나 파일을 추가하여 파일을 무시할 수 있습니다.
![](/2022/Days/Images/Day38_Git13.png)
`.gitignore` 파일을 열면 logs/ 디렉토리가 있는 것을 확인할 수 있습니다. 여기에 무시할 파일과 폴더를 추가할 수도 있습니다.
![](/2022/Days/Images/Day38_Git14.png)
이제 `git status`를 보고 어떤 일이 일어났는지 확인할 수 있습니다.
![](/2022/Days/Images/Day38_Git15.png)
로그 폴더를 이미 공유했지만, 나중에 공유하면 안 된다는 것을 깨달았을 때 파일과 폴더를 무시해야 하는 경우도 있습니다. 이전에 추적한 폴더가 있지만 이제 무시하고 싶은 경우 `git rm --cached`를 사용하여 스테이징 영역에서 파일과 폴더를 제거해야 합니다.
### 간략한 status
준비 영역에 무엇이 있고 무엇이 없는지 파악하기 위해 `git status`를 많이 사용해왔는데, 이 명령은 매우 포괄적이고 세부적인 내용을 담고 있습니다. 대부분의 경우 무엇이 수정되었는지 또는 무엇이 새로운 것인지 알고 싶을 것입니다. 이 세부 사항에 대한 간단한 상태를 확인하려면 `git status -s`를 사용할 수 있습니다. 저는 보통 시스템에서 단축어로 설정하여 더 자세한 명령 대신 `git status -s`만 사용하도록 합니다.
![](/2022/Days/Images/Day38_Git16.png)
내일 포스트에서는 이러한 일반적인 git 명령에 대한 간략한 예제를 계속 살펴보겠습니다.
## 자료
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
[Day 39](day39.md)에서 봐요!

212
2022/ko/Days/day39.md Normal file
View File

@ -0,0 +1,212 @@
---
title: '#90DaysOfDevOps - Viewing, unstaging, discarding & restoring - Day 39'
published: false
description: '90DaysOfDevOps - Viewing, unstaging, discarding & restoring'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048827
---
## 보기, 스테이징 해제, 삭제 및 복원
어제에 이어서 git에서 사용할 수 있는 몇 가지 명령어와 프로젝트에서 git을 활용하는 방법에 대해 알아보겠습니다. 아직 GitHub나 다른 git 기반 서비스에 대해서는 다루지 않았지만, 지금은 로컬에서 프로젝트를 제어하는 데 도움이 되는 내용이며, 향후 해당 도구에 통합되기 시작하면 모두 유용하게 사용할 수 있을 것입니다.
### 스테이징된 변경 사항과 스테이징되지 않은 변경 사항 보기
commit하기 전에 스테이징된 코드와 스테이징되지 않은 코드를 확인하는 것이 좋습니다. 다음 `git diff --staged` 명령을 실행하면 됩니다.
![](/2022/Days/Images/Day39_Git1.png)
그러면 우리가 수행한 모든 변경 사항과 추가하거나 삭제한 모든 새 파일이 표시됩니다.
수정한 파일의 변경 사항은 `---` 또는 `+++`로 표시되며, 아래에서 방금 + 추가한 텍스트는 새로운 줄임을 의미합니다.
![](/2022/Days/Images/Day39_Git2.png)
또한 `git diff`를 실행하여 스테이징 영역과 작업 디렉토리를 비교할 수 있습니다. 새로 추가한 code.txt 파일을 변경하고 몇 줄의 텍스트를 추가하면 다음과 같습니다.
![](/2022/Days/Images/Day39_Git3.png)
그런 다음 `git diff`를 실행하면 아래와 같은 출력을 비교하여 확인할 수 있습니다.
![](/2022/Days/Images/Day39_Git4.png)
### 시각적 Diff 도구
저는 위의 방법이 혼란스럽다고 생각하기 때문에 시각적 도구를 사용하는 편이 낫습니다,
몇 가지 시각적 Diff 도구를 소개합니다:
- KDiff3
- P4Merge
- WinMerge (Windows 전용)
- VSCode
git에서 설정하려면 다음 명령 `git config --global diff.tool vscode`를 실행합니다.
위의 명령어를 실행하고 VScode를 시작할 때 몇 가지 매개 변수를 설정하겠습니다.
![](/2022/Days/Images/Day39_Git5.png)
또한 `git config --global -e`로 설정을 확인할 수 있습니다.
![](/2022/Days/Images/Day39_Git6.png)
이제 `git difftool`을 사용하여 Diff 시각화 도구를 열 수 있습니다.
![](/2022/Days/Images/Day39_Git7.png)
이제 Diff 페이지에서 VScode 에디터를 열고 두 파일을 비교하면, 아무것도 없는 상태에서 오른쪽에 코드 한 줄을 추가한 파일 하나만 수정했습니다.
![](/2022/Days/Images/Day39_Git8.png)
이 방법은 변경 사항을 추적하기가 훨씬 쉬우며, GitHub와 같은 Git 기반 서비스를 살펴볼 때 보게 될 것과 비슷한 방식입니다.
또한 `git difftool --staged`를 사용하여 commit된 파일과 스테이지를 비교할 수 있습니다.
![](/2022/Days/Images/Day39_Git9.png)
그러면 commit하기 전에 변경된 파일들을 확인할 수 있게 됩니다.
![](/2022/Days/Images/Day39_Git10.png)
저는 IDE로 VScode를 사용하고 있으며 대부분의 IDE와 마찬가지로 이미 내장되어 있는 명령어이므로 터미널에서 직접 실행해야 하는 경우는 매우 드물지만, 어떤 이유로 IDE가 설치되어 있지 않은 경우 유용합니다.
### 히스토리 보기
앞서 리포지토리에서 수행한 모든 commit을 종합적으로 볼 수 있는 `git log`에 대해 살펴봤습니다.
![](/2022/Days/Images/Day39_Git11.png)
각 commit에는 리포지토리에 고유한 16진수 문자열이 있습니다. 여기에서 작업 중인 branch와 작성자, 날짜, commit 메시지를 확인할 수 있습니다.
또한 `git log --oneline`을 사용하면 다른 `diff` 명령에서 사용할 수 있는 훨씬 더 작은 버전의 16진수 문자열을 얻을 수 있습니다. 또한 한 줄 설명 또는 commit 메시지만 있습니다.
![](/2022/Days/Images/Day39_Git12.png)
`git log --oneline --reverse`를 실행하면 페이지 상단에 첫 번째 commit이 표시됩니다.
![](/2022/Days/Images/Day39_Git13.png)
### commit 보기
commit 메시지를 볼 수 있는 것은 모범 사례를 따르고 의미 있는 commit 메시지를 추가한 경우 매우 유용하지만, commit을 검사하고 볼 수 있는 `git show` 명령도 있습니다.
우리는 `git log --oneline --reverse`를 사용하여 commit 목록을 가져올 수 있습니다. 그런 다음 이를 가져와서 `git show <commit ID>`를 실행할 수 있습니다.
![](/2022/Days/Images/Day39_Git14.png)
이 명령의 출력은 commit, 작성자 및 변경된 내용에 대한 세부 정보와 함께 아래와 같이 표시됩니다.
![](/2022/Days/Images/Day39_Git15.png)
`git show HEAD~1`을 사용할 수도 있습니다. 여기서 1은 현재 버전에서 몇 단계 뒤로 돌아가려는지 나타냅니다.
이 방법은 파일에 대한 세부 정보를 원하지만, 전체 스냅샷 디렉토리에 대한 트리의 모든 파일을 나열하려는 경우에 유용합니다. 마지막 commit에서 다시 한 스냅샷을 거슬러 올라가는 `git ls-tree HEAD~1` 명령을 사용하면 이 작업을 수행할 수 있습니다. 아래에서 두 개의 blob이 있는 것을 볼 수 있는데, blob은 파일을 나타내고 트리는 디렉토리를 나타냅니다. 이 정보에서 commit과 태그도 볼 수 있습니다.
![](/2022/Days/Images/Day39_Git16.png)
이제 위의 내용을 사용하여 `git show` 명령을 사용하여 파일(blob)의 내용을 자세히 확인할 수 있습니다.
![](/2022/Days/Images/Day39_Git17.png)
그러면 특정 버전의 파일 내용이 표시됩니다.
![](/2022/Days/Images/Day39_Git18.png)
### 파일 스테이징 해제
`git add .`를 사용했지만 아직 해당 스냅샷에 commit하고 싶지 않은 파일이 있는 경우가 있을 수 있습니다. 아래 예제에서는 스테이징 영역에 newfile.txt를 추가했지만, 이 파일을 commit할 준비가 되지 않았으므로 `git restore --staged newfile.txt`를 사용하여 `git add` 단계를 실행 취소하겠습니다.
![](/2022/Days/Images/Day39_Git19.png)
위 그림에서 수정된 파일(예: main.js)에 대해서도 동일한 작업을 수행하여 commit의 스테이징을 해제할 수 있습니다.
![](/2022/Days/Images/Day39_Git20.png)
저는 이 명령어가 90DaysOfDevOps 기간 동안 매우 유용하다는 것을 알았습니다. 다음 날을 위한 메모를 작성하고 싶지만, 공개 GitHub 리포지토리에 commit하고 push하고 싶지 않은 날을 앞두고 작업하는 경우가 종종 있기 때문입니다.
### 로컬 변경 사항 삭제하기
때때로 우리는 변경을 했지만, 그 변경이 마음에 들지 않아서 버리고 싶을 때가 있습니다. 다시 `git restore` 명령을 사용하여 스냅샷 또는 이전 버전에서 파일을 복원할 수 있습니다. 디렉토리에 대해 `git restore .`를 실행하면 스냅샷에서 모든 것을 복원할 수 있지만 추적되지 않은 파일이 여전히 존재한다는 것을 알 수 있습니다. 추적 중인 이전 파일은 newfile.txt라는 파일이 없습니다.
![](/2022/Days/Images/Day39_Git21.png)
이제 새로운 파일 txt 또는 추적되지 않은 파일을 제거합니다. 우리는 `git clean`을 사용하면 경고만 받을 수 있습니다.
![](/2022/Days/Images/Day39_Git22.png)
또는 결과를 알고 있다면 `git clean -fd`를 실행하여 모든 디렉토리를 강제로 제거할 수 있습니다.
![](/2022/Days/Images/Day39_Git23.png)
### 파일을 이전 버전으로 복원하기
앞서 언급했듯이 Git의 큰 장점 중 하나는 스냅샷에서 파일 사본을 복원할 수 있다는 점입니다(백업은 아니지만 매우 빠른 복원 방법입니다). 백업 솔루션을 사용하여 코드 사본을 다른 위치에도 저장하는 것을 추천드립니다.
예시로 디렉토리에서 가장 중요한 파일을 삭제해 보겠습니다. 디렉토리에서 이 파일을 제거하기 위해 git 명령이 아닌 Unix 기반 명령을 사용하고 있음을 알 수 있습니다.
![](/2022/Days/Images/Day39_Git24.png)
이제 작업 디렉토리에 readme.md가 없습니다. `git rm readme.md`를 사용하면 git 데이터베이스에 반영될 수 있습니다. 완전히 제거된 것을 시뮬레이션하기 위해 여기서도 삭제해 보겠습니다.
![](/2022/Days/Images/Day39_Git25.png)
이제 이 내용을 메시지와 함께 commit하고 작업 디렉토리 또는 스테이징 영역에 더 이상 아무것도 없음을 증명해 보겠습니다.
![](/2022/Days/Images/Day39_Git26.png)
실수가 있었으니 이제 이 파일을 되돌릴 필요가 있습니다!
`git undo` 명령을 사용하여 마지막 commit을 취소할 수 있지만, 오래된 commit이라면 어떻게 해야 할까요? `git log` 명령을 사용하여 commit 기록을 찾을 수 있습니다. 파일이 마지막 commit에 포함되어 있다는 것을 확인했지만, 모든 commit을 취소하고 싶지는 않습니다. 이 경우 `git restore --source=HEAD~1 README.md` 명령을 사용하여 특정 파일을 찾고 스냅샷에서 복원할 수 있습니다.
이 프로세스를 통해 파일을 작업 디렉토리에 다시 가져온 것을 볼 수 있습니다.
![](/2022/Days/Images/Day39_Git27.png)
이제 추적되지 않은 새 파일이 생겼으며 앞서 언급한 명령을 사용하여 파일과 변경 사항을 추적, 스테이징 및 commit할 수 있습니다.
### Rebase와 Merge
git 리포지토리에서 언제 rebase를 사용해야 하는지, 언제 merge를 사용해야 하는지가 가장 골치 아픈 문제인 것 같습니다.
가장 먼저 알아야 할 것은 `git rebase``git merge`이 모두 같은 문제를 해결한다는 것입니다. 둘 다 한 branch의 변경 내용을 다른 branch에 통합하는 것입니다. 하지만 다른 방식으로 이 작업을 수행합니다.
새로운 feature branch로 새로운 기능을 만들어보겠습니다. main branch는 새로운 commit이 계속 추가되고 있습니다.
![](/2022/Days/Images/Day39_Git28.png)
여기서 쉬운 옵션은 `git merge feature main`을 사용하여 main branch를 feature branch에 merge하는 것입니다.
![](/2022/Days/Images/Day39_Git29.png)
merge는 비파괴적이기 때문에 간단합니다. 기존 branch는 어떤 방식으로도 변경되지 않습니다. 하지만 feature branch에 업스트림 변경 사항을 통합해야 할 때마다 관련 없는 merge commit이 발생하게 됩니다. main branch가 매우 바쁘거나 활성 상태인 경우 feature branch 히스토리를 오염시킬 수도 있습니다.
다른 옵션으로, feature branch를 main branch에 rebase하는 방법도 있습니다.
```
git checkout feature
git rebase main
```
이렇게 하면 feature branch(전체 feature branch)가 main branch에 모든 새 commit을 효과적으로 통합합니다. 그러나 merge commit을 사용하는 대신 rebase는 원래 branch에 있는 각 commit에 대해 새로운 commit을 생성하여 프로젝트 기록을 다시 작성하게 됩니다.
![](/2022/Days/Images/Day39_Git30.png)
rebase의 가장 큰 장점은 프로젝트 히스토리가 훨씬 깔끔해진다는 것입니다. 또한 불필요한 merge commit을 제거하며, 마지막 두 이미지를 비교하면 훨씬 더 깔끔한 선형 프로젝트 히스토리를 따라갈 수 있습니다.
아직 확실한 결론은 아니지만, 더 깔끔한 히스토리를 선택하는 것도 장단점이 있는데, [rebase의 황금률](https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing)을 따르지 않는다면 프로젝트 히스토리를 다시 작성하는 것은 협업 workflow에 치명적일 수 있습니다. 그리고 더 중요한 것은 rebase를 하면 merge commit이 제공하는 컨텍스트가 사라져 업스트림 변경 사항이 언제 feature에 통합되었는지 알 수 없다는 것입니다.
## 자료
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
- [Exploring the Git command line A getting started guide](https://veducate.co.uk/exploring-the-git-command-line/)
[Day 40](day40.md)에서 봐요!

210
2022/ko/Days/day40.md Normal file
View File

@ -0,0 +1,210 @@
---
title: '#90DaysOfDevOps - Social Network for code - Day 40'
published: false
description: 90DaysOfDevOps - Social Network for code
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049044
---
## 코드를 위한 소셜 네트워크
GitHub 살펴보기 | GitLab | BitBucket
오늘은 우리 모두가 들어봤을 법한, 그리고 우리도 매일 사용할 것으로 예상되는 몇 가지 git 기반 서비스를 다루고자 합니다.
그런 다음 이전 세션에서 배운 지식을 사용하여 데이터의 사본을 각 주요 서비스로 이동해 보겠습니다.
이 섹션을 "코드를 위한 소셜 네트워크"라고 부른 이유를 설명해드릴까요?
### GitHub
적어도 저에게 가장 일반적인 것은 GitHub입니다. GitHub는 Git을 위한 웹 기반 호스팅 서비스입니다. 소프트웨어 개발자가 코드를 저장하는 데 가장 일반적으로 사용합니다. git 버전 관리 기능뿐만 아니라 다양한 추가 기능을 통해 소스 코드를 관리할 수 있습니다. 팀이나 오픈 컨트리뷰터가 쉽게 소통할 수 있으며 코딩에 소셜 측면을 제공합니다. (따라서 소셜 네트워킹이라는 제목을 붙였습니다.) 2018년부터 GitHub는 Microsoft의 일부가 되었습니다.
GitHub는 2007/2008년에 설립되어 꽤 오래전부터 존재해 왔습니다. 현재 4천만 명 이상의 사용자가 이 플랫폼을 사용하고 있습니다.
GitHub 주요 기능
- 코드 리포지토리
- Pull Requests
- 프로젝트 관리 도구 세트 - Issues
- CI/CD 파이프라인 - GitHub Actions
가격 측면에서 GitHub는 사용자에 따라 다양한 수준의 가격을 책정합니다. 자세한 내용은 [가격](https://github.com/pricing)에서 확인할 수 있습니다.
여기서는 프리티어를 다루겠습니다.
이 안내에서는 이미 생성한 GitHub 계정을 사용할 예정이므로 계정이 없는 경우, GitHub 시작 페이지에서 가입 옵션과 몇 가지 간단한 단계를 통해 설정할 수 있습니다.
### GitHub 시작 페이지
GitHub 계정에 처음 로그인하면 다양한 위젯이 포함된 페이지가 표시되어 어디에서 무엇을 보고 싶고 무엇을 할 것인지에 대한 옵션을 제공합니다. 먼저 "All Activity"를 통해 리포지토리에서 어떤 일이 일어나고 있는지 또는 조직이나 계정과 관련된 일반적인 활동을 살펴볼 수 있습니다.
![](/2022/Days/Images/Day40_Git1.png)
다음으로, 자체 리포지토리 또는 최근에 상호 작용한 리포지토리가 있는 코드 리포지토리가 있습니다. 새 리포지토리나 검색 리포지토리를 빠르게 생성할 수도 있습니다.
![](/2022/Days/Images/Day40_Git2.png)
최근 활동은 제가 최근에 만들었거나 기여한 issues와 pull requests입니다.
![](/2022/Days/Images/Day40_Git3.png)
페이지 오른쪽에는 최근 활동 또는 자체 프로젝트를 기반으로 관심을 가질 만한 리포지토리에 대한 추천이 있습니다.
![](/2022/Days/Images/Day40_Git4.png)
솔직히 저는 방금 보고 설명한 홈페이지에 거의 들어가지 않지만, 특정 프로젝트에서 커뮤니티와 좀 더 잘 소통하는 데 이 피드가 정말 유용할 수 있다는 것을 깨달았습니다.
다음으로 GitHub 프로필로 이동하려면 오른쪽 상단 모서리로 이동하면 이미지에 계정을 탐색할 수 있는 드롭다운이 있습니다. 여기에서 프로필에 액세스하려면 "Your Profile"을 선택합니다.
![](/2022/Days/Images/Day40_Git5.png)
다음으로 프로필 페이지가 표시되는데, 기본적으로 설정을 변경하지 않는 한 내가 가진 것을 볼 수 없으며, [vZilla](https://vzilla.co.uk)의 최근 블로그 게시물과 내 [YouTube](https://m.youtube.com/c/MichaelCade1) 채널의 최신 동영상을 보여주는 기능을 추가했습니다.
프로필을 보는 데 많은 시간을 할애하지는 않겠지만, 현재 진행 중인 멋진 프로젝트를 볼 수 있도록 네트워크에 공유하기에 좋은 프로필 페이지입니다.
![](/2022/Days/Images/Day40_Git6.png)
이제 GitHub의 빌딩 블록인 리포지토리를 자세히 살펴볼 수 있습니다. 여기에서 리포지토리를 볼 수 있으며 비공개 리포지토리가 있는 경우 이 긴 목록에 해당 리포지토리도 표시됩니다.
![](/2022/Days/Images/Day40_Git7.png)
리포지토리는 GitHub에서 매우 중요하기 때문에 최근에 많이 사용된 리포지토리를 선택하여 로컬 시스템에서 git으로 "코드"를 편집할 때 이미 사용하고 있는 모든 기능 외에 여기서 사용할 수 있는 핵심 기능 몇 가지를 살펴보겠습니다.
우선, 이전 창에서 90DaysOfDevOps 리포지토리를 선택했더니 다음과 같은 보기가 표시됩니다. 이 보기에서 많은 정보를 볼 수 있으며, 리포지토리에 저장된 파일과 폴더를 보여주는 기본 코드 구조가 있습니다. 맨 아래에는 README.md이 표시됩니다. 페이지 오른쪽에는 리포지토리에 대한 설명과 목적이 있는 정보 섹션이 있습니다. 그리고 그 아래에는 얼마나 많은 사람들이 프로젝트에 참여하고, folk하고, 봤는지 보여주는 많은 정보가 있습니다.
![](/2022/Days/Images/Day40_Git8.png)
조금 더 아래로 스크롤하면 릴리즈가 있는 것을 볼 수 있는데, 이는 챌린지의 Go 언어 부분에서 나온 것입니다. 우리 프로젝트에는 패키지가 없으며 여기에 기여자가 나열되어 있습니다. (오타와 사실 확인에 도움을 주신 커뮤니티에 감사드립니다.) 그런 다음 챌린지의 다른 섹션에서 다시 사용된 언어가 있습니다.
![](/2022/Days/Images/Day40_Git9.png)
페이지 상단에 탭 목록이 표시됩니다. 탭은 다양할 수 있으며 필요한 탭만 표시하도록 수정할 수 있습니다. 이 탭들을 모두 사용하지 않으므로 전체 리포지토리를 깔끔하게 정리하려면 이 탭들을 제거해야 한다는 것을 알 수 있습니다.
먼저 방금 설명한 코드 탭이 있는데, 이 탭은 리포지토리를 탐색할 때 항상 사용할 수 있으므로 섹션 사이를 빠르고 쉽게 이동할 수 있어 매우 유용합니다. 다음으로 issues 탭이 있습니다.
issues를 사용하면 개발이 이루어지는 GitHub에서 작업을 추적할 수 있습니다. 이 특정 리포지토리에는 다이어그램이나 오타를 추가하는 데 중점을 둔 몇 가지 issues가 있지만 중국어 버전의 리포지토리에 대한 필요성 또는 요구 사항을 명시하는 issues도 있음을 알 수 있습니다.
이 리포지토리가 코드 리포지토리라면 유지 관리자에게 우려 사항이나 문제를 제기하기에 좋은 곳이지만, 보고하는 내용을 염두에 두고 가능한 한 자세하게 설명해야 함을 잊지 마세요.
![](/2022/Days/Images/Day40_Git10.png)
다음 탭은 pull requests이며, pull requests를 사용하면 리포지토리의 branch에 push한 변경 사항을 다른 사람에게 알릴 수 있습니다. 누군가 리포지토리를 folk하여 버그 수정이나 기능 개선 등의 변경을 하거나 이 리포지토리의 많은 경우, 오타를 수정했을 수 있습니다.
folk에 대해서는 나중에 다루겠습니다.
![](/2022/Days/Images/Day40_Git11.png)
다음 탭은 꽤 새로운 탭이라고 생각되죠? #90DaysOfDevOps와 같은 프로젝트에서는 이 탭이 콘텐츠 여정을 안내하는 데 도움이 될 뿐만 아니라 커뮤니티가 학습 여정을 걸어가는 데도 도움이 될 수 있다고 생각했습니다. 챌린지의 각 섹션에 대한 토론 그룹을 만들어 사람들이 참여하여 토론할 수 있도록 했습니다.
![](/2022/Days/Images/Day40_Git12.png)
Actions 탭을 사용하면 GitHub 내에서 바로 코드를 빌드, 테스트 및 배포하는 등 다양한 작업을 수행할 수 있습니다. GitHub 작업은 챌린지의 CI/CD 섹션에서 다루겠지만, 여기에서 몇 가지 구성을 설정하여 단계를 자동화할 수 있습니다.
제 기본 GitHub 프로필에서는 GitHub Actions를 사용하여 최신 블로그 게시물과 YouTube 동영상을 가져와 홈 화면에 최신 정보를 표시하고 있습니다.
![](/2022/Days/Images/Day40_Git13.png)
위에서 GitHub가 단순한 소스 코드 리포지토리가 아니라 프로젝트 관리 도구라고 말씀드렸는데, Projects 탭에서는 프로젝트 테이블을 칸반 형식의 보드로 구성하여 issues와 PR을 연결하여 프로젝트에 대한 협업을 개선하고 해당 작업에 대한 가시성을 확보할 수 있습니다.
![](/2022/Days/Images/Day40_Git14.png)
issues가 기능 요청을 기록하기에 좋은 곳인 것 같고 실제로도 그렇지만 Wiki 페이지를 사용하면 프로젝트에 대한 포괄적인 로드맵을 현재 상태와 함께 설명할 수 있고 일반적으로 문제 해결 또는 방법 유형 콘텐츠 등 프로젝트에 대한 문서화를 더 잘 할 수 있습니다.
![](/2022/Days/Images/Day40_Git15.png)
이 프로젝트에는 해당되지 않지만, Security 탭은 기여자가 특정 작업을 처리하는 방법을 알 수 있도록 하기 위한 탭으로, 여기에서 정책을 정의할 수 있을 뿐만 아니라 코드 검사 애드온을 사용하여 코드에 비밀 환경 변수가 포함되어 있지 않은지 확인할 수도 있습니다.
![](/2022/Days/Images/Day40_Git16.png)
Insight 탭은 리포지토리의 활동량부터 commit 및 issues에 이르기까지 리포지토리에 대한 많은 정보를 제공할 뿐만 아니라 리포지토리에 대한 트래픽도 보고해줘서 매우 유용합니다. 왼쪽에 리포지토리의 메트릭에 대해 자세히 살펴볼 수 있는 목록이 표시됩니다.
![](/2022/Days/Images/Day40_Git17.png)
마지막으로 Settings 탭이 있는데, 여기서 리포지토리를 실행하는 방법에 대한 세부 정보를 확인할 수 있으며, 현재 리포지토리의 유일한 관리자는 저이지만, 여기서 다른 사람에게 권한을 부여할 수 있습니다. 여기에서 통합 및 기타 작업을 정의할 수 있습니다.
![](/2022/Days/Images/Day40_Git18.png)
지금까지 GitHub에 대한 간략한 개요를 살펴봤는데, 좀 더 자세히 설명해야 할 부분이 몇 가지 더 있을 것 같습니다. 앞서 언급했듯이 GitHub에는 수백만 개의 리포지토리가 있으며, 대부분 소스 코드가 저장되어 있고 공개 또는 비공개로 액세스할 수 있습니다.
### Folk
내일 세션에서 오픈소스에 대해 더 자세히 다룰 예정이지만, 코드 리포지토리의 가장 큰 장점은 커뮤니티와 협업할 수 있다는 점입니다. 리포지토리에 몇 가지 변경을 하고 싶어서, 버그를 수정하고 싶어서, 또는 원래 코드 관리자가 의도한 사용 사례가 아닌 다른 사용 사례에 사용하기 위해 무언가를 변경하고 싶어서 리포지토리의 복사본을 원하는 시나리오를 생각해 봅시다. 이를 리포지토리 folk라고 합니다. folk는 리포지토리의 복사본입니다. 리포지토리를 folk하면 원래 프로젝트에 영향을 주지 않고 자유롭게 변경 사항을 실험할 수 있습니다.
로그인 후 시작 페이지로 돌아가서 추천 리포지토리 중 하나를 살펴보겠습니다.
![](/2022/Days/Images/Day40_Git19.png)
해당 리포지토리를 클릭하면 방금 살펴본 90DaysOfDevOps 리포지토리와 동일한 모습을 볼 수 있습니다.
![](/2022/Days/Images/Day40_Git20.png)
아래에서 3가지 옵션이 있음을 알 수 있습니다. Watch, Folk, Star가 있습니다.
- Watch - 리포지토리에 어떤 일이 발생하면 업데이트합니다.
- Folk - 리포지토리의 복사본.
- Star - "프로젝트가 멋진 것 같아요"
![](/2022/Days/Images/Day40_Git21.png)
이 리포지토리의 복사본을 작업하고 싶다는 시나리오를 고려할 때, folk 옵션을 사용하겠습니다. 여러 조직의 구성원인 경우, folk가 발생할 위치를 선택해야 하는데, 저는 제 프로필을 선택하겠습니다.
![](/2022/Days/Images/Day40_Git22.png)
이제 우리는 자유롭게 작업하고 필요에 따라 변경할 수 있는 리포지토리 사본을 갖게 되었습니다. 이것이 앞서 잠깐 언급했던 pull requests 프로세스의 시작이지만 내일 더 자세히 다루겠습니다.
![](/2022/Days/Images/Day40_Git23.png)
이 리포지토리와 코드가 웹사이트에 있는 경우, 웹사이트에 가서 편집할 수는 있지만 로컬 시스템에서 좋아하는 색상 테마로 좋아하는 IDE를 사용하는 것과는 다를 것입니다. 로컬 시스템에서 이 리포지토리의 복사본을 얻으려면 리포지토리의 복제를 수행합니다. 이렇게 하면 로컬에서 작업한 다음 변경 사항을 folk된 리포지토리 사본에 다시 push할 수 있습니다.
아래에서 볼 수 있듯이 이 코드의 복사본을 얻는 데는 몇 가지 옵션이 있습니다.
변경 사항을 추적하고 로컬과 GitHub 간에 변경 사항을 push 및 pull할 수 있는 시각적 데스크톱 애플리케이션을 제공하는 GitHub Desktop의 로컬 버전이 있습니다.
이 작은 데모에서는 여기에 표시된 HTTPS URL을 사용하겠습니다.
![](/2022/Days/Images/Day40_Git24.png)
이제 로컬 컴퓨터에서 이 리포지토리를 다운로드할 디렉토리로 이동한 다음 `git clone url`을 실행하겠습니다.
![](/2022/Days/Images/Day40_Git25.png)
이제 VScode로 가져가서 몇 가지 변경을 할 수 있습니다.
![](/2022/Days/Images/Day40_Git26.png)
이제 몇 가지 변경을 해보겠습니다. 모든 링크를 변경하고 다른 것으로 바꾸고 싶습니다.
![](/2022/Days/Images/Day40_Git27.png)
이제 GitHub를 다시 확인하고 해당 리포지토리에서 README.md을 찾으면 파일에 몇 가지 변경한 내용을 볼 수 있을 것입니다.
![](/2022/Days/Images/Day40_Git28.png)
이 단계에서는 이 작업이 완료되고 우리만 새로운 변경 사항을 사용할 것이므로 변경 사항에 만족할 수도 있지만, 버그 변경일 수도 있으며 이 경우, pull requests를 통해 기여하여 원래 리포지토리 관리자에게 변경 사항을 알리고 변경 사항을 수락하는지 확인하고 싶을 것입니다.
아래 강조 표시된 기여 버튼을 사용하여 이 작업을 수행할 수 있습니다. 내일 오픈소스 workflow를 살펴보면서 이에 대해 더 자세히 다루겠습니다.
![](/2022/Days/Images/Day40_Git29.png)
오랜 시간 동안 GitHub를 살펴봤는데 다른 옵션은 없는지 궁금해하시는 분들도 계실 것 같습니다!
글쎄요, 그런 옵션도 있고 그중 일부에 대한 기본 사항을 다루는 몇 가지 리소스를 찾아보려고 합니다. 앞으로 GitLab과 BitBucket을 만나게 될 텐데, 이 두 서비스는 git 기반 서비스이긴 하지만 차이점이 있습니다.
또한 호스팅 옵션도 있습니다. 호스팅 버전인 GitLab과 무료 호스팅 GitHub도 있을 거라고 생각하지 않으신가요?
## 자료
- [Learn GitLab in 3 Hours | GitLab Complete Tutorial For Beginners](https://www.youtube.com/watch?v=8aV5AxJrHDg)
- [BitBucket Tutorials Playlist](https://www.youtube.com/watch?v=OMLh-5O6Ub8&list=PLaD4FvsFdarSyyGl3ooAm-ZyAllgw_AM5)
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
[Day 41](day41.md)에서 봐요!

127
2022/ko/Days/day41.md Normal file
View File

@ -0,0 +1,127 @@
---
title: '#90DaysOfDevOps - The Open Source Workflow - Day 41'
published: false
description: 90DaysOfDevOps - The Open Source Workflow
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048806
---
## 오픈 소스 workflow
지난 7회에 걸친 Git 섹션을 통해 Git이 무엇인지, 그리고 GitHub와 같은 Git 기반 서비스가 어떻게 소스 코드 저장소를 제공할 뿐만 아니라 더 많은 커뮤니티가 함께 코드와 프로젝트를 협업할 수 있는 방법을 제공하는지 더 잘 이해하셨기를 바랍니다.
GitHub의 기본 사항을 살펴볼 때 임의의 프로젝트를 fork하고 로컬 리포지토리를 변경하는 과정을 거쳤습니다. 여기서는 한 단계 더 나아가 오픈소스 프로젝트에 기여하고자 합니다. 기여는 반드시 버그 수정이나 코딩 기능일 필요는 없으며 문서화일 수도 있다는 점을 기억하세요. 작은 도움이라도 모두 의미 있으며, 지금까지 다룬 몇 가지 git 기능을 직접 사용해 볼 수 있습니다.
## 프로젝트 fork하기
가장 먼저 해야 할 일은 우리가 기여할 수 있는 프로젝트를 찾는 것입니다. 저는 최근 [Kanister 프로젝트](https://github.com/kanisterio/kanister)에서 발표를 하고 있는데, 현재 유튜브에 올라와 있는 프레젠테이션을 프로젝트의 메인 README.md 파일에 공유하고자 합니다.
우선 프로젝트를 fork해야 합니다. 그 과정을 살펴보겠습니다. 위에서 공유한 링크로 이동하여 리포지토리를 fork하겠습니다.
![](/2022/Days/Images/Day41_Git1.png)
이제 전체 리포지토리의 복사본을 얻었습니다.
![](/2022/Days/Images/Day41_Git2.png)
참고로 README.md 파일에 나열된 원본 프레젠테이션은 이 두 개뿐이므로 프로세스를 통해 이 문제를 해결해야 합니다.
![](/2022/Days/Images/Day41_Git3.png)
## 로컬 머신에 복제
이제 fork를 로컬로 가져와서 파일에 대한 편집을 시작할 수 있습니다. 리포지토리의 코드 버튼을 사용하여 URL을 가져온 다음 리포지토리를 배치하려는 디렉토리에 `git clone url`을 사용하면 됩니다.
![](/2022/Days/Images/Day41_Git4.png)
## 변경하기
프로젝트가 로컬에 있으므로 VSCode 또는 원하는 IDE 또는 텍스트 편집기를 열어 수정 사항을 추가할 수 있습니다.
![](/2022/Days/Images/Day41_Git5.png)
READEME.md 파일은 마크다운 언어로 작성되었으며, 다른 사람의 프로젝트를 수정하고 있으므로 기존 프로젝트 형식을 따라 콘텐츠를 추가하겠습니다.
![](/2022/Days/Images/Day41_Git6.png)
## 변경 사항 테스트하기
코드 변경 후에도 애플리케이션이 계속 작동하는지 확인하려면 변경 사항을 테스트하는 것이 가장 좋은 방법이며, 문서 형식이 올바르게 지정되어 있는지 확인해야 합니다.
VSCode에서는 많은 플러그인을 추가할 수 있는데, 그중 하나가 마크다운 페이지를 미리 볼 수 있는 기능입니다.
![](/2022/Days/Images/Day41_Git7.png)
## 변경 사항을 fork된 리포지토리로 push하기
변경 사항을 Kanister 리포지토리로 직접 push할 수 있는 권한이 없으므로 이 경로를 사용해야 합니다. 이제 변경 사항에 만족하므로 이제 잘 알려진 몇 가지 git 명령을 실행할 수 있습니다.
![](/2022/Days/Images/Day41_Git8.png)
이제 GitHub로 돌아가서 변경 사항을 다시 한번 확인한 다음 마스터 프로젝트에 다시 기여합니다.
좋아 보이네요.
![](/2022/Days/Images/Day41_Git9.png)
이제 Kanister의 fork된 리포지토리 상단으로 돌아가서 kanisterio:master branch보다 commit이 1개 앞선 것을 볼 수 있습니다.
![](/2022/Days/Images/Day41_Git10.png)
다음으로 위에 강조 표시된 기여 버튼을 누릅니다. "Open Pull Request" 옵션이 표시됩니다.
![](/2022/Days/Images/Day41_Git11.png)
## Open Pull Request
다음 이미지에서 꽤 많은 일이 진행되고 있습니다. 왼쪽 위에는 이제 원본 또는 마스터 리포지토리에 있는 것을 볼 수 있습니다. 그리고 비교 대상인 원본 마스터 리포지토리와 fork된 리포지토리를 볼 수 있습니다. 이제 Create Pull Request 버튼이 있는데, 곧 다시 설명하겠습니다. 단일 commit이 있지만 변경 사항이 더 많으면 여기에 여러 개의 commit이 있을 수 있습니다. 그러면 README.md 파일에 변경 사항이 있습니다.
![](/2022/Days/Images/Day41_Git12.png)
위의 변경 사항을 검토했으며 녹색 버튼을 눌러 pull requests를 생성할 준비가 되었습니다.
그런 다음 프로젝트 관리자가 리포지토리에 pull requests 기능을 어떻게 설정했는지에 따라 관리자가 보고자 하는 내용을 알려주는 템플릿이 있을 수도 있고 없을 수도 있습니다.
여기서도 자신이 한 일에 대해 명확하고 간결하면서도 충분히 상세하게 의미 있는 설명을 작성해야 합니다. 간단한 변경 개요를 작성하고 문서화를 체크한 것을 볼 수 있습니다.
![](/2022/Days/Images/Day41_Git13.png)
## Create Pull Request
이제 pull requests를 만들 준비가 되었습니다. 페이지 상단의 "Create Pull Request"를 누르면 pull requests에 대한 요약이 표시됩니다.
![](/2022/Days/Images/Day41_Git14.png)
아래로 스크롤하면 일부 자동화가 진행 중인 것을 볼 수 있는데, 이 경우 검토가 필요하며 몇 가지 확인이 진행 중입니다. Travis CI가 진행 중이고 빌드가 시작되었음을 알 수 있으며, 업데이트를 확인하여 merge하기 전에 추가한 내용이 손상되지 않았는지 확인합니다.
![](/2022/Days/Images/Day41_Git15.png)
위 스크린샷에서 보이는 빨간색은 약간 위협적으로 보일 수 있으며, 마치 실수를 저질렀다고 생각할 수 있습니다. 걱정하지 마세요, 아무것도 망가뜨린 것이 없습니다. 여기서 가장 중요한 팁은 이 과정이 당신과 프로젝트 관리자를 돕기 위한 것이라는 것입니다. 혹시 실수를 저질렀다면 제 경험에 따르면 관리자가 연락하여 다음에 무엇을 해야 할지 조언해줄 것입니다.
이 pull requests는 이제 모든 사람이 볼 수 있도록 공개되었습니다 [added Kanister presentation/resource #1237](https://github.com/kanisterio/kanister/pull/1237).
merge 및 pull requests가 수락되기 전에 이 글을 게시하려고 합니다. 따라서 여전히 관심을 가지고 있는 사람들에게 성공적인 PR의 사진을 추가할 수 있는 작은 보상을 제공할 수 있을 것입니다.
1. 이 저장소를 귀하의 GitHub 계정으로 folk하세요.
2. 사진과 함께 텍스트를 추가해 주세요.
3. 변경 사항을 folk된 저장소에 push하세요.
4. 제가 볼 수 있고 승인할 수 있는 PR을 생성하세요.
5. 일종의 보상을 생각해 볼게요.
이것으로 Git과 GitHub에 대해 살펴본 내용을 마무리하고, 다음에는 컨테이너를 어떻게, 왜 사용하는지에 대한 큰 그림부터 시작하여 가상화에 대해 살펴보고 여기까지 오게 된 과정을 살펴볼 것입니다.
## 자료
- [Learn GitLab in 3 Hours | GitLab Complete Tutorial For Beginners](https://www.youtube.com/watch?v=8aV5AxJrHDg)
- [BitBucket Tutorials Playlist](https://www.youtube.com/watch?v=OMLh-5O6Ub8&list=PLaD4FvsFdarSyyGl3ooAm-ZyAllgw_AM5)
- [What is Version Control?](https://www.youtube.com/watch?v=Yc8sCSeMhi4)
- [Types of Version Control System](https://www.youtube.com/watch?v=kr62e_n6QuQ)
- [Git Tutorial for Beginners](https://www.youtube.com/watch?v=8JJ101D3knE&t=52s)
- [Git for Professionals Tutorial](https://www.youtube.com/watch?v=Uszj_k0DGsg)
- [Git and GitHub for Beginners - Crash Course](https://www.youtube.com/watch?v=RGOj5yH7evk&t=8s)
- [Complete Git and GitHub Tutorial](https://www.youtube.com/watch?v=apGV9Kg7ics)
- [Git cheatsheet](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet)
[Day 42](day42.md)에서 봐요!

136
2022/ko/Days/day42.md Normal file
View File

@ -0,0 +1,136 @@
---
title: '#90DaysOfDevOps - The Big Picture: Containers - Day 42'
published: false
description: 90DaysOfDevOps - The Big Picture Containers
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048826
---
## 큰 그림: 컨테이너
이제 다음 섹션을 시작하겠습니다. 이번 섹션에서는 컨테이너, 특히 컨테이너에 대해 더 많이 이해하기 위해 몇 가지 핵심 영역에 대해 살펴보는 Docker를 중점적으로 다룰 것입니다.
또한 이 섹션뿐만 아니라 챌린지 후반부의 다음 섹션에서도 사용할 수 있는 컨테이너를 만들기 위한 실습도 해보려고 합니다.
언제나 그렇듯이 이번 첫 번째 포스팅에서는 우리가 어떻게 여기까지 왔는지, 그리고 이 모든 것이 무엇을 의미하는지에 대한 큰 그림에 초점을 맞출 것입니다.
플랫폼 및 애플리케이션 개발의 역사 가상화 및 컨테이너화에 대해 이야기하고 싶습니다.
### 왜 애플리케이션을 실행하는 다른 방법일까요?
가장 먼저 살펴봐야 할 것은 소프트웨어나 애플리케이션을 실행하는 다른 방법이 필요한 이유입니다. 다양한 형태로 애플리케이션을 실행할 수 있기 때문입니다. 물리적 하드웨어에 운영 체제와 단일 애플리케이션이 배포된 애플리케이션을 볼 수도 있고, 가상 머신 또는 클라우드 기반 IaaS 인스턴스가 애플리케이션을 실행한 다음 다시 가상 머신의 데이터베이스에 통합되거나 퍼블릭 클라우드의 PaaS 제품으로 통합되는 것을 볼 수도 있습니다. 또는 애플리케이션이 컨테이너에서 실행되는 것을 볼 수도 있습니다.
위의 옵션 중 어느 것도 틀린 것도, 옳은 것도 아니지만 각 옵션이 존재해야 하는 이유가 있으며, 저는 이 중 어느 것도 사라지지 않을 것이라고 굳게 믿습니다. 컨테이너와 가상 머신을 비교하는 콘텐츠를 많이 봤는데, 이는 사과와 배를 비교하는 것과 같이 둘 다 과일(애플리케이션을 실행하는 방법)이지만 같은 과일이 아니기 때문에 논쟁을 해서는 안 됩니다.
또한 애플리케이션을 개발 중이라면 나중에 이러한 영역 중 일부를 다루겠지만 효율성, 속도 및 크기에 관한 것이므로 컨테이너에 기대야 한다고 말씀드리고 싶습니다. 하지만 여기에는 대가가 따르는데, 컨테이너에 대해 전혀 모른다면 그 이유를 이해하고 그 사고방식에 익숙해지려면 학습 곡선을 밟아야 할 것입니다. 애플리케이션을 특정 방식으로 개발했거나 그린필드 환경이 아니라면 컨테이너를 고려하기 전에 해결해야 할 문제가 더 많을 수 있습니다.
특정 소프트웨어를 다운로드할 때 사용할 수 있는 운영 체제가 다양하기 때문에 선택의 폭이 넓어집니다. 그리고 애플리케이션을 설치하기 위해 수행해야 하는 작업에 대한 구체적인 지침도 있습니다.
![](/2022/Days/Images/Day42_Containers1.png)
최근에는 예전에는 전체 서버 OS, 가상 머신, 물리적 또는 클라우드 인스턴스가 필요했던 애플리케이션이 이제 컨테이너 기반 버전의 소프트웨어를 출시하는 경우가 점점 더 많아지고 있습니다. 이는 애플리케이션 개발자에게만 초점을 맞추는 것이 아니라 모든 사람에게 컨테이너와 쿠버네티스의 세계를 열어준다는 점에서 흥미롭습니다.
![](/2022/Days/Images/Day42_Containers2.png)
앞서 말씀드렸듯이, 저는 컨테이너가 정답이라고 주장하지는 않겠습니다. 하지만 애플리케이션을 배포할 때 고려해야 할 또 다른 옵션이 컨테이너라는 점을 말씀드리고 싶습니다.
![](/2022/Days/Images/Day42_Containers4.png)
최근 10년 동안, 특히 지난 5년간 컨테이너 기술이 인기를 얻은 이유는 무엇일까요? 이미 수십 년 동안 컨테이너 기술이 존재해 왔습니다. 이 문제는 컨테이너와 이미지라는 용어를 두고, 소프트웨어 배포 방식의 도전 과제로 귀결됩니다. 만약 단순히 컨테이너 기술만을 가지고 있다면, 여전히 소프트웨어 관리에 있어서 겪었던 여러 문제들이 계속 발생할 것입니다.
docker를 도구로 생각하면, docker가 성공할 수 있었던 이유는 쉽게 찾고 사용할 수 있는 이미지 에코시스템 때문입니다. 시스템에 설치하고 실행하는 것이 간단합니다. 그중 가장 중요한 부분은 소프트웨어에서 직면하는 다양한 과제에 대한 전체 공간의 일관성입니다. MongoDB든 nodeJS든 상관없이 두 가지를 모두 실행하는 프로세스는 동일합니다. 중단하는 과정도 마찬가지입니다. 이러한 모든 문제는 여전히 존재하겠지만, 좋은 점은 좋은 컨테이너와 이미지 기술을 함께 사용하면 이러한 다양한 문제를 모두 해결하는 데 도움이 되는 단일 도구 세트를 갖게 된다는 것입니다. 이러한 문제 중 일부는 다음과 같습니다:
- 먼저 인터넷에서 소프트웨어를 찾아야 합니다.
- 그런 다음, 이 소프트웨어를 다운로드해야 합니다.
- 소스를 신뢰할 수 있는가?
- 라이선스가 필요한가요? 어떤 라이선스가 필요한가요?
- 다른 플랫폼과 호환되는가?
- 패키지는 무엇인가요? 바이너리인가요? 실행 파일인가요? 패키지 관리자?
- 소프트웨어를 어떻게 구성하나요?
- 종속성은 무엇인가요? 전체 다운로드에 포함되어 있나요, 아니면 추가로 필요한가요?
- 종속성의 종속성?
- 애플리케이션을 어떻게 시작하나요?
- 애플리케이션을 어떻게 중지하나요?
- 자동으로 다시 시작되나요?
- 부팅 시 시작되나요?
- 리소스 충돌?
- 충돌하는 라이브러리?
- 포트 충돌
- 소프트웨어 보안?
- 소프트웨어 업데이트?
- 소프트웨어를 제거하려면 어떻게 해야 하나요?
위의 내용을 소프트웨어의 복잡성 중 컨테이너와 이미지가 도움이 되는 세 가지 영역으로 나눌 수 있습니다.
| Distribution | Installation | Operation |
| ------------ | ------------- | ------------------ |
| Find | Install | Start |
| Download | Configuration | Security |
| License | Uninstall | Ports |
| Package | Dependencies | Resource Conflicts |
| Trust | Platform | Auto-Restart |
| Find | Libraries | Updates |
컨테이너와 이미지는 다른 소프트웨어와 애플리케이션에서 겪을 수 있는 이러한 문제 중 일부를 제거하는 데 도움이 될 것입니다.
높은 수준에서 설치와 운영을 동일한 목록으로 옮길 수 있으며, 이미지는 배포 관점에서, 컨테이너는 설치와 운영에 도움이 될 것입니다.
좋아요, 멋지고 흥미진진하게 들리겠지만 컨테이너가 무엇인지 이해할 필요가 있고 이제 이미지를 언급했으니 다음에는 그 부분을 다루겠습니다.
소프트웨어 개발용 컨테이너에 대해 이야기할 때 많이 보셨을 또 다른 것은 선적 컨테이너와 함께 사용되는 비유입니다. 선적 컨테이너는 대형 선박을 사용하여 바다를 가로질러 다양한 물품을 운송하는 데 사용됩니다.
![](/2022/Days/Images/Day42_Containers5.png)
이것이 컨테이너라는 주제와 어떤 관련이 있을까요? 소프트웨어 개발자가 작성하는 코드를 생각해 보세요. 특정 코드를 한 컴퓨터에서 다른 컴퓨터로 어떻게 전송할 수 있을까요?
앞서 소프트웨어 배포, 설치 및 운영에 대해 다룬 내용을 이제 환경 비주얼로 구축하기 시작하면 다음과 같습니다. 여러 애플리케이션을 실행할 하드웨어와 운영 체제가 있습니다. 예를 들어 nodejs에는 특정 종속성이 있고 특정 라이브러리가 필요합니다. 그런 다음 MySQL을 설치하려면 필요한 라이브러리와 종속성이 필요합니다. 각 소프트웨어 애플리케이션에는 해당 라이브러리와 종속성이 있습니다. 운이 좋아서 특정 라이브러리와 종속성이 충돌하여 문제를 일으키는 애플리케이션 간에 충돌이 발생하지 않을 수도 있지만, 애플리케이션이 많을수록 충돌의 가능성이나 위험은 높아집니다. 그러나 소프트웨어 애플리케이션을 모두 수정한 후 업데이트하면 이러한 충돌이 발생할 수도 있습니다.
![](/2022/Days/Images/Day42_Containers6.png)
컨테이너는 이 문제를 해결하는 데 도움이 될 수 있습니다. 컨테이너는 애플리케이션을 **구축**하고, 애플리케이션을 **배송**하고, 이러한 애플리케이션을 독립적으로 쉽게 **배포**하고 **확장**할 수 있도록 도와줍니다. 아키텍처를 살펴보면 하드웨어와 운영체제가 있고 그 위에 나중에 다룰 docker(docker)와 같은 컨테이너 엔진이 있습니다. 컨테이너 엔진 소프트웨어는 라이브러리와 종속성을 함께 패키징하는 컨테이너를 생성하는 데 도움이 되므로 라이브러리와 종속성이 컨테이너 패키지의 일부로 제공되므로 라이브러리와 종속성에 대한 걱정 없이 이 컨테이너를 한 시스템에서 다른 시스템으로 원활하게 이동할 수 있으므로 이 컨테이너는 애플리케이션이 실행하는 데 필요한 기본 종속성에 대한 걱정 없이 시스템 간에 이동이 가능합니다.
애플리케이션이 실행하는 데 필요한 모든 것이 컨테이너로 패키징되어 있기 때문에
컨테이너로 패키징되어 있기 때문입니다.
![](/2022/Days/Images/Day42_Containers7.png)
### 컨테이너의 장점
- 컨테이너는 컨테이너 내의 모든 종속성을 패키징하고 격리할 수 있습니다.
- 컨테이너를 쉽게 관리할 수 있습니다.
- 한 시스템에서 다른 시스템으로 이동할 수 있습니다.
- 컨테이너는 소프트웨어를 패키징하는 데 도움이 되며 중복 작업 없이 쉽게 배포할 수 있습니다.
- 컨테이너는 쉽게 확장할 수 있습니다.
컨테이너를 사용하면 독립적인 컨테이너를 확장하고 로드 밸런서를 사용할 수 있습니다.
또는 트래픽을 분할하는 데 도움이 되는 서비스를 사용하여 애플리케이션을 수평적으로 확장할 수 있습니다. 컨테이너는 애플리케이션 관리 방식에 있어 많은 유연성과 편의성을 제공합니다.
### 컨테이너란 무엇인가요?
컴퓨터에서 애플리케이션을 실행할 때 이 글을 읽는 데 사용하고 있는 웹 브라우저나 VScode가 컨테이너일 수 있습니다. 해당 애플리케이션은 프로세스로 실행되거나 프로세스라고 하는 것으로 알려져 있습니다. 노트북이나 시스템에서는 여러 개의 애플리케이션 또는 프로세스를 실행하는 경향이 있습니다. 새 애플리케이션을 열거나 애플리케이션 아이콘을 클릭하면 이 애플리케이션은 우리가 실행하려는 애플리케이션이며, 때로는 이 애플리케이션이 백그라운드에서 실행하려는 서비스일 수도 있으며, 운영 체제는 백그라운드에서 실행되는 서비스로 가득 차 있어 시스템에서 얻을 수 있는 사용자 경험을 제공합니다.
이 애플리케이션 아이콘은 파일 시스템 어딘가에 있는 실행 파일에 대한 링크를 나타내며, 운영 체제는 해당 실행 파일을 메모리에 로드합니다. 흥미롭게도 프로세스에 대해 이야기할 때 이 실행 파일을 이미지라고 부르기도 합니다.
컨테이너는 프로세스로, 컨테이너는 코드와 모든 종속성을 패키징하여 애플리케이션이 한 컴퓨팅 환경에서 다른 컴퓨팅 환경으로 빠르고 안정적으로 실행되도록 하는 소프트웨어의 표준 단위입니다.
컨테이너화된 소프트웨어는 인프라에 관계없이 항상 동일하게 실행됩니다. 컨테이너는 소프트웨어를 환경으로부터 분리하여 개발 환경과 스테이징 환경 간의 차이에도 불구하고 소프트웨어가 균일하게 작동하도록 보장합니다.
지난 섹션에서 컨테이너와 이미지의 결합이 어떻게 그리고 왜 우리 에코시스템에서 컨테이너가 인기를 얻게 되었는지에 관해 이미지를 언급했습니다.
### 이미지란 무엇인가요?
컨테이너 이미지는 경량의 독립형 실행형 소프트웨어 패키지입니다.
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [Introduction to Container By Red Hat](https://www.redhat.com/en/topics/containers)
[Day 43](day43.md)에서 봐요!

88
2022/ko/Days/day43.md Normal file
View File

@ -0,0 +1,88 @@
---
title: '#90DaysOfDevOps - What is Docker & Getting installed - Day 43'
published: false
description: 90DaysOfDevOps - What is Docker & Getting installed
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048739
---
## Docker를 알아보고 설치하기
이전 포스팅에서 docker에 대해 한 번쯤은 언급했는데, 그 이유는 docker가 컨테이너가 오래전부터 사용되어 왔음에도 불구하고 대중화될 수 있었던 혁신적인 기술이기 때문입니다.
여기서는 docker를 사용하고 설명할 예정이지만, 벤더 종속의 위험을 피하면서 혁신을 장려하는 산업 표준 조직인 [Open Container Initiative(OCI)](https://www.opencontainers.org/)에 대해서도 언급해야 합니다. OCI 덕분에 컨테이너 툴체인을 선택할 때 Docker, [CRI-O](https://cri-o.io/), [Podman](http://podman.io/), [LXC](https://linuxcontainers.org/) 등을 선택할 수 있게 되었습니다.
docker는 컨테이너를 빌드, 실행 및 관리하기 위한 소프트웨어 프레임워크입니다. "docker"라는 용어는 도구(명령어 및 데몬) 또는 Dockerfile 파일 형식을 지칭할 수 있습니다.
여기서는 (교육 및 학습용으로) 무료인 Docker Personal을 사용하겠습니다. 여기에는 컨테이너와 도구에 대한 지식의 기초를 다지기 위해 다루어야 할 모든 필수 사항이 포함됩니다.
우리가 사용할 몇 가지 "docker" 도구와 그 용도를 세분화해 볼 가치가 있을 것입니다. docker라는 용어는 개발자와 관리자가 애플리케이션을 개발, 배포 및 실행하기 위한 플랫폼인 docker 프로젝트 전반을 지칭할 수 있습니다. 또한 이미지와 컨테이너를 관리하는 호스트에서 실행되는 docker 데몬 프로세스를 지칭할 수도 있으며, Docker Engine이라고도 합니다.
### Docker Engine
Docker Engine은 애플리케이션을 빌드하고 컨테이너화하기 위한 오픈소스 컨테이너화 기술입니다. Docker Engine은 클라이언트-서버 애플리케이션으로 작동합니다:
- 장기 실행 데몬 프로세스인 dockerd가 있는 서버.
- API는 프로그램이 Docker 데몬과 대화하고 지시하는 데 사용할 수 있는 인터페이스를 지정합니다.
- 커맨드라인 인터페이스(CLI) 클라이언트 docker입니다.
위의 내용은 공식 docker 문서와 특정 [Docker Engine 개요](https://docs.docker.com/engine/)에서 발췌한 것입니다.
### Docker Desktop
저희는 Windows와 macOS 시스템 모두를 위한 Docker Desktop을 제공합니다. 설치하기 쉬운 경량 docker 개발 환경입니다. 호스트 운영 체제의 가상화 기능을 활용하는 네이티브 OS 애플리케이션입니다.
Windows 또는 macOS에서 docker화된 애플리케이션을 빌드, 디버그, 테스트, 패키징 및 출시하려는 경우 가장 적합한 솔루션입니다.
Windows에서는 WSL2와 Microsoft Hyper-V도 활용할 수 있습니다. WSL2의 몇 가지 이점은 차근차근 살펴보도록 하겠습니다.
호스트 운영 체제의 하이퍼바이저 기능과 통합되어 있기 때문에 docker는 리눅스 운영 체제에서 컨테이너를 실행할 수 있는 기능을 제공합니다.
### Docker Compose
Docker Compose는 여러 컨테이너에서 더 복잡한 앱을 실행할 수 있는 도구입니다. 단일 파일과 명령을 사용하여 애플리케이션을 스핀업할 수 있다는 이점이 있습니다.
### DockerHub
docker와 그 구성 요소로 작업하기 위한 중앙 집중식 리소스입니다. 가장 일반적으로는 docker 이미지를 호스팅하는 레지스트리로 알려져 있습니다. 그러나 여기에는 부분적으로 자동화와 함께 사용하거나 보안 검사뿐만 아니라 GitHub에 통합할 수 있는 많은 추가 서비스가 있습니다.
### Dockerfile
Dockerfile은 일반적으로 docker 이미지를 빌드하기 위해 수동으로 실행하는 명령이 포함된 텍스트 파일입니다. docker는 Dockerfile에 있는 지침을 읽어 이미지를 자동으로 빌드할 수 있습니다.
## Docker Desktop 설치
[Docker 문서](https://docs.docker.com/engine/install/)는 매우 훌륭하며, 이제 막 docker에 입문하는 분이라면 꼭 한 번 읽어보시기 바랍니다. 여기서는 WSL2가 설치된 Windows에서 Docker Desktop을 사용하겠습니다. 여기서 사용하는 머신에 이미 설치를 완료했습니다.
![](/2022/Days/Images/Day43_Containers1.png)
설치를 진행하기 전에 시스템 요구 사항을 참고하시기 바라며, [윈도우에 Docker Desktop 설치하기](https://docs.docker.com/desktop/windows/install/)를 참고하시고, M1 기반 CPU 아키텍처를 포함한 맥OS를 사용하시는 경우 [맥OS에 docker Desktop 설치하기](https://docs.docker.com/desktop/mac/install/)도 참고하시면 됩니다.
다른 윈도우 머신에서 윈도우용 docker Desktop 설치를 실행하고 그 과정을 아래에 기록해 보겠습니다.
### Windows
- 장치의 운영 체제로 Windows를 선택합니다.
<img src = ../../Days/Images/Day43_operatingSystem.png>
- 인스톨러를 저장할 폴더로 이동하여 저장합니다.
- 인스톨러를 실행하고 몇 초간 기다린 후 WSL에 대한 액세스 권한을 부여합니다.
<img src = ../../Days/Images/Day43_EnableWSL.png>
- 확인을 클릭하면 설치가 시작됩니다.
<img src = ../../Days/Images/Day43_install.png>
- Docker Desktop이 장치에 성공적으로 설치되었습니다. 이제 터미널에서 "docker" 명령을 실행하여 설치가 성공적으로 완료되었는지 확인할 수 있습니다.
<img src = ../../Days/Images/Day43_check.png>
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
[Day 44](day44.md)에서 봐요!

141
2022/ko/Days/day44.md Normal file
View File

@ -0,0 +1,141 @@
---
title: '#90DaysOfDevOps - Docker Images & Hands-On with Docker Desktop - Day 44'
published: false
description: 90DaysOfDevOps - Docker Images & Hands-On with Docker Desktop
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048708
---
## Docker 이미지 및 Docker Desktop 실습하기
이제 시스템에 Docker Desktop을 설치했습니다. (Linux를 실행하는 경우 여전히 옵션은 있지만 GUI는 없지만 Docker는 Linux에서 작동합니다.)[우분투에 Docker Engine 설치](https://docs.docker.com/engine/install/ubuntu/) (다른 배포판도 사용할 수 있습니다.)
이 글에서는 몇 가지 이미지를 우리 환경에 배포하는 작업을 시작하겠습니다. Docker 이미지에 대한 요약 - Docker 이미지는 Docker 컨테이너에서 코드를 실행하는 데 사용되는 파일입니다. Docker 이미지는 템플릿처럼 Docker 컨테이너를 빌드하기 위한 일련의 지침 역할을 합니다. 또한 Docker 이미지는 Docker를 사용할 때 시작점 역할을 하기도 합니다.
지금 바로 [DockerHub](https://hub.docker.com/)에서 계정을 생성하세요.
![](/2022/Days/Images/Day44_Containers1.png)
DockerHub는 Docker 및 그 구성 요소로 작업하기 위한 중앙 집중식 리소스입니다. 가장 일반적으로는 docker 이미지를 호스팅하는 레지스트리로 알려져 있습니다. 그러나 여기에는 부분적으로 자동화와 함께 사용하거나 보안 검사뿐만 아니라 GitHub에 통합할 수 있는 많은 추가 서비스가 있습니다.
로그인한 후 아래로 스크롤하면 컨테이너 이미지 목록이 표시되며, MySQL, hello-world 등의 데이터베이스 이미지가 표시될 수 있습니다. 데이터베이스 이미지가 필요하거나 직접 만들 필요가 없는 경우 공식 이미지를 사용하는 것이 가장 좋습니다.
![](/2022/Days/Images/Day44_Containers2.png)
사용 가능한 이미지 보기를 더 자세히 살펴보고 카테고리, 운영 체제 및 아키텍처에 따라 검색할 수 있습니다. 아래에서 강조 표시한 것은 공식 이미지로, 이 컨테이너 이미지의 출처에 대해 안심할 수 있습니다.
![](/2022/Days/Images/Day44_Containers3.png)
특정 이미지를 검색할 수도 있습니다. 예를 들어 워드프레스가 좋은 기본 이미지가 될 수 있으므로 상단에 있는 이미지를 검색하여 워드프레스와 관련된 모든 컨테이너 이미지를 찾을 수 있습니다. 아래는 확인된 퍼블리셔에 대한 공지사항입니다.
- 공식 이미지 - Docker 공식 이미지는 엄선된 Docker 오픈 소스 및 "drop-in" 솔루션 리포지토리 집합입니다.
- 검증된 퍼블리셔 - 검증된 퍼블리셔의 고품질 Docker 콘텐츠입니다. 이러한 제품은 상업적 주체가 직접 게시하고 유지 관리합니다.
![](/2022/Days/Images/Day44_Containers4.png)
### Docker Desktop 살펴보기
저희 시스템에는 Docker Desktop이 설치되어 있으며, 이 파일을 열면 이미 설치되어 있지 않다면 아래 이미지와 비슷한 것을 볼 수 있을 것입니다. 보시다시피 컨테이너가 실행되고 있지 않고 Docker Engine이 실행되고 있습니다.
![](/2022/Days/Images/Day44_Containers5.png)
새로 설치한 것이 아니기 때문에 이미 다운로드하여 시스템에 사용할 수 있는 이미지가 몇 개 있습니다. 여기에는 아무것도 표시되지 않을 것입니다.
![](/2022/Days/Images/Day44_Containers6.png)
원격 리포지토리 아래에서 DockerHub에 저장한 컨테이너 이미지를 찾을 수 있습니다. 아래에서 볼 수 있듯이 이미지가 없습니다.
![](/2022/Days/Images/Day44_Containers7.png)
DockerHub 사이트에서도 리포지토리가 없음을 확인할 수 있습니다.
![](/2022/Days/Images/Day44_Containers8.png)
다음으로 Volumes 탭이 있는데, 지속성이 필요한 컨테이너가 있는 경우 여기에서 로컬 파일 시스템이나 공유 파일 시스템에 이러한 Volumes를 추가할 수 있습니다.
![](/2022/Days/Images/Day44_Containers9.png)
이 글을 쓰는 시점에 Environments 탭도 있는데, 이 탭은 다른 git branch 사이를 이동하지 않고 팀과 협업하는 데 도움이 될 것입니다. 여기서는 다루지 않겠습니다.
![](/2022/Days/Images/Day44_Containers10.png)
첫 번째 탭으로 돌아가면 시작 컨테이너를 실행할 수 있는 명령이 있음을 알 수 있습니다. 터미널에서 `docker run -d -p 80:80 docker/getting-started`를 실행해 보겠습니다.
![](/2022/Days/Images/Day44_Containers11.png)
Docker Desktop 창을 다시 확인하면 컨테이너가 실행 중인 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day44_Containers12.png)
WSL2를 사용하고 있다는 것을 눈치채셨을 텐데요, 이를 사용하려면 설정에서 이 기능이 활성화되어 있는지 확인해야 합니다.
![](/2022/Days/Images/Day44_Containers13.png)
이제 Images 탭으로 다시 이동하여 확인하면 이제 사용 중인 이미지인 docker/getting-started를 볼 수 있습니다.
![](/2022/Days/Images/Day44_Containers14.png)
Containers/Apps 탭으로 돌아가서 실행 중인 컨테이너를 클릭합니다. 기본적으로 로그가 표시되고 상단에 선택할 수 있는 몇 가지 옵션이 있는데, 이 컨테이너에서 실행 중인 웹 페이지가 될 것이 확실하므로 브라우저에서 열기를 선택하겠습니다.
![](/2022/Days/Images/Day44_Containers15.png)
위의 버튼을 누르면 로컬호스트로 연결되는 웹 페이지가 열리고 아래와 비슷한 내용이 표시됩니다.
이 컨테이너에는 컨테이너와 이미지에 대한 자세한 내용도 있습니다.
![](/2022/Days/Images/Day44_Containers16.png)
이제 첫 번째 컨테이너를 실행했습니다. 아직은 쉽습니다. 컨테이너 이미지 중 하나를 DockerHub에서 가져오고 싶다면 어떻게 해야 할까요? 아마도 우리가 사용할 수 있는 `hello world` docker 컨테이너가 있을 것입니다.
시작 컨테이너는 리소스를 많이 차지하기 때문이 아니라 몇 가지 단계를 더 진행하면서 깔끔하게 정리하기 위해 중단했습니다.
터미널로 돌아와서 `docker run hello-world`를 실행하고 어떤 일이 일어나는지 살펴봅시다.
로컬에 이미지가 없었기 때문에 이미지를 끌어내렸고, 컨테이너 이미지에 시작 및 실행에 대한 몇 가지 정보와 참조 지점에 대한 링크가 포함된 메시지가 표시되는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day44_Containers17.png)
그러나 이제 Docker Desktop을 살펴보면 실행 중인 컨테이너는 없지만, hello-world 메시지를 사용한 종료된 컨테이너, 즉 시작되어 메시지를 전달한 후 종료된 컨테이너는 있습니다.
![](/2022/Days/Images/Day44_Containers18.png)
마지막으로 Images 탭을 확인해보면 시스템에 로컬로 새로운 hello-world 이미지가 있는 것을 확인할 수 있습니다. 즉, 터미널에서 `docker run hello-world` 명령을 다시 실행해도 버전이 변경되지 않는 한 아무것도 가져올 필요가 없습니다.
![](/2022/Days/Images/Day44_Containers19.png)
'hello-world' 컨테이너에서 온 메시지로 인해 조금 더 야심찬 도전을 하고 싶어졌습니다.
도전!
![](/2022/Days/Images/Day44_Containers20.png)
터미널에서 `docker run -it ubuntu bash`를 실행할 때 우리는 운영 체제의 전체 복사본이 아닌 우분투의 컨테이너화된 버전을 실행할 것입니다. 이 특정 이미지에 대한 자세한 내용은 [DockerHub](https://hub.docker.com/_/ubuntu)에서 확인할 수 있습니다.
아래 명령어를 실행하면 대화형 프롬프트(`-it`)가 나타나고 컨테이너에 bash 셸이 생성되는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day44_Containers21.png)
bash 셸이 있지만 그 이상은 없기 때문에 이 컨테이너 이미지는 30MB 미만입니다.
![](/2022/Days/Images/Day44_Containers22.png)
하지만 여전히 이 이미지를 사용할 수 있고, apt package manager를 사용하여 소프트웨어를 설치할 수 있으며, 컨테이너 이미지를 업데이트하고 업그레이드할 수도 있습니다.
![](/2022/Days/Images/Day44_Containers23.png)
또는 컨테이너에 일부 소프트웨어를 설치하고 싶을 수도 있습니다. pinta는 이미지 편집기이고 200MB가 넘기 때문에 여기서는 정말 나쁜 예를 선택했지만 제가 이걸로 무엇을 하려는지 이해하시길 바랍니다. 이렇게 하면 컨테이너의 크기가 상당히 커지지만, 여전히 GB가 아닌 MB 단위로 사용할 것입니다.
![](/2022/Days/Images/Day44_Containers24.png)
이 글에서는 사용 사례를 통해 Docker Desktop과 컨테이너의 세계에 대한 개요를 간단하고 접근하기 쉬운 방식으로 제공하고자 합니다. 그러나 컨테이너 이미지를 다운로드하고 사용하는 것 외에도 네트워킹, 보안 및 기타 사용 가능한 옵션에 대해서도 다뤄야 합니다. 이 섹션의 궁극적인 목표는 무언가를 만들어서 DockerHub 리포지토리에 업로드하고 배포하는 것입니다.
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
[Day 45](day45.md)에서 봐요!

119
2022/ko/Days/day45.md Normal file
View File

@ -0,0 +1,119 @@
---
title: '#90DaysOfDevOps - The anatomy of a Docker Image - Day 45'
published: false
description: 90DaysOfDevOps - The anatomy of a Docker Image
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048777
---
## Docker 이미지의 구조
지난 세션에서는 DockerHub와 결합된 Docker Desktop을 사용하여 몇 가지 검증된 이미지를 배포하고 실행하는 방법에 대한 몇 가지 기본 사항을 다루었습니다. 이미지가 무엇인지에 대한 요약을 계속 언급하면 잊어버리지 않을 것입니다.
Docker 이미지는 Docker 플랫폼에서 실행할 수 있는 컨테이너를 만들기 위한 일련의 지침이 포함된 읽기 전용 템플릿입니다. 애플리케이션과 사전 구성된 서버 환경을 패키징하여 개인적으로 사용하거나 다른 Docker 사용자와 공개적으로 공유할 수 있는 편리한 방법을 제공합니다. 또한 Docker 이미지는 Docker를 처음 사용하는 모든 사용자에게 시작점이 됩니다.
자체 Docker 이미지를 만들려면 어떻게 해야 하나요? 이를 위해서는 Dockerfile을 생성해야 합니다. 우분투 컨테이너 이미지를 가져와서 소프트웨어를 추가하면 원하는 소프트웨어가 포함된 컨테이너 이미지를 갖게 되고 모든 것이 좋지만, 컨테이너가 종료되거나 폐기되면 모든 소프트웨어 업데이트와 설치가 사라져 반복할 수 있는 버전이 없습니다. 따라서 컨테이너를 실행할 때마다 동일한 소프트웨어 세트가 설치된 여러 환경에 걸쳐 이미지를 전송하는 데는 도움이 되지 않습니다.
### Dockerfile이란?
Dockerfile은 일반적으로 docker 이미지를 빌드하기 위해 수동으로 실행하는 명령이 포함된 텍스트 파일입니다. docker는 Dockerfile에 있는 지침을 읽어 이미지를 자동으로 빌드할 수 있습니다.
docker 이미지를 구성하는 각 파일을 레이어라고 하며, 이러한 레이어는 단계적으로 서로 위에 빌드되는 일련의 이미지를 형성합니다. 각 레이어는 바로 아래 레이어에 종속됩니다. 레이어의 순서는 docker 이미지의 라이프사이클 관리 효율성의 핵심입니다.
가장 자주 변경되는 레이어는 가능한 한 스택에서 가장 높은 곳에 구성해야 하는데, 이는 이미지의 레이어를 변경하면 Docker가 해당 레이어뿐만 아니라 해당 레이어에서 빌드된 모든 레이어를 다시 빌드하기 때문입니다. 따라서 맨 위에 있는 레이어를 변경하면 전체 이미지를 다시 빌드하는 데 필요한 작업량이 가장 적습니다.
docker가 이미지로부터 컨테이너를 실행할 때마다 (어제 실행한 것처럼), 컨테이너 레이어라고 하는 쓰기 가능한 레이어가 추가됩니다. 이 레이어는 컨테이너가 실행되는 동안 모든 변경 사항을 저장합니다. 이 레이어는 실제 운영 중인 컨테이너와 소스 이미지 자체 사이의 유일한 차이점입니다. 같은 이미지에 기반한 동일한 컨테이너들이 상태를 유지하면서 액세스를 공유할 수 있습니다.
예제로 돌아가서, 어제 우분투 이미지를 사용했습니다. 동일한 명령을 여러 번 실행하여 첫 번째 컨테이너에는 pinta를 설치하고 두 번째 컨테이너에는 두 개의 다른 애플리케이션, 다른 목적, 다른 크기 등을 가진 figlet을 설치할 수 있습니다. 배포한 각 컨테이너는 동일한 이미지를 공유하지만, 동일한 상태는 아니며, 컨테이너를 제거하면 해당 상태는 사라집니다.
![](/2022/Days/Images/Day45_Containers1.png)
위의 예제에서 우분투 이미지뿐만 아니라 DockerHub 및 기타 서드파티 리포지토리에서 사용할 수 있는 다른 많은 기성 컨테이너 이미지도 마찬가지입니다. 이러한 이미지를 일반적으로 부모 이미지라고 합니다. 이 이미지는 다른 모든 레이어가 구축되는 기반이 되며 컨테이너 환경의 기본 구성 요소를 제공합니다.
개별 레이어 파일 세트와 함께 Docker 이미지에는 manifest라는 추가 파일도 포함됩니다. 이 파일은 기본적으로 이미지에 대한 JSON 형식의 설명이며 이미지 태그, 전자 서명, 다양한 유형의 호스트 플랫폼에 맞게 컨테이너를 구성하는 방법에 대한 세부 정보와 같은 정보로 구성됩니다.
![](/2022/Days/Images/Day45_Containers2.png)
### Docker 이미지를 생성하는 방법
docker 이미지를 생성하는 방법에는 두 가지가 있습니다. 어제 시작한 프로세스로 즉석에서 만들 수 있습니다. 기본 이미지를 선택하여 해당 컨테이너를 스핀업하고 컨테이너에 원하는 모든 소프트웨어와 종속성을 설치합니다.
그런 다음 `docker commit container name`을 사용하면 이 이미지의 로컬 복사본이 docker 이미지와 Docker Desktop 이미지 탭 아래에 있습니다.
매우 간단하지만, 프로세스를 이해하고 싶은 게 아니라면, 이 방법을 권장하지 않습니다. 이 방법은 라이프사이클 관리를 관리하기가 매우 어렵고 수동 구성/재구성이 많이 필요합니다. 하지만 docker 이미지를 빌드하는 가장 빠르고 간단한 방법입니다. 테스트, 문제 해결, 종속성 검증 등에 적합합니다.
우리가 이미지를 생성하려는 방법은 Dockerfile을 통한 방법입니다. 이는 이미지를 만드는 깔끔하고 간결하며 반복 가능한 방법을 제공합니다. 더 쉬운 라이프사이클 관리와 지속적인 통합 및 지속적인 배포 프로세스에 쉽게 통합할 수 있습니다. 하지만 처음 언급된 방법보다 조금 더 어려울 수 있습니다.
Dockerfile 방법을 사용하는 것이 실제 엔터프라이즈급 컨테이너 배포에 훨씬 더 잘 맞습니다.
Dockerfile은 3단계 프로세스를 통해 Dockerfile을 만들고 이미지를 조립하는 데 필요한 명령을 추가합니다.
다음 표는 사용자가 가장 많이 사용할 가능성이 높은 몇 가지 Dockerfile 설정을 보여줍니다.
| Command | Purpose |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| FROM | 상위 이미지를 지정합니다. |
| WORKDIR | Dockerfile에서 다음에 나오는 명령의 작업 디렉터리를 설정합니다. |
| RUN | 컨테이너에 필요한 애플리케이션과 패키지를 설치합니다. |
| COPY | 특정 위치에서 파일 또는 디렉터리를 복사합니다. |
| ADD | 복사뿐만 아니라 원격 URL을 처리하고 압축 파일의 압축을 풀 수도 있습니다. |
| ENTRYPOINT | 컨테이너가 시작될 때 항상 실행되는 명령입니다. 지정하지 않으면 기본값은 "/bin/sh -c"입니다. |
| CMD | 엔트리포인트로 전달된 인자입니다. 엔트리포인트가 설정되지 않은 경우(기본값은 "/bin/sh -c"), 컨테이너가 실행하는 명령은 CMD가 됩니다. |
| EXPOSE | 컨테이너 애플리케이션에 액세스할 포트를 정의합니다. |
| LABEL | 이미지에 메타데이터를 추가합니다. |
이제 첫 번째 Dockerfile을 빌드하는 방법에 대한 세부 정보를 얻었으므로 작업 디렉터리를 생성하고 Dockerfile을 만들 수 있습니다. 이 리포지토리 내에 작업 디렉터리를 만들었는데, [여기서](/2022/Days/Containers/) 제가 살펴봐야 할 파일과 폴더를 볼 수 있습니다.
이 디렉터리에는 지난 섹션에서 사용한 .gitignore와 유사한 .dockerignore 파일을 만들겠습니다. 이 파일에는 최종 빌드에서 제외하려는 Docker 빌드 프로세스 중에 생성되는 모든 파일이 나열됩니다.
컨테이너는 부피가 커지지 않고 가능한 한 빠르게 컴팩트하게 만들어야 함을 기억하세요.
위에 링크된 폴더에서 아래 레이아웃으로 매우 간단한 Dockerfile을 만들고 싶습니다.
```dockerfile
# 공식 우분투 18.04를 기본으로 사용하세요.
FROM ubuntu:18.04
# nginx 및 curl 설치
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y nginx curl
RUN rm -rf /var/lib/apt/lists/*
```
터미널에서 이 디렉토리로 이동한 다음 `docker build -t 90daysofdevops:0.1 .`를 실행합니다. `-t`를 사용한 다에는 이미지 이름과 태그를 설정할 수 있습니다.
![](/2022/Days/Images/Day45_Containers3.png)
이제 이미지를 만들었으므로 Docker Desktop을 사용하여 이미지를 실행하거나 docker 커맨드라인을 사용할 수 있습니다. 저의 경우에는 Docker Desktop을 사용하여 컨테이너를 실행하고, 컨테이너의 cli에서 `curl`을 사용한 것을 볼 수 있습니다.
![](/2022/Days/Images/Day45_Containers4.png)
Docker Desktop에서는 UI를 활용하여 이 새로운 이미지로 몇 가지 작업을 더 수행할 수 있습니다.
![](/2022/Days/Images/Day45_Containers5.png)
이미지를 검사하면 컨테이너 내에서 실행하려고 하는 Dockerfile과 코드들을 매우 많이 볼 수 있습니다.
![](/2022/Days/Images/Day45_Containers6.png)
pull 옵션이 있지만, 이 이미지는 어디에도 호스팅되지 않기 때문에 이 옵션은 실패할 것이고 오류로 표시됩니다. 하지만 Push to hub 옵션이 있어 이미지를 DockerHub로 push할 수 있습니다.
앞서 실행한 것과 동일한 `docker build`를 사용하는 경우에도 이 방법이 작동하지 않으므로 빌드 명령을 `docker build -t {{username}}/{{imagename}}:{{version}}`로 해야 합니다.
![](/2022/Days/Images/Day45_Containers7.png)
이제 DockerHub 리포지토리로 이동하여 살펴보면 방금 새 이미지를 push한 것을 확인할 수 있습니다. 이제 Docker Desktop에서 해당 pull 탭을 사용할 수 있습니다.
![](/2022/Days/Images/Day45_Containers8.png)
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [Blog on gettng started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-/2022/Days/images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-/2022/Days/images/dockerfile_best-practices/)
[Day 46](day46.md)에서 봐요!

183
2022/ko/Days/day46.md Normal file
View File

@ -0,0 +1,183 @@
---
title: '#90DaysOfDevOps - Docker Compose - Day 46'
published: false
description: 90DaysOfDevOps - Docker Compose
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048740
---
## Docker Compose
하나의 컨테이너를 실행할 수 있는 기능은 단일 사용 사례에 필요한 모든 것을 갖춘 독립적인 이미지가 있는 경우 유용할 수 있지만, 서로 다른 컨테이너 이미지 간에 여러 애플리케이션을 빌드하려는 경우 흥미로운 문제가 발생할 수 있습니다. 예를 들어, 웹사이트 프론트엔드가 있지만 백엔드 데이터베이스가 필요한 경우 모든 것을 하나의 컨테이너에 넣을 수 있지만 데이터베이스용 컨테이너를 사용하는 것이 더 효율적이고 좋을 것입니다.
이때 여러 컨테이너에서 더 복잡한 앱을 실행할 수 있는 도구인 Docker Compose가 등장합니다. 단일 파일과 명령을 사용하여 애플리케이션을 스핀업할 수 있다는 이점이 있습니다. 이 글에서 안내하는 예제는 [Docker 빠른 시작 샘플 앱(빠른 시작: 작성 및 워드프레스)](https://docs.docker.com/samples/wordpress/)에서 가져온 것입니다.
이 첫 번째 예제에서는
- Docker Compose를 사용하여 WordPress와 별도의 MySQL 인스턴스를 불러옵니다.
- 'docker-compose.yml'이라는 YAML 파일을 사용합니다.
- 프로젝트 빌드
- 브라우저를 통해 워드프레스 구성
- 종료 및 정리
### Docker Compose 설치
앞서 언급했듯이 docker compose는 도구이며, 맥OS나 윈도우를 사용하는 경우 Docker Desktop 설치에 compose가 포함되어 있습니다. 하지만, 윈도우 서버 호스트나 리눅스 서버에서 컨테이너를 실행하고 싶을 수 있으며, 이 경우 다음 [docker compose 설치](https://docs.docker.com/compose/install/) 지침을 사용하여 설치할 수 있습니다.
터미널을 열고 위의 명령어를 입력하면 시스템에 `docker-compose`가 설치되었는지 확인할 수 있습니다.
![](/2022/Days/Images/Day46_Containers1.png)
### Docker-Compose.yml(YAML)
다음에 이야기할 것은 리포지토리의 컨테이너 폴더에서 찾을 수 있는 docker-compose.yml입니다. 그 전에, YAML에 대해 조금 설명하겠습니다.
거의 모든 프로그래밍 언어에서 사용할 수 있는 YAML은 다양한 곳에서 사용될 수 있습니다.
"YAML은 모든 프로그래밍 언어에 대한 인간 친화적인 데이터 직렬화 언어입니다."
일반적으로 구성 파일과 데이터를 저장하거나 전송하는 일부 애플리케이션에서 사용됩니다. 동일한 구성 파일을 제공하는 경향이 있는 XML 파일을 접한 적이 있을 것입니다. YAML은 최소한의 구문을 제공하지만, 동일한 사용 사례를 목표로 합니다.
YAML(YAML Ain't Markup Language)은 지난 몇 년 동안 꾸준히 인기가 높아진 직렬화 언어입니다. 객체 직렬화 기능 덕분에 JSON과 같은 언어를 대체할 수 있습니다.
YAML의 약어는 Yet Another Markup Language의 약자였습니다. 그러나 유지 관리자는 데이터 지향적 기능을 더 강조하기 위해 YAML Ain't Markup Language로 이름을 변경했습니다.
어쨌든, 다시 docker-compose.yml 파일로 돌아가겠습니다. 이 파일은 단일 시스템에 여러 개의 컨테이너를 배포할 때 수행하고자 하는 작업의 구성 파일입니다.
위에 링크된 튜토리얼에서 바로 파일의 내용을 보면 다음과 같이 보입니다:
```yaml
version: '3.9'
services:
DB:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- '8000:80'
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
```
버전을 선언한 다음, 이 docker-compose.yml 파일의 대부분은 서비스로 구성되어 있으며, DB 서비스와 워드프레스 서비스가 있습니다. 각 서비스에는 버전 태그가 연결된 이미지가 정의되어 있는 것을 볼 수 있습니다. 이제 첫 번째 연습과 달리 구성에 상태도 도입하고 있는데, 데이터베이스를 저장할 수 있도록 볼륨을 생성하겠습니다.
그런 다음 비밀번호 및 사용자 이름과 같은 몇 가지 환경 변수가 있습니다. 이러한 파일은 매우 복잡해질 수 있지만 YAML 구성 파일을 사용하면 전체적으로 단순화할 수 있습니다.
### 프로젝트 빌드
이제 터미널로 돌아가서 docker-compose 도구로 몇 가지 명령을 사용할 수 있습니다. 디렉토리로 이동하여 docker-compose.yml 파일이 있는 디렉터리로 이동합니다.
터미널에서 `docker-compose up -d`를 실행하면 해당 이미지를 가져와 멀티 컨테이너 애플리케이션을 세우는 프로세스가 시작됩니다.
이 명령의 `-d`는 분리 모드를 의미하며, 이는 실행 명령이 백그라운드에서 실행 중이거나 실행될 것임을 의미합니다.
![](/2022/Days/Images/Day46_Containers2.png)
이제 `docker ps` 명령을 실행하면 2개의 컨테이너가 실행 중이며 하나는 WordPress이고 다른 하나는 MySQL인 것을 볼 수 있습니다.
![](/2022/Days/Images/Day46_Containers3.png)
다음으로 브라우저를 열고 `http://localhost:8000`으로 이동하면 WordPress가 실행 중인지 확인할 수 있으며, WordPress 설정 페이지가 표시됩니다.
![](/2022/Days/Images/Day46_Containers4.png)
워드프레스 설정을 완료한 다음 아래 콘솔에서 원하는 대로 웹사이트 구축을 시작할 수 있습니다.
![](/2022/Days/Images/Day46_Containers5.png)
이제 새 탭을 열고 `http://localhost:8000` 이전과 동일한 주소로 이동하면 사이트 제목이 "90DaysOfDevOps"인 간단한 기본 테마가 표시되고 샘플 게시물이 표시됩니다.
![](/2022/Days/Images/Day46_Containers6.png)
변경하기 전에 Docker Desktop을 열고 볼륨 탭으로 이동하면 컨테이너와 연결된 두 개의 볼륨(하나는 워드프레스용, 다른 하나는 DB용)을 볼 수 있습니다.
![](/2022/Days/Images/Day46_Containers7.png)
현재 워드프레스 테마는 "Twenty Twenty-Two"이며 이를 "Twenty Twenty"로 변경하고 싶습니다. 대시보드로 돌아와서 변경할 수 있습니다.
![](/2022/Days/Images/Day46_Containers8.png)
또한 사이트에 새 게시물을 추가하려고 하는데, 아래에서 새 사이트의 최신 버전을 볼 수 있습니다.
![](/2022/Days/Images/Day46_Containers9.png)
### 정리 여부
이제 `docker-compose down` 명령을 사용하면 컨테이너가 삭제됩니다. 하지만 볼륨은 그대로 유지됩니다.
![](/2022/Days/Images/Day46_Containers10.png)
Docker Desktop에서 볼륨이 여전히 존재한다는 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day46_Containers11.png)
그런 다음 다시 백업하려면 동일한 디렉토리 내에서 `docker up -d` 명령을 실행하면 애플리케이션을 다시 백업하고 실행할 수 있습니다.
![](/2022/Days/Images/Day46_Containers12.png)
그런 다음 브라우저에서 동일한 주소인 `http://localhost:8000`으로 이동하면 새 글과 테마 변경 사항이 모두 그대로 유지되는 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day46_Containers13.png)
컨테이너와 해당 볼륨을 제거하려면 `docker-compose down --volumes`를 실행하면 볼륨도 제거됩니다.
![](/2022/Days/Images/Day46_Containers14.png)
이제 `docker-compose up -d`를 다시 사용하면 시작하지만, 이미지는 여전히 우리 시스템의 로컬에 있으므로 DockerHub 리포지토리에서 다시 가져올 필요가 없습니다.
docker-compose와 그 기능에 대해 알아보기 시작했을 때 이것이 Kubernetes와 같은 컨테이너 오케스트레이션 도구와 어디에 위치하는지 혼란스러웠는데, 이 짧은 데모에서 우리가 한 모든 작업은 로컬 데스크톱 머신에서 실행 중인 WordPress와 DB가 있는 호스트 하나에 초점을 맞추고 있습니다. 여러 가상 머신이나 여러 물리적 머신이 없으며 애플리케이션의 요구 사항을 쉽게 확장 및 축소할 수도 없습니다.
다음 섹션에서는 Kubernetes를 다룰 예정이지만, 먼저 컨테이너에 대한 전반적인 내용을 며칠 더 살펴보겠습니다.
[Awesome-Compose](https://github.com/docker/awesome-compose)는 여러 통합이 있는 docker-compose 애플리케이션의 샘플을 위한 훌륭한 리소스입니다.
위의 리포지토리에는 단일 노드에 Elasticsearch, Logstash, Kibana(ELK)를 배포하는 훌륭한 예제가 있습니다.
[Containers 폴더](/2022/Days/Containers/elasticsearch-logstash-kibana/)에 파일을 업로드했습니다. 이 폴더가 로컬에 있으면 해당 폴더로 이동하여 `docker-compose up -d`를 사용하면 간단하게 설치할 수 있습니다.
![](/2022/Days/Images/Day46_Containers15.png)
그런 다음 `docker ps`로 실행 중인 컨테이너가 있는지 확인할 수 있습니다.
![](/2022/Days/Images/Day46_Containers16.png)
이제 각 컨테이너에 대한 브라우저를 열 수 있습니다:
![](/2022/Days/Images/Day46_Containers17.png)
모든 것을 제거하려면 `docker-compose down` 명령을 사용할 수 있습니다.
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [Blog on getting started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-/2022/Days/images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-/2022/Days/images/dockerfile_best-practices/)
- [YAML Tutorial: Everything You Need to Get Started in Minute](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started)
[Day 47](day47.md)에서 봐요!

139
2022/ko/Days/day47.md Normal file
View File

@ -0,0 +1,139 @@
---
title: '#90DaysOfDevOps - Docker Networking & Security - Day 47'
published: false
description: 90DaysOfDevOps - Docker Networking & Security
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049078
---
## Docker 네트워킹 및 보안
지금까지 컨테이너 세션에서 우리는 작업을 수행했지만, 네트워킹 관점에서 작업이 어떻게 작동했는지 살펴보지 않았으며 보안에 대해서도 다루지 않았습니다.
### Docker 네트워킹 기본 사항
터미널을 열고, 컨테이너 네트워크를 구성하고 관리하기 위한 기본 명령어인 `docker network` 명령을 입력합니다.
아래에서 이 명령어를 사용하는 방법과 사용 가능한 모든 하위 명령을 확인할 수 있습니다. 새로운 네트워크를 생성하고, 기존 네트워크를 나열하고, 네트워크를 검사 및 제거할 수 있습니다.
![](/2022/Days/Images/Day47_Containers1.png)
설치 이후 우리가 가지고 있는 기존 네트워크를 살펴보기 위해 `docker network list` 명령을 사용하는 기본 Docker 네트워킹의 모습을 살펴봅시다.
각 네트워크는 고유한 ID와 이름을 갖습니다. 각 네트워크는 또한 단일 드라이버와 연결됩니다. "bridge" 네트워크와 "host" 네트워크는 각각의 드라이버와 이름이 동일합니다.
![](/2022/Days/Images/Day47_Containers2.png)
다음으로 `docker network inspect` 명령으로 네트워크를 더 자세히 살펴볼 수 있습니다.
`docker network inspect bridge`를 실행하면 특정 네트워크 이름에 대한 모든 구성 세부 정보를 얻을 수 있습니다. 여기에는 이름, ID, 드라이버, 연결된 컨테이너 등이 포함되며 보시다시피 훨씬 더 많은 정보를 확인할 수 있습니다.
![](/2022/Days/Images/Day47_Containers3.png)
### Docker: bridge 네트워킹
위에서 보았듯이 Docker Desktop을 표준 설치하면 `bridge`라는 사전 구축된 네트워크가 제공됩니다. `docker network list` 명령을 다시 실행하면 bridge라는 네트워크가 `bridge` 드라이버와 연결되어 있는 것을 볼 수 있습니다. 이름이 같다고 해서 같은 것은 아닙니다. 연결되었지만 같은 것은 아닙니다.
위의 출력은 또한 bridge 네트워크가 로컬로 범위가 지정되었음을 보여줍니다. 이는 네트워크가 이 Docker host에만 존재한다는 것을 의미합니다. 이는 bridge 드라이버를 사용하는 모든 네트워크에 해당되며, bridge 드라이버는 단일 host 네트워킹을 제공합니다.
bridge 드라이버로 생성된 모든 네트워크는 Linux bridge(virtual switch라고도 함)를 기반으로 합니다.
### 컨테이너 연결
기본적으로 bridge 네트워크는 새 컨테이너에 할당되므로 네트워크를 지정하지 않으면 모든 컨테이너가 bridge 네트워크에 연결됩니다.
`docker run -dt ubuntu sleep infinity` 명령으로 새 컨테이너를 생성해 보겠습니다.
위의 sleep 명령은 컨테이너를 백그라운드에서 계속 실행시켜서 컨테이너를 마음대로 다룰 수 있도록 합니다.
![](/2022/Days/Images/Day47_Containers4.png)
이제 `docker network inspect bridge`로 bridge 네트워크를 확인하면 네트워크를 지정하지 않았기 때문에 방금 배포한 것과 일치하는 컨테이너가 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day47_Containers5.png)
`docker exec -it 3a99af449ca2 bash`를 사용하여 컨테이너를 자세히 살펴볼 수도 있습니다. 컨테이너 ID를 얻으려면 `docker ps`를 사용해야 합니다.
여기에서 이미지에는 핑할 항목이 없으므로, `apt-get update && apt-get install -y iputils-ping`을 실행한 다음 외부 인터페이스 주소를 핑합니다. `ping -c5 www.90daysofdevops.com`
![](/2022/Days/Images/Day47_Containers6.png)
이 문제를 해결하기 위해 `docker stop 3a99af449ca2`를 다시 실행하고 `docker ps`를 사용하여 컨테이너 ID를 찾을 수 있지만, 이렇게 하면 컨테이너가 제거됩니다.
### 외부 연결을 위한 NAT 구성하기
이 단계에서는 새 NGINX 컨테이너를 시작하고 Docker host의 포트 8080을 컨테이너 내부의 포트 80으로 매핑합니다. 즉, 포트 8080의 Docker host에 도달하는 트래픽은 컨테이너 내부의 포트 80으로 전달됩니다.
`docker run --name web1 -d -p 8080:80 nginx`를 실행하여 공식 NGINX 이미지를 기반으로 새 컨테이너를 시작합니다.
![](/2022/Days/Images/Day47_Containers7.png)
`docker ps`를 실행하여 컨테이너 상태와 포트 매핑을 검토합니다.
![](/2022/Days/Images/Day47_Containers8.png)
맨 위 줄은 NGINX를 실행하는 새 web1 컨테이너를 보여줍니다. 컨테이너가 실행 중인 명령과 포트 매핑에 주목하세요. - `0.0.0.0:8080->80/tcp`는 모든 host 인터페이스의 8080 포트를 web1 컨테이너 내부의 80 포트에 매핑합니다. 이 포트 매핑을 통해 외부 소스에서 컨테이너의 웹 서비스에 효과적으로 액세스할 수 있습니다(포트 8080의 Docker host IP 주소를 통해).
이제 실제 host에 대한 IP 주소가 필요하며, WSL 터미널로 이동하여 `IP addr` 명령을 사용하여 이를 수행할 수 있습니다.
![](/2022/Days/Images/Day47_Containers9.png)
그런 다음, 이 IP를 가지고 브라우저를 열어 `http://172.25.218.154:8080/`로 이동하면 IP가 다를 수 있습니다. 이렇게 하면 NGINX에 액세스할 수 있음을 확인할 수 있습니다.
![](/2022/Days/Images/Day47_Containers10.png)
이 사이트의 이 지침은 2017년 DockerCon에서 가져온 것이지만 오늘날에도 여전히 유효합니다. 그러나 나머지 연습은 Docker Swarm에 대한 것이므로 여기서는 다루지 않겠습니다. [Docker 네트워킹 - DockerCon 2017](https://github.com/docker/labs/tree/master/dockercon-us-2017/docker-networking)
### 컨테이너 보안
컨테이너는 전체 서버 구성에 비해 워크로드에 안전한 환경을 제공합니다. 컨테이너는 애플리케이션을 서로 격리된 훨씬 더 작고 느슨하게 결합된 구성 요소로 분할할 수 있는 기능을 제공하므로 전체적으로 공격 표면을 줄이는 데 도움이 됩니다.
하지만 시스템의 취약점을 공격하려는 해커로부터 자유롭지는 않습니다. 우리는 여전히 이 기술의 보안 결함을 이해하고 모범 사례를 유지해야 합니다.
### 루트 권한에서 벗어나기
지금까지 배포한 모든 컨테이너는 컨테이너 내 프로세스에 대한 루트 권한을 사용해 왔습니다. 즉, 컨테이너와 host 환경에 대한 모든 관리 액세스 권한이 있다는 뜻입니다. 이제 이러한 시스템이 오래 가동되지 않을 것이라는 것을 알고 있었습니다. 하지만 시작하고 실행하는 것이 얼마나 쉬운지 보셨을 것입니다.
프로세스에 몇 단계를 추가하여 루트 사용자가 아닌 사용자가 선호하는 모범 사례를 사용할 수 있도록 할 수 있습니다. dockerfile을 만들 때 사용자 계정을 만들 수 있습니다. 이 예제는 리포지토리의 컨테이너 폴더에서도 찾을 수 있습니다.
```dockerfile
# 공식 Ubuntu 18.04를 기본으로 사용하세요.
FROM ubuntu:18.04
RUN apt-get update && apt-get upgrade -y
RUN groupadd -g 1000 basicuser && useradd -r -u 1000 -g basicuser basicuser
USER basicuser
```
`docker run --user 1009 ubuntu` 명령은 dockerfile에 지정된 모든 사용자를 재정의합니다. 따라서 다음 예제에서는 컨테이너가 항상 권한이 가장 낮은 사용자 식별자 1009로 실행되며 권한 수준도 가장 낮습니다.
그러나 이 방법은 이미지 자체의 근본적인 보안 결함을 해결하지 못합니다. 따라서 컨테이너가 항상 안전하게 실행되도록 dockerfile에 루트 사용자가 아닌 사용자를 지정하는 것이 좋습니다.
### 비공개 레지스트리
조직에서 컨테이너 이미지의 비공개 레지스트리를 설정하면 원하는 곳에서 호스팅할 수 있거나 이를 위한 관리형 서비스도 있지만, 대체로 사용자와 팀이 사용할 수 있는 이미지를 완벽하게 제어할 수 있습니다.
DockerHub는 기준선을 제시하는 데는 훌륭하지만, 이미지 게시자를 많이 신뢰해야 하는 기본적인 서비스만 제공합니다.
### 린 & 클린
보안과 관련되지는 않았지만, 전체적으로 언급했습니다. 그러나 애플리케이션에서 사용하지 않는 리소스가 컨테이너에 필요하지 않은 경우 컨테이너의 크기는 공격 표면 측면에서 보안에 영향을 미칠 수 있습니다.
또한 `latest` 이미지를 가져올 때 이미지에 많은 부풀림을 가져올 수 있기 때문에 이것이 저의 주요 관심사입니다. DockerHub는 리포지토리에 있는 각 이미지의 압축 크기를 표시합니다.
`docker image`를 확인하면 이미지의 크기를 확인할 수 있는 좋은 명령어입니다.
![](/2022/Days/Images/Day47_Containers11.png)
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [Blog on getting started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-/2022/Days/images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-/2022/Days/images/dockerfile_best-practices/)
- [YAML Tutorial: Everything You Need to Get Started in Minute](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started)
[Day 48](day48.md)에서 봐요!

115
2022/ko/Days/day48.md Normal file
View File

@ -0,0 +1,115 @@
---
title: '#90DaysOfDevOps - Alternatives to Docker - Day 48'
published: false
description: 90DaysOfDevOps - Alternatives to Docker
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048807
---
## Docker의 대안
이 섹션의 맨 처음에 Docker를 사용할 것이라고 말씀드린 이유는 단순히 리소스 측면에서 매우 많고 커뮤니티가 매우 크기 때문이기도 하지만, 컨테이너를 대중화하기 위한 시도가 바로 여기에서 시작되었기 때문입니다. Docker의 역사와 그 탄생 과정을 살펴보는 것이 매우 유용하다고 생각합니다.
하지만 앞서 언급했듯이 Docker를 대체할 수 있는 다른 대안이 있습니다. Docker가 무엇이고 무엇을 다루었는지 생각해 보면 다음과 같습니다. 애플리케이션을 개발, 테스트, 배포 및 관리하기 위한 플랫폼입니다.
앞으로 실제로 사용할 수 있거나 앞으로 사용할 수 있는 Docker의 몇 가지 대안을 강조하고 싶습니다.
### Podman
Podman이란? Podman은 리눅스 시스템에서 OCI 컨테이너를 개발, 관리, 실행하기 위한 데몬이 없는 컨테이너 엔진입니다. 컨테이너는 루트로 실행하거나 루트리스 모드로 실행할 수 있습니다.
여기서는 Windows 관점에서 살펴볼 것이지만, Docker와 마찬가지로 Windows에서는 할 수 없는 기본 OS를 사용하기 때문에 가상화가 필요하지 않습니다.
Podman은 WSL2에서도 실행할 수 있지만, Docker Desktop의 경험만큼 매끄럽지는 않습니다. 컨테이너가 실행될 Linux VM에 연결할 수 있는 Windows 원격 클라이언트도 있습니다.
제가 사용하는 WSL2의 우분투는 20.04 릴리스입니다. 다음 단계에 따라 WSL 인스턴스에 Podman을 설치할 수 있습니다.
```Shell
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /" |
sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
```
GPG 키를 추가합니다.
```Shell
curl -L "https://download.opensuse.org/repositories/devel:/kubic:\
/libcontainers:/stable/xUbuntu_20.04/Release.key" | sudo apt-key add -
```
`sudo apt-get update && sudo apt-get upgrade`명령으로 시스템 업데이트 및 업그레이드를 실행합니다. 마지막으로`sudo apt install podman`을 사용하여 podman을 설치할 수 있습니다.
이제 docker에 사용하던 것과 동일한 명령을 많이 사용할 수 있습니다. 다만 멋진 docker 데스크톱 UI가 없다는 점에 유의하세요. 아래에서 볼 수 있듯이 `podman images`를 사용했고 설치 후 아무것도 없으므로 `podman pull ubuntu`를 사용하여 우분투 컨테이너 이미지를 끌어 내렸습니다.
![](/2022/Days/Images/Day48_Containers1.png)
그런 다음 `podman run -dit ubuntu``podman ps`를 사용하여 우분투 이미지를 실행하여 실행 중인 이미지를 확인할 수 있습니다.
![](/2022/Days/Images/Day48_Containers2.png)
그런 다음 해당 컨테이너에 들어가기 위해 `podman attach dazzling_darwin`을 실행하면 컨테이너 이름이 달라질 수 있습니다.
![](/2022/Days/Images/Day48_Containers3.png)
docker에서 podman으로 이동하는 경우, 설정 파일에 `alias docker=podman`으로 변경하여 docker로 실행하는 모든 명령이 podman을 사용하도록 하는 것도 일반적입니다.
### LXC
LXC는 사용자가 다시 여러 개의 격리된 리눅스 컨테이너 환경을 생성할 수 있게 해주는 컨테이너화 엔진입니다. Docker와 달리, LXC는 별도의 시스템 파일과 네트워킹 기능을 갖춘 여러 리눅스 머신을 생성하기 위한 하이퍼바이저 역할을 합니다. docker보다 먼저 등장했다가 docker의 단점으로 인해 잠시 사용되었습니다.
LXC는 docker만큼 가볍고 쉽게 배포할 수 있습니다.
### Containerd
독립형 컨테이너 런타임. Containerd는 단순성과 견고성은 물론 이식성까지 제공합니다. 이전에는 Docker 컨테이너 서비스의 일부로 실행되는 도구로 사용되다가 Docker가 구성 요소를 독립형 구성 요소로 분리하기로 결정하기 전까지 Containerd가 사용되었습니다.
클라우드 네이티브 컴퓨팅 재단의 프로젝트로, Kubernetes, Prometheus, CoreDNS와 같은 인기 컨테이너 도구와 같은 부류에 속합니다.
### 기타 Docker 도구
Rancher와 VirtualBox와 관련된 도구와 옵션도 언급할 수 있지만 다음 기회에 더 자세히 다루겠습니다.
[**Gradle**](https://gradle.org/)
- 빌드 스캔을 통해 팀은 공동으로 스크립트를 디버깅하고 모든 빌드의 이력을 추적할 수 있습니다.
- 실행 옵션을 통해 팀은 변경 사항이 입력될 때마다 작업이 자동으로 실행되도록 지속적으로 빌드할 수 있습니다.
- 사용자 지정 리포지토리 레이아웃을 통해 팀은 모든 파일 디렉토리 구조를 아티팩트 리포지토리로 취급할 수 있습니다.
[**Packer**](https://packer.io/)
- 여러 머신 이미지를 병렬로 생성하여 개발자의 시간을 절약하고 효율성을 높일 수 있습니다.
- 패커의 디버거를 사용하여 빌드를 쉽게 디버깅할 수 있어 실패를 검사하고 빌드를 다시 시작하기 전에 솔루션을 시험해 볼 수 있습니다.
- 플러그인을 통해 다양한 플랫폼을 지원하므로 팀이 빌드를 커스터마이징할 수 있습니다.
[**Logspout**](https://github.com/gliderlabs/logspout)
- 로깅 도구 - 이 도구의 사용자 지정 기능을 통해 팀은 동일한 로그를 여러 대상에 전송할 수 있습니다.
- 이 도구는 Docker 소켓에 액세스하기만 하면 되기 때문에 팀에서 파일을 쉽게 관리할 수 있습니다.
- 완전히 오픈 소스이며 배포가 쉽습니다.
[**Logstash**](https://www.elastic.co/products/logstash)
- Logstash의 플러그형 프레임워크를 사용해 파이프라인을 사용자 정의하세요.
- 분석을 위해 데이터를 쉽게 구문 분석하고 변환하여 비즈니스 가치를 제공할 수 있습니다.
- Logstash의 다양한 출력을 통해 원하는 곳으로 데이터를 라우팅할 수 있습니다.
[**Portainer**](https://www.portainer.io/)
- 미리 만들어진 템플릿을 활용하거나 직접 템플릿을 만들어 애플리케이션을 배포하세요.
- 팀을 생성하고 팀원에게 역할과 권한을 할당하세요.
- 도구의 대시보드를 사용하여 각 환경에서 무엇이 실행되고 있는지 파악하세요.
## 자료
- [TechWorld with Nana - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=3c-iBn73dDE)
- [Programming with Mosh - Docker Tutorial for Beginners](https://www.youtube.com/watch?v=pTFZFxd4hOI)
- [Docker Tutorial for Beginners - What is Docker? Introduction to Containers](https://www.youtube.com/watch?v=17Bl31rlnRM&list=WL&index=128&t=61s)
- [WSL 2 with Docker getting started](https://www.youtube.com/watch?v=5RQbdMn04Oc)
- [Blog on getting started building a docker image](https://stackify.com/docker-build-a-beginners-guide-to-building-docker-images/)
- [Docker documentation for building an image](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
- [YAML Tutorial: Everything You Need to Get Started in Minute](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started)
- [Podman | Daemonless Docker | Getting Started with Podman](https://www.youtube.com/watch?v=Za2BqzeZjBk)
- [LXC - Guide to building an LXC Lab](https://www.youtube.com/watch?v=cqOtksmsxfg)
[Day 49](day49.md)에서 봐요!

235
2022/ko/Days/day49.md Normal file
View File

@ -0,0 +1,235 @@
---
title: '#90DaysOfDevOps - The Big Picture: Kubernetes - Day 49'
published: false
description: 90DaysOfDevOps - The Big Picture Kubernetes
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049049
---
## 큰 그림: Kubernetes
지난 섹션에서 컨테이너에 대해 살펴보았는데, 컨테이너는 scale과 오케스트레이션만으로는 부족합니다. 우리가 할 수 있는 최선은 docker-compose를 사용하여 여러 컨테이너를 함께 불러오는 것입니다. 컨테이너 오케스트레이터인 Kubernetes를 사용하면 애플리케이션과 서비스의 부하에 따라 자동화된 방식으로 확장 및 축소할 수 있습니다.
플랫폼으로서 Kubernetes는 요구사항과 원하는 상태에 따라 컨테이너를 오케스트레이션할 수 있는 기능을 제공합니다. 이 섹션에서는 차세대 인프라로 빠르게 성장하고 있는 Kubernetes에 대해 다룰 예정입니다. 또한 데브옵스 관점에서 볼 때 Kubernetes는 기본적인 이해가 필요한 하나의 플랫폼일 뿐이며, 베어메탈, 가상화 및 대부분의 클라우드 기반 서비스도 이해해야 합니다. Kubernetes는 애플리케이션을 실행하기 위한 또 다른 옵션일 뿐입니다.
### 컨테이너 오케스트레이션이란 무엇인가요?
앞서 Kubernetes와 컨테이너 오케스트레이션에 대해 언급했는데, Kubernetes는 기술인 반면 컨테이너 오케스트레이션은 기술 이면의 개념 또는 프로세스입니다. 컨테이너 오케스트레이션 플랫폼은 Kubernetes뿐만 아니라 Docker Swarm, HashiCorp Nomad 등도 있습니다. 하지만 Kubernetes가 점점 더 강세를 보이고 있기 때문에 Kubernetes를 다루고 싶지만, Kubernetes만이 유일한 것은 아니라는 점을 말씀드리고 싶었습니다.
### Kubernetes란 무엇인가요?
Kubernetes를 처음 접하는 경우 가장 먼저 읽어야 할 것은 공식 문서입니다. 1년 조금 전에 Kubernetes에 대해 깊이 파고든 제 경험에 따르면 학습 곡선이 가파르게 진행될 것입니다. 가상화 및 스토리지에 대한 배경지식이 있는 저는 이것이 얼마나 벅차게 느껴질지 생각했습니다.
하지만 커뮤니티, 무료 학습 리소스 및 문서는 놀랍습니다. [Kubernetes.io](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
Kubernetes는 컨테이너화된 워크로드와 서비스를 관리하기 위한 이식 가능하고 확장 가능한 오픈소스 플랫폼으로, 선언적 구성과 자동화를 모두 용이하게 합니다. 빠르게 성장하는 대규모 에코시스템이 있습니다. Kubernetes 서비스, 지원, 도구는 널리 이용 가능합니다.
위의 인용문에서 주목해야 할 중요한 점은 Kubernetes는 클라우드 네이티브 컴퓨팅 재단(CNCF)에 프로젝트를 기부한 Google로 거슬러 올라가는 풍부한 역사를 가진 오픈소스이며, 현재 오픈소스 커뮤니티와 대기업 벤더가 오늘날의 Kubernetes를 만드는 데 기여하면서 발전해 왔다는 점입니다.
위에서 컨테이너가 훌륭하다고 말씀드렸고 이전 섹션에서는 컨테이너와 컨테이너 이미지가 어떻게 클라우드 네이티브 시스템의 채택을 변화시키고 가속화했는지에 대해 이야기했습니다. 하지만 컨테이너만으로는 애플리케이션에 필요한 프로덕션 지원 환경을 제공할 수 없습니다. Kubernetes는 다음과 같은 이점을 제공합니다:
- **Services discovery 및 로드 밸런싱** Kubernetes는 DNS 이름 또는 IP 주소를 사용하여 컨테이너를 노출할 수 있습니다. 컨테이너에 대한 트래픽이 많을 경우, Kubernetes는 네트워크 트래픽을 로드 밸런싱하고 분산하여 배포가 안정적으로 이루어지도록 할 수 있습니다.
- **스토리지 오케스트레이션** Kubernetes를 사용하면 로컬 스토리지, 퍼블릭 클라우드 제공자 등 원하는 스토리지 시스템을 자동으로 마운트할 수 있습니다.
- **자동화된 롤아웃 및 롤백** 배포된 컨테이너에 대해 원하는 상태를 설명할 수 있으며, 제어된 속도로 실제 상태를 원하는 상태로 변경할 수 있습니다. 예를 들어, 배포를 위한 새 컨테이너를 생성하고, 기존 컨테이너를 제거하고, 모든 리소스를 새 컨테이너에 적용하도록 Kubernetes를 자동화할 수 있습니다.
- **자동 bin 패킹** 컨테이너화된 작업을 실행하는 데 사용할 수 있는 노드 클러스터를 Kubernetes에 제공하고, 각 컨테이너에 필요한 CPU와 메모리(RAM)의 양을 Kubernetes에 알려줍니다. Kubernetes는 리소스를 최대한 활용하기 위해 컨테이너를 노드에 맞출 수 있습니다.
- **자가 복구** Kubernetes는 장애가 발생한 컨테이너를 다시 시작하고, 컨테이너를 교체하고, 사용자 정의 상태 확인에 응답하지 않는 컨테이너를 죽이고, 제공할 준비가 될 때까지 클라이언트에게 알리지 않습니다.
- **비밀 및 구성 관리** Kubernetes를 사용하면 비밀번호, OAuth 토큰, SSH 키와 같은 민감한 정보를 저장하고 관리할 수 있습니다. 컨테이너 이미지를 다시 빌드하거나 스택 구성에 시크릿을 노출하지 않고도 시크릿 및 애플리케이션 구성을 배포하고 업데이트할 수 있습니다.
Kubernetes는 분산 시스템을 탄력적으로 실행할 수 있는 프레임워크를 제공합니다.
컨테이너 오케스트레이션은 컨테이너의 배포, 배치 및 라이프사이클을 관리합니다.
또한 다른 많은 책임도 있습니다:
- 클러스터 관리는 호스트를 하나의 대상으로 묶습니다.
- 스케줄 관리는 스케줄러를 통해 컨테이너를 노드 간에 배포합니다.
- Services discovery은 컨테이너의 위치를 파악하고 클라이언트 요청을 컨테이너에 분산합니다.
- 복제는 요청된 워크로드에 적합한 수의 노드와 컨테이너를 사용할 수 있도록 보장합니다.
- 상태 관리는 건강하지 않은 컨테이너와 노드를 감지하고 교체합니다.
### 주요 Kubernetes 구성 요소
Kubernetes는 애플리케이션을 프로비저닝, 관리 및 확장하기 위한 컨테이너 오케스트레이터입니다. 이를 사용하여 VM 또는 물리적 머신과 같은 워커 머신의 모음인 노드 클러스터에서 컨테이너화된 앱의 라이프사이클을 관리할 수 있습니다.
앱을 실행하려면 데이터베이스 연결, 방화벽 백엔드와의 통신, 키 보안에 도움이 되는 볼륨, 네트워크, 시크릿 등 다른 많은 리소스가 필요할 수 있습니다. Kubernetes를 사용하면 이러한 리소스를 앱에 추가할 수 있습니다. 앱에 필요한 인프라 리소스는 선언적으로 관리됩니다.
Kubernetes의 핵심 패러다임은 선언적 모델입니다. 사용자가 원하는 상태를 제공하면 Kubernetes가 이를 실현합니다. 인스턴스 다섯 개가 필요한 경우, 사용자가 직접 다섯 개의 인스턴스를 시작하지 않습니다. 대신 인스턴스 5개가 필요하다고 Kubernetes에 알려주면 Kubernetes가 자동으로 상태를 조정합니다. 인스턴스 중 하나에 문제가 발생하여 실패하더라도 Kubernetes는 여전히 사용자가 원하는 상태를 파악하고 사용 가능한 노드에 인스턴스를 생성합니다.
### 노드
#### 컨트롤 플레인
모든 Kubernetes 클러스터에는 컨트롤 플레인 노드가 필요하며, 컨트롤 플레인의 구성 요소는 클러스터에 대한 전역 결정(예: 스케줄링)을 내리고 클러스터 이벤트를 감지 및 응답합니다.
![](/2022/Days/Images/Day49_Kubernetes1.png)
#### 워커 노드
Kubernetes 워크로드를 실행하는 워커 머신입니다. 물리적(베어메탈) 머신이거나 가상 머신(VM)일 수 있습니다. 각 노드는 하나 이상의 pod를 호스트할 수 있습니다. Kubernetes 노드는 컨트롤 플레인에 의해 관리됩니다.
![](/2022/Days/Images/Day49_Kubernetes2.png)
다른 노드 유형이 있지만 여기서는 다루지 않겠습니다.
#### kubelet
클러스터의 각 노드에서 실행되는 에이전트입니다. 컨테이너가 pod에서 실행되고 있는지 확인합니다.
kubelet은 다양한 메커니즘을 통해 제공되는 일련의 PodSpec을 가져와서 해당 PodSpec에 설명된 컨테이너가 실행 중이고 정상인지 확인합니다. kubelet은 Kubernetes가 생성하지 않은 컨테이너는 관리하지 않습니다.
![](/2022/Days/Images/Day49_Kubernetes3.png)
#### kube-proxy
kube-proxy는 클러스터의 각 노드에서 실행되는 네트워크 프록시로, Kubernetes Services 개념의 일부를 구현합니다.
kube-proxy는 노드에서 네트워크 규칙을 유지 관리합니다. 이러한 네트워크 규칙은 클러스터 내부 또는 외부의 네트워크 세션에서 pod로의 네트워크 통신을 허용합니다.
운영 체제 패킷 필터링 계층이 있고 사용 가능한 경우, kube-proxy는 이를 사용합니다. 그렇지 않으면, kube-proxy는 트래픽 자체를 전달합니다.
![](/2022/Days/Images/Day49_Kubernetes4.png)
#### 컨테이너 런타임
컨테이너 런타임은 컨테이너 실행을 담당하는 소프트웨어입니다.
Kubernetes는 여러 컨테이너 런타임을 지원합니다: docker, containerd, CRI-O 그리고 Kubernetes CRI(Container Runtime Interface)의 모든 구현
![](/2022/Days/Images/Day49_Kubernetes5.png)
### 클러스터
클러스터는 노드의 그룹으로, 노드는 물리적 머신 또는 가상 머신이 될 수 있습니다. 각 노드에는 컨테이너 런타임(Docker)이 있으며 마스터 컨트롤러(나중에 자세히 설명)의 명령을 받는 에이전트인 kubelet 서비스와 다른 구성 요소(나중에 자세히 설명)에서 pod에 대한 연결을 프록시하는 데 사용되는 프록시도 실행됩니다.
고가용성으로 만들 수 있는 컨트롤 플레인에는 워커 노드와 비교하여 몇 가지 고유한 역할이 포함되며, 가장 중요한 것은 정보를 가져오거나 Kubernetes 클러스터로 정보를 푸시하기 위한 모든 통신이 이루어지는 곳인 kube API 서버입니다.
#### Kube API 서버
Kubernetes API 서버는 pod, 서비스, 응답 컨트롤러 등을 포함하는 API 오브젝트에 대한 데이터의 유효성을 검사하고 구성합니다. API 서버는 REST 작업을 수행하고 다른 모든 구성 요소가 상호 작용하는 클러스터의 공유 상태에 대한 프론트엔드를 제공합니다.
#### 스케줄러
Kubernetes 스케줄러는 노드에 pod를 할당하는 컨트롤 플레인 프로세스입니다. 스케줄러는 제약 조건과 사용 가능한 리소스에 따라 스케줄링 대기열에서 각 pod에 대해 유효한 배치가 되는 노드를 결정합니다. 그런 다음 스케줄러는 각 유효한 노드의 순위를 매기고 pod를 적합한 노드에 바인딩합니다.
#### 컨트롤러 매니저
Kubernetes 컨트롤러 매니저는 Kubernetes와 함께 제공되는 핵심 제어 루프를 임베드하는 daemon입니다. 로보틱스 및 자동화 애플리케이션에서 제어 루프는 시스템 상태를 조절하는 비종료 루프입니다. Kubernetes에서 컨트롤러는 API 서버를 통해 클러스터의 공유 상태를 감시하고 현재 상태를 원하는 상태로 이동시키기 위해 변경을 시도하는 제어 루프입니다.
#### etcd
모든 클러스터 데이터에 대한 Kubernetes의 백업 저장소로 사용되는 일관되고 가용성이 높은 키 값 저장소입니다.
![](/2022/Days/Images/Day49_Kubernetes6.png)
#### kubectl
CLI 관점에서 이를 관리하기 위해 kubectl이 있으며, kubectl은 API 서버와 상호 작용합니다.
Kubernetes 커맨드-라인 도구인 kubectl을 사용하면 Kubernetes 클러스터에 대해 명령을 실행할 수 있습니다. kubectl을 사용하여 애플리케이션을 배포하고, 클러스터 리소스를 검사 및 관리하고, 로그를 볼 수 있습니다.
![](/2022/Days/Images/Day49_Kubernetes7.png)
### Pods
pod는 논리적 애플리케이션을 구성하는 컨테이너 그룹입니다. 예를 들어, NodeJS 컨테이너와 MySQL 컨테이너를 실행하는 웹 애플리케이션이 있는 경우, 이 두 컨테이너는 모두 단일 pod에 위치하게 됩니다. 또한 pod는 공통 데이터 볼륨을 공유할 수 있으며 동일한 네트워킹 네임스페이스도 공유합니다. pod는 임시적이며 마스터 컨트롤러에 의해 위아래로 이동될 수 있다는 것을 기억합시다. Kubernetes는 레이블(이름-값) 개념을 통해 pod를 식별하는 간단하지만, 효과적인 수단을 사용합니다.
- pod는 컨테이너의 볼륨, 시크릿 및 구성을 처리합니다.
- pod는 임시적입니다. 죽으면 자동으로 재시작되도록 설계되었습니다.
- pod는 ReplicationSet에 의해 앱이 수평으로 스케일 될 때 복사됩니다. 각 pod는 동일한 컨테이너 코드를 실행합니다.
- pod는 워커 노드에서 실행됩니다.
![](/2022/Days/Images/Day49_Kubernetes8.png)
### Deployments
- pod를 실행하기로 결정할 수 있지만 죽으면 끝입니다.
- Deployments를 사용하면 pod가 지속적으로 실행될 수 있습니다.
- Deployments를 사용하면 다운타임 없이 실행 중인 앱을 업데이트할 수 있습니다.
- 또한, Deployments는 pod가 죽었을 때 재시작하는 전략을 지정합니다.
![](/2022/Days/Images/Day49_Kubernetes9.png)
### ReplicaSets
- Deployments는 ReplicaSets을 생성할 수도 있습니다.
- ReplicaSets은 앱이 원하는 수의 pod를 갖도록 보장합니다.
- ReplicaSets은 Deployments에 따라 pod를 생성하고 확장합니다.
- Deployments, ReplicaSets, pod는 배타적이지는 않지만 그렇게 될 수 있습니다.
### StatefulSets
- 앱의 상태에 대한 정보를 유지해야 하나요?
- 데이터베이스에는 상태가 필요합니다.
- StatefulSets의 pod는 서로 호환되지 않습니다.
- 각 pod에는 컨트롤러가 모든 스케줄링에 대해 유지하는 고유하고 영구적인 식별자가 있습니다.
![](/2022/Days/Images/Day49_Kubernetes10.png)
### DaemonSets
- DaemonSets은 연속 프로세스를 위한 것입니다.
- 노드당 하나의 pod를 실행합니다.
- 클러스터에 새로운 노드가 추가될 때마다 pod가 시작됩니다.
- 모니터링 및 로그 수집과 같은 백그라운드 작업에 유용합니다.
- 각 pod에는 컨트롤러가 모든 스케줄링에 대해 유지하는 고유하고 영구적인 식별자가 있습니다.
![](/2022/Days/Images/Day49_Kubernetes11.png)
### Services
- pod에 액세스하기 위한 단일 엔드포인트입니다.
- 클러스터와 최종적으로 pod 목록으로 트래픽을 라우팅하는 통합된 방법입니다.
- Services를 사용하면 아무 영향 없이 pod를 올리고 내릴 수 있습니다.
이것은 Kubernetes의 기본 구성 요소에 대한 간략한 개요와 참고 사항일 뿐이며, 이 지식을 바탕으로 스토리지와 Ingress 관련 몇 가지 다른 영역을 추가하여 애플리케이션을 개선할 수 있지만, Kubernetes 클러스터가 실행되는 위치에 대한 선택의 폭도 넓어집니다. 다음 세션에서는 스토리지와 관련된 몇 가지 세부 사항을 살펴보면서 Kubernetes 클러스터를 실행할 수 있는 위치에 대한 이러한 옵션에 중점을 두겠습니다.
![](/2022/Days/Images/Day49_Kubernetes12.png)
### Kubernetes 시리즈에서 다룰 내용
- Kubernetes 아키텍처
- Kubectl 커맨드
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm 패키지 관리자
- 영속성 스토리지
- stateful 앱
## 자료
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
[Day 50](day50.md)에서 봐요!

79
2022/ko/Days/day50.md Normal file
View File

@ -0,0 +1,79 @@
---
title: '#90DaysOfDevOps - Choosing your Kubernetes platform - Day 50'
published: false
description: 90DaysOfDevOps - Choosing your Kubernetes platform
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049046
---
## Kubernetes 플랫폼 선택하기
이 세션을 통해 몇 가지 플랫폼 또는 배포판이라는 용어를 사용하는 것이 더 적합할 수도 있는데, Kubernetes 세계에서 도전 과제 중 하나는 복잡성을 제거하는 것입니다.
Kubernetes 어려운 길은 아무것도 없는 상태에서 완전한 기능을 갖춘 Kubernetes 클러스터로 구축하는 방법을 안내하지만, 적어도 제가 이야기하는 사람들은 점점 더 많은 사람들이 이러한 복잡성을 제거하고 관리형 Kubernetes 클러스터를 실행하기를 원하고 있습니다. 문제는 비용이 더 많이 들지만, 관리형 서비스를 사용하면 기본 노드 아키텍처와 컨트롤 플레인 노드 관점에서 무슨 일이 일어나고 있는지 알아야 하지만 일반적으로 이에 액세스할 수 없는 경우 이점을 누릴 수 있다는 것입니다.
그런 다음 시스템을 사용할 수 있는 로컬 개발 배포판이 있고, 개발자가 의도한 플랫폼에서 앱을 실행할 수 있는 완전한 작업 환경을 갖출 수 있도록 로컬 버전의 Kubernetes를 실행할 수 있습니다.
이 모든 개념의 일반적인 기본은 모두 Kubernetes의 한 종류이므로 요구 사항에 맞게 워크로드를 필요한 곳으로 자유롭게 마이그레이션하고 이동할 수 있어야 한다는 것입니다.
또한 어떤 투자가 이루어졌는지에 따라 많은 선택이 달라질 것입니다. 개발자 경험에 대해서도 언급했지만, 노트북에서 실행되는 로컬 Kubernetes 환경 중 일부는 비용을 들이지 않고도 기술을 익힐 수 있는 훌륭한 환경입니다.
### 베어 메탈 클러스터
많은 사람들이 클러스터를 생성하기 위해 여러 대의 물리적 서버에서 바로 Linux OS를 실행하는 옵션을 선택할 수 있으며, Windows일 수도 있지만 Windows, 컨테이너 및 Kubernetes와 관련된 채택률에 대해서는 많이 듣지 못했습니다. 만약 여러분이 기업이고 물리적 서버를 구매하기로 CAPEX 결정을 내렸다면, Kubernetes 클러스터를 구축할 때 이 방법을 사용할 수 있지만, 관리 및 관리자 측면에서는 여러분이 직접 구축하고 모든 것을 처음부터 관리해야 한다는 것을 의미합니다.
### 가상화
테스트 및 학습 환경이나 엔터프라이즈급 Kubernetes 클러스터에 관계없이 가상화는 일반적으로 가상 머신을 스핀업하여 노드 역할을 하도록 한 다음 함께 클러스터링할 수 있는 훌륭한 방법입니다. 가상화의 기본 아키텍처, 효율성 및 속도를 활용할 수 있을 뿐만 아니라 기존 지출을 활용할 수 있습니다. 예를 들어 VMware는 가상 머신과 Kubernetes 모두를 위한 훌륭한 솔루션을 다양한 형태로 제공합니다.
제가 처음으로 구축한 Kubernetes 클러스터는 몇 개의 VM을 노드로 실행할 수 있는 오래된 서버에서 Microsoft Hyper-V를 사용한 가상화를 기반으로 구축되었습니다.
### 로컬 데스크톱 옵션
데스크톱이나 노트북에서 로컬 Kubernetes 클러스터를 실행하는 데는 몇 가지 옵션이 있습니다. 앞서 말했듯이 개발자는 비용이 많이 들거나 복잡한 클러스터를 여러 개 보유하지 않고도 앱이 어떻게 보일지 확인할 수 있습니다. 개인적으로 저는 이 클러스터를 많이 사용해 왔으며 특히 Minikube를 사용해 왔습니다. 여기에는 무언가를 시작하고 실행하는 방식을 바꾸는 몇 가지 훌륭한 기능과 애드온이 있습니다.
### Kubernetes Managed Services
가상화에 대해 언급했는데, 이는 로컬에서 하이퍼바이저를 통해 달성할 수 있지만 이전 섹션에서 퍼블릭 클라우드의 가상 머신을 활용하여 노드 역할을 할 수도 있다는 것을 알고 있습니다. 여기서 말하는 Kubernetes 관리형 서비스란 대규모 하이퍼스케일러뿐만 아니라 최종 사용자로부터 관리 및 제어 계층을 제거하여 최종 사용자로부터 제어 플레인을 제거하는 MSP에서 제공하는 서비스를 말하며, 이는 Amazon EKS, Microsoft AKS 및 Google Kubernetes Engine에서 일어나는 일입니다. (GKE)
### 압도적인 선택
선택의 폭이 넓다는 것은 좋지만, 위에 나열된 각 카테고리의 모든 옵션에 대해 자세히 살펴본 것은 아닙니다. 위의 옵션 외에도 Red Hat의 OpenShift가 있으며, 이 옵션은 위의 모든 주요 클라우드 제공업체에서 실행할 수 있으며 클러스터가 배포된 위치에 관계없이 관리자에게 최고의 전반적인 사용성을 제공할 수 있습니다.
제가 가상화 경로로 시작했다고 말씀드렸지만, 이는 제가 목적에 맞게 사용할 수 있는 물리적 서버에 액세스할 수 있었기 때문에 감사하게도 그 이후로는 더 이상 이 옵션을 사용할 수 없었습니다.
지금 제가 드리고 싶은 조언은 Minikube를 첫 번째 옵션으로 사용하거나 Kind(Docker의 Kubernetes)를 사용하라는 것이지만, Minikube는 애드온을 사용하고 빠르게 구축한 다음 완료되면 날려버릴 수 있고, 여러 클러스터를 실행할 수 있으며, 거의 모든 곳에서 실행할 수 있고, 크로스 플랫폼 및 하드웨어에 구애받지 않기 때문에 복잡성을 거의 추상화할 수 있는 몇 가지 추가적인 이점을 제공합니다.
저는 Kubernetes에 대해 배우면서 약간의 여정을 거쳤기 때문에 플랫폼 선택과 구체적인 내용은 여기서는 플랫폼인 Kubernetes와 실행 가능한 위치에 대한 이해를 돕기 위해 시도했던 옵션들을 나열해 보겠습니다. 아래 블로그 포스팅을 다시 한번 살펴보고 블로그 게시물에 링크되어 있는 것보다 여기에 더 많이 소개할 수 있도록 하겠습니다.
- [Kubernetes playground How to choose your platform](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-1)
- [Kubernetes playground Setting up your cluster](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-2)
- [Getting started with Amazon Elastic Kubernetes Service (Amazon EKS)](https://vzilla.co.uk/vzilla-blog/getting-started-with-amazon-elastic-kubernetes-service-amazon-eks)
- [Getting started with Microsoft Azure Kubernetes Service (AKS)](https://vzilla.co.uk/vzilla-blog/getting-started-with-microsoft-azure-kubernetes-service-aks)
- [Getting Started with Microsoft AKS Azure PowerShell Edition](https://vzilla.co.uk/vzilla-blog/getting-started-with-microsoft-aks-azure-powershell-edition)
- [Getting started with Google Kubernetes Service (GKE)](https://vzilla.co.uk/vzilla-blog/getting-started-with-google-kubernetes-service-gke)
- [Kubernetes, How to AWS Bottlerocket + Amazon EKS](https://vzilla.co.uk/vzilla-blog/kubernetes-how-to-aws-bottlerocket-amazon-eks)
- [Getting started with CIVO Cloud](https://vzilla.co.uk/vzilla-blog/getting-started-with-civo-cloud)
- [Minikube - Kubernetes Demo Environment For Everyone](https://vzilla.co.uk/vzilla-blog/project_pace-kasten-k10-demo-environment-for-everyone)
### Kubernetes 시리즈에서 다룰 내용
- Kubernetes 아키텍처
- Kubectl 커맨드
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm 패키지 관리자
- 영속성 스토리지
- stateful 앱
## 자료
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
[Day 51](day51.md)에서 봐요!

178
2022/ko/Days/day51.md Normal file
View File

@ -0,0 +1,178 @@
---
title: '#90DaysOfDevOps - Deploying your first Kubernetes Cluster - Day 51'
published: false
description: 90DaysOfDevOps - Deploying your first Kubernetes Cluster
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048778
---
## 첫 번째 Kubernetes 클러스터 배포하기
이 글에서는 Minikube를 사용하여 로컬 머신에서 Kubernetes 클러스터를 시작하고 실행해 보겠습니다. 이렇게 하면 나머지 Kubernetes 섹션을 위한 기본 Kubernetes 클러스터가 제공되지만, 나중에 VirtualBox에서도 Kubernetes 클러스터를 배포하는 방법을 살펴볼 것입니다. 퍼블릭 클라우드에서 관리형 Kubernetes 클러스터를 스핀업하는 대신 이 방법을 선택한 이유는 무료 티어를 사용하더라도 비용이 들기 때문이며, 이전 섹션 [Day 50](day50.md)에서 해당 환경을 스핀업하려는 경우 몇 가지 블로그를 공유한 바 있습니다.
### Minikube란?
> "Minikube는 macOS, Linux, Windows에서 로컬 Kubernetes 클러스터를 빠르게 설정합니다. 우리는 애플리케이션 개발자와 새로운 Kubernetes 사용자를 돕는 데 주력하고 있습니다."
위에 해당되지 않을 수도 있지만, 저는 Minikube가 Kubernetes 방식으로 무언가를 테스트하고 싶을 때 앱을 쉽게 배포할 수 있고 몇 가지 놀라운 애드온이 있다는 것을 알게 되었으며, 이 글에서도 다룰 것입니다.
우선, 워크스테이션 OS에 관계없이 Minikube를 실행할 수 있습니다. 먼저 [프로젝트 페이지](https://minikube.sigs.k8s.io/docs/start/)로 이동합니다. 첫 번째 옵션은 설치 방법을 선택하는 것입니다. 저는 이 방법을 사용하지 않았지만, 여러분은 제가 사용하는 방법과 다른 방법을 선택할 수 있습니다(곧 소개할 예정입니다).
아래에 언급된 "Container or virtual machine managers, such as Docker, Hyper kit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware"가 있어야 한다고 명시되어 있는데, 이것이 Minikube가 실행되는 곳이고 쉬운 옵션이며 저장소에 명시되어 있지 않은 한 저는 Docker를 사용하고 있습니다. 그리고 [여기](https://docs.docker.com/get-docker/)에서 시스템에 Docker를 설치할 수 있습니다.
![](/2022/Days/Images/Day51_Kubernetes1.png)
### Minikube 및 기타 전제조건을 설치하는 방법...
저는 한동안 arkade를 사용하여 모든 Kubernetes 도구와 CLI를 설치해왔는데, arkade를 시작하기 위한 설치 단계는 이 [github 저장소](https://github.com/alexellis/arkade)에서 확인할 수 있습니다. 설치가 필요한 다른 블로그 게시물에서도 언급했습니다. arkade get을 누른 다음 툴이나 CLI를 사용할 수 있는지 확인하는 것만으로도 간단합니다. 리눅스 섹션에서 패키지 관리자와 소프트웨어를 얻는 프로세스에 대해 이야기했는데, arkade는 모든 앱과 Kubernetes용 CLI를 위한 마켓플레이스라고 생각하시면 됩니다. 시스템에서 사용할 수 있는 매우 편리한 작은 도구로, GO로 작성되어 크로스 플랫폼을 지원합니다.
![](/2022/Days/Images/Day51_Kubernetes2.png)
arkade 내에서 사용 가능한 긴 앱 목록의 일부로 Minikube도 그중 하나이므로 간단한 `arkade get minikube` 명령으로 바이너리를 다운로드하고 이제 바로 사용할 수 있습니다.
![](/2022/Days/Images/Day51_Kubernetes3.png)
또한 도구의 일부로 kubectl이 필요하므로 arkade를 통해서도 얻을 수 있으며, 위에서 언급한 curl 명령의 일부로 Minikube 문서에 나와 있다고 생각합니다. 이 포스트의 뒷부분에서 kubectl에 대해 더 자세히 다루겠습니다.
### Kubernetes 클러스터 시작 및 실행하기
이 특정 섹션에서는 로컬 머신에서 Kubernetes 클러스터를 시작하고 실행할 때 사용할 수 있는 옵션에 대해 다루고자 합니다. 다음 명령을 실행하기만 하면 사용할 수 있는 클러스터가 스핀업됩니다.
커맨드라인에 minikube가 사용되며, 모든 설치가 완료되면 `minikube start`를 실행하여 첫 번째 Kubernetes 클러스터를 배포할 수 있습니다. 아래에서 중첩된 가상화 노드를 실행할 위치에 대한 기본값이 Docker 드라이버인 것을 확인할 수 있습니다. 게시물의 시작 부분에서 사용 가능한 다른 옵션에 대해 언급했는데, 다른 옵션은 이 로컬 Kubernetes 클러스터의 모양을 확장하고자 할 때 도움이 됩니다.
이 인스턴스에서는 단일 Minikube 클러스터가 단일 docker 컨테이너로 구성되며, 이 컨테이너에는 컨트롤 플레인 노드와 워커 노드가 하나의 인스턴스에 포함됩니다. 일반적으로는 이러한 노드를 분리합니다. 다음 섹션에서는 아직 홈 랩 유형의 Kubernetes 환경이지만 프로덕션 아키텍처에 조금 더 가까운 환경을 살펴볼 것입니다.
![](/2022/Days/Images/Day51_Kubernetes4.png)
지금까지 몇 번 언급했지만, 저는 사용 가능한 애드온 때문에 Minikube를 좋아하는데, 처음부터 필요한 모든 애드온을 포함한 간단한 명령으로 클러스터를 배포할 수 있기 때문에 매번 동일한 설정을 배포하는 데 도움이 됩니다.
아래에서 이러한 애드온 목록을 볼 수 있는데, 저는 일반적으로 `CSI-host path-driver``volumesnapshots` 애드온을 사용하지만, 아래에서 긴 목록을 볼 수 있습니다. 물론 이러한 애드온은 나중에 Kubernetes 섹션에서 다루겠지만 일반적으로 Helm을 사용하여 배포할 수 있지만 훨씬 더 간단해진다.
![](/2022/Days/Images/Day51_Kubernetes5.png)
또한 프로젝트에서 몇 가지 추가 구성을 정의하고 있는데, apiserver는 임의의 API 포트 대신 6433으로 설정하고 container runtime도 containerd로 정의하고 있지만 기본값은 docker이고 CRI-O도 사용할 수 있습니다. 또한 특정 Kubernetes 버전도 설정하고 있습니다.
![](/2022/Days/Images/Day51_Kubernetes6.png)
이제 Minikube를 사용하여 첫 번째 Kubernetes 클러스터를 배포할 준비가 되었습니다. 클러스터와 상호 작용하려면 `kubectl`도 필요하다고 앞서 언급했습니다. arkade를 사용하여 `arkade get kubectl` 명령으로 kubectl을 설치할 수 있습니다.
![](/2022/Days/Images/Day51_Kubernetes7.png)
또는 다음에서 크로스 플랫폼으로 다운로드할 수 있습니다.
- [리눅스](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux)
- [macOS](https://kubernetes.io/docs/tasks/tools/install-kubectl-macos)
- [윈도우](https://kubernetes.io/docs/tasks/tools/install-kubectl-windows)
kubectl을 설치했으면 `kubectl get nodes`와 같은 간단한 명령으로 클러스터와 상호 작용할 수 있습니다.
![](/2022/Days/Images/Day51_Kubernetes8.png)
### kubectl이란?
이제 Minikube와 Kubernetes 클러스터를 모두 설치하고 실행 중이며, Minikube에 대해서는 최소한 Minikube가 무엇을 하는지에 대해 설명했지만, kubectl이 무엇이고 어떤 역할을 하는지에 대해서는 설명하지 않았습니다.
kubectl은 Kubernetes 클러스터와 상호 작용하는 데 사용되거나 상호 작용할 수 있게 해주는 클리어로, 여기서는 Minikube 클러스터와 상호 작용하는 데 사용하고 있지만 퍼블릭 클라우드 전반의 엔터프라이즈 클러스터와 상호 작용하는 데도 kubectl을 사용할 수 있습니다.
우리는 애플리케이션을 배포하고 클러스터 리소스를 검사 및 관리하기 위해 kubectl을 사용합니다. 훨씬 더 자세한 개요는 Kubernetes [공식 문서](https://kubernetes.io/docs/reference/kubectl/overview/)에서 확인할 수 있습니다.
kubectl은 이전 포스트에서 간략하게 다룬 컨트롤 플레인 노드에 있는 API 서버와 상호작용합니다.
### kubectl 치트 시트
공식 문서와 함께, 필자는 kubectl 명령어를 찾을 때 [이 페이지](https://unofficial-kubernetes.readthedocs.io/en/latest/)를 항상 열어두는 것을 추천합니다.
| Listing Resources | |
| ------------------------ | ------------------------------------------ |
| kubectl get nodes | 클러스터의 모든 노드 나열 |
| kubectl get namespaces | 클러스터의 모든 네임스페이스 나열 |
| kubectl get pods | 기본 네임스페이스 클러스터에 모든 pod 나열 |
| kubectl get pods -n name | "이름" 네임스페이스에 모든 pod를 나열 |
| Creating Resources | |
| ----------------------------- | ------------------------------------------ |
| kubectl create namespace name | "name"이라는 네임스페이스를 생성 |
| kubectl create -f [filename] | JSON 또는 YAML 파일에서 리소스를 다시 생성 |
| Editing Resources | |
| ---------------------------- | ------------- |
| kubectl edit svc/servicename | 서비스를 편집 |
| More detail on Resources | |
| ------------------------ | ------------------------------------- |
| kubectl describe nodes | 원하는 수의 리소스 상태를 자세히 표시 |
| Delete Resources | |
| ------------------ | --------------------------------------------------------- |
| kubectl delete pod | 리소스를 제거할 수 있으며, 이는 stdin 또는 파일에서 제거. |
예를 들어 `-n``namespace`의 줄임말로, 명령을 입력하기 쉬울 뿐만 아니라 스크립트를 작성할 때 훨씬 더 깔끔한 코드를 만들 수 있습니다.
| Short name | Full name |
| ---------- | -------------------------- |
| csr | certificatesigningrequests |
| cs | componentstatuses |
| cm | configmaps |
| ds | daemonsets |
| deploy | deployments |
| ep | endpoints |
| ev | events |
| hpa | horizontalpodautoscalers |
| ing | ingresses |
| limits | limitranges |
| ns | namespaces |
| no | nodes |
| pvc | persistentvolumeclaims |
| pv | persistentvolumes |
| po | pods |
| pdb | poddisruptionbudgets |
| psp | podsecuritypolicies |
| rs | replicasets |
| rc | replicationcontrollers |
| quota | resourcequotas |
| sa | serviceaccounts |
| svc | services |
마지막으로 추가하고 싶은 것은 데이터 서비스를 표시하기 위해 데모 환경을 빠르게 스핀업하고 Kasten K10으로 이러한 워크로드를 보호하기 위해 Minikube와 관련된 또 다른 프로젝트를 만들었습니다. [Project Pace](https://github.com/MichaelCade/project_pace)는 여기에서 찾을 수 있으며 여러분의 피드백이나 상호 작용을 원하며 Minikube 클러스터를 배포하고 다양한 데이터 서비스 애플리케이션을 만드는 몇 가지 자동화된 방법을 표시하거나 포함합니다.
다음에는 VirtualBox를 사용하여 여러 노드를 가상 머신에 배포하는 방법을 살펴보겠지만, Linux 섹션에서 vagrant를 사용하여 머신을 빠르게 스핀업하고 원하는 방식으로 소프트웨어를 배포했던 것처럼 여기에서도 쉽게 진행할 것입니다.
어제 포스트에 배포 중인 다양한 Kubernetes 클러스터에 대해 제가 수행한 워크스루 블로그인 이 목록을 추가했습니다.
- [Kubernetes playground How to choose your platform](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-1)
- [Kubernetes playground Setting up your cluster](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-2)
- [Getting started with Amazon Elastic Kubernetes Service (Amazon EKS)](https://vzilla.co.uk/vzilla-blog/getting-started-with-amazon-elastic-kubernetes-service-amazon-eks)
- [Getting started with Microsoft Azure Kubernetes Service (AKS)](https://vzilla.co.uk/vzilla-blog/getting-started-with-microsoft-azure-kubernetes-service-aks)
- [Getting Started with Microsoft AKS Azure PowerShell Edition](https://vzilla.co.uk/vzilla-blog/getting-started-with-microsoft-aks-azure-powershell-edition)
- [Getting started with Google Kubernetes Service (GKE)](https://vzilla.co.uk/vzilla-blog/getting-started-with-google-kubernetes-service-gke)
- [Kubernetes, How to AWS Bottlerocket + Amazon EKS](https://vzilla.co.uk/vzilla-blog/kubernetes-how-to-aws-bottlerocket-amazon-eks)
- [Getting started with CIVO Cloud](https://vzilla.co.uk/vzilla-blog/getting-started-with-civo-cloud)
- [Minikube - Kubernetes Demo Environment For Everyone](https://vzilla.co.uk/vzilla-blog/project_pace-kasten-k10-demo-environment-for-everyone)
- [Minikube - Deploy Minikube Using Vagrant and Ansible on VirtualBox](https://medium.com/techbeatly/deploy-minikube-using-vagrant-and-ansible-on-virtualbox-infrastructure-as-code-2baf98188847)
### Kubernetes 시리즈에서 다룰 내용
아래에 언급된 내용 중 일부를 다루기 시작했지만, 내일 두 번째 클러스터 배포를 통해 더 많은 실습을 한 후 클러스터에 애플리케이션 배포를 시작할 수 있습니다.
- Kubernetes 아키텍처
- Kubectl 커맨드
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm 패키지 관리자
- 영속성 스토리지
- stateful 앱
## 자료
사용하신 무료 리소스가 있다면 리포지토리에 PR을 통해 여기에 추가해 주시면 기꺼이 포함시켜드리겠습니다.
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
- [Techbeatly - Deploy Minikube Using Vagrant and Ansible on VirtualBox](https://www.youtube.com/watch?v=xPLQqHbp9BM&t=371s)
[Day 52](day52.md)에서 봐요!

182
2022/ko/Days/day52.md Normal file
View File

@ -0,0 +1,182 @@
---
title: '#90DaysOfDevOps - Setting up a multinode Kubernetes Cluster - Day 52'
published: false
description: 90DaysOfDevOps - Setting up a multinode Kubernetes Cluster
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049050
---
## 멀티노드 Kubernetes 클러스터 설정하기
이 제목을 "Vagrant로 멀티노드 Kubernetes 클러스터 설정하기"로 하고 싶었지만, 너무 길 것 같았습니다!
어제 세션에서는 멋진 프로젝트를 사용하여 첫 번째 Kubernetes 클러스터를 배포하고 Kubernetes를 사용할 때 접하게 될 가장 중요한 CLI 도구(kubectl)를 조금 실습해 보았습니다.
여기서는 VirtualBox를 기본으로 사용하지만, 지난번 리눅스 섹션에서 Vagrant에 대해 이야기할 때 언급했듯이 지원되는 모든 하이퍼바이저 또는 가상화 도구를 사용할 수 있습니다. 리눅스 섹션에서 우분투 머신을 배포한 것은 [Day 14](day14.md)였습니다.
### Vagrant에 대한 간략한 요약
Vagrant는 가상 머신의 라이프사이클을 관리하는 CLI 유틸리티입니다. vSphere, Hyper-v, Virtual Box, Docker 등 다양한 플랫폼에서 가상 머신을 스핀업 및 스핀다운하는 데 Vagrant를 사용할 수 있습니다. 다른 공급업체도 있지만 여기서는 Virtual Box를 사용하고 있으므로 계속 사용하겠습니다.
이 [블로그 및 리포지토리](https://devopscube.com/kubernetes-cluster-vagrant/)를 기준으로 하여 구성을 안내해 드리겠습니다. 하지만 Kubernetes 클러스터를 처음 배포하는 경우라면 수동으로 이 작업을 수행하는 방법도 살펴보고 최소한 어떤 모습인지 알고 계실 것을 권해드리고 싶습니다. Kubernetes는 릴리스될 때마다 더욱 효율적으로 개선되고 있다고 말씀드리고 싶습니다. 저는 이것을 VMware와 ESX 시절에 비유하자면, ESX 서버 3대를 배포하는 데 적어도 하루는 필요했지만, 지금은 한 시간 안에 이를 실행할 수 있습니다. 저희는 Kubernetes와 관련해서는 그 방향으로 나아가고 있습니다.
### Kubernetes 랩 환경
환경을 구축하는 데 사용할 vagrantfile을 [Kubernetes 폴더](/2022/Days/Kubernetes)에 업로드했습니다. 이 파일을 잡고 터미널에서 이 디렉토리로 이동합니다. 저는 다시 Windows를 사용하므로 PowerShell을 사용하여 vagrant로 워크스테이션 명령을 수행하겠습니다. vagrant가 없는 경우 어제 Minikube 및 기타 도구를 설치할 때 다룬 arkade를 사용할 수 있습니다. 간단한 명령어인 `arkade get vagrant`를 실행하면 최신 버전의 vagrant를 다운로드하여 설치할 수 있습니다.
디렉토리에 들어가면 `vagrant up`을 실행하고 모든 것이 올바르게 구성되었다면 터미널에 다음과 같은 킥오프가 표시됩니다.
![](/2022/Days/Images/Day52_Kubernetes1.png)
터미널에서 몇 가지 단계가 진행되는 것을 볼 수 있지만, 그동안 우리가 여기서 무엇을 빌드하고 있는지 살펴봅시다.
![](/2022/Days/Images/Day52_Kubernetes2.png)
위에서 보면 3개의 가상 머신을 빌드하고 컨트롤 플레인 노드와 두 개의 워커 노드가 있다는 것을 알 수 있습니다. [Day 49](day49.md)로 돌아가면 이미지에서 볼 수 있는 이러한 영역에 대한 설명이 더 있습니다.
또한 이미지에서는 클러스터 외부에서 kubectl 액세스가 발생하여 해당 kube apiserver에 도달하는 것으로 표시되어 있지만, 실제로는 vagrant 프로비저닝의 일부로 각 노드 내에서 클러스터에 액세스할 수 있도록 각 노드에 kubectl을 배포하고 있습니다.
이 실습을 구축하는 과정은 설정에 따라 5분에서 30분 정도 걸릴 수 있습니다.
곧 스크립트에 대해서도 다룰 예정이지만, 배포의 일부로 3개의 스크립트를 호출하는 vagrant 파일을 보면 클러스터가 실제로 생성되는 곳이라는 것을 알 수 있습니다. Vagrant boxes를 사용하여 가상 머신과 OS 설치를 배포하는 것이 얼마나 쉬운지 살펴보았지만, 배포 프로세스의 일부로 셸 스크립트를 실행할 수 있는 기능이 있다는 것은 이러한 실습 빌드 아웃 자동화와 관련하여 매우 흥미로운 부분입니다.
완료되면 터미널에서 노드 중 하나에 `vagrant ssh master`로 접속하면 액세스할 수 있으며, 기본 사용자 이름과 비밀번호는 `vagrant/vagrant`입니다.
원하는 경우 `vagrant ssh node01``vagrant ssh node02`를 사용하여 작업자 노드에 액세스할 수도 있습니다.
![](/2022/Days/Images/Day52_Kubernetes3.png)
이제 새 클러스터의 위 노드 중 하나에서 `kubectl get nodes`를 실행하여 3노드 클러스터와 그 상태를 확인할 수 있습니다.
![](/2022/Days/Images/Day52_Kubernetes4.png)
이 시점에서, 컨트롤 플레인 노드 1개와 워커 노드 2개로 구성된 3노드 클러스터가 실행되고 있습니다.
### Vagrant 파일 및 셸 스크립트 연습
vagrantfile을 살펴보면 여러 작업자 노드, VirtualBox 내의 브리지 네트워크에 대한 네트워킹 IP 주소, 그리고 일부 이름 지정을 정의하고 있음을 알 수 있습니다. 또한 특정 호스트에서 실행하려는 일부 스크립트를 호출하고 있음을 알 수 있습니다.
```shell
NUM_WORKER_NODES=2
IP_NW="10.0.0."
IP_START=10
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: <<-SHELL
apt-get update -y
echo "$IP_NW$((IP_START)) master-node" >> /etc/hosts
echo "$IP_NW$((IP_START+1)) worker-node01" >> /etc/hosts
echo "$IP_NW$((IP_START+2)) worker-node02" >> /etc/hosts
SHELL
config.vm.box = "bento/ubuntu-21.10"
config.vm.box_check_update = true
config.vm.define "master" do |master|
master.vm.hostname = "master-node"
master.vm.network "private_network", ip: IP_NW + "#{IP_START}"
master.vm.provider "virtualbox" do |vb|
vb.memory = 4048
vb.cpus = 2
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
master.vm.provision "shell", path: "scripts/common.sh"
master.vm.provision "shell", path: "scripts/master.sh"
end
(1..NUM_WORKER_NODES).each do |i|
config.vm.define "node0#{i}" do |node|
node.vm.hostname = "worker-node0#{i}"
node.vm.network "private_network", ip: IP_NW + "#{IP_START + i}"
node.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 1
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
node.vm.provision "shell", path: "scripts/common.sh"
node.vm.provision "shell", path: "scripts/node.sh"
end
end
end
```
실행 중인 스크립트를 분석해 보겠습니다. 특정 노드에서 실행할 세 개의 스크립트가 위의 VAGRANTFILE에 나열되어 있습니다.
`master.vm.provision "shell", path: "scripts/common.sh"`
위의 스크립트는 노드를 준비하는 데 초점을 맞출 것이며, 3개의 노드 모두에서 실행될 것이며, 기존의 모든 Docker 구성 요소를 제거하고 Docker와 ContainerD는 물론 kubeadm, kubelet 및 kubectl을 다시 설치합니다. 이 스크립트는 또한 시스템의 기존 소프트웨어 패키지도 업데이트합니다.
`master.vm.provision "shell", path: "scripts/master.sh"`
master.sh 스크립트는 컨트롤 플레인 노드에서만 실행되며, 이 스크립트는 kubeadm 커맨드를 사용하여 Kubernetes 클러스터를 생성합니다. 또한 이 클러스터에 대한 액세스를 위한 구성 컨텍스트도 준비할 것이며, 이는 다음에 다룰 것입니다.
`node.vm.provision "shell", path: "scripts/node.sh"`
이것은 단순히 마스터가 생성한 구성을 가져와서 우리 노드를 Kubernetes 클러스터에 추가하는 것이며, 이 추가 프로세스는 다시 kubeadm과 config 폴더에서 찾을 수 있는 다른 스크립트를 사용합니다.
### Kubernetes 클러스터에 액세스하기
이제 두 개의 클러스터가 배포되었습니다. 이전 섹션에서 배포한 Minikube 클러스터와 방금 VirtualBox에 배포한 새로운 3노드 클러스터가 있습니다.
또한 vagrant를 실행한 머신에서도 액세스할 수 있는 구성 파일에는 워크스테이션에서 클러스터에 액세스하는 방법이 포함되어 있습니다.
이를 보여드리기 전에 컨텍스트에 대해 말씀드리겠습니다.
![](/2022/Days/Images/Day52_Kubernetes5.png)
컨텍스트가 중요하며, 데스크톱이나 노트북에서 Kubernetes 클러스터에 액세스할 수 있는 기능이 필요합니다. 다양한 옵션이 존재하며 사람들은 각기 다른 운영 체제를 일상적으로 사용합니다.
기본적으로, Kubernetes CLI 클라이언트(kubectl)는 엔드포인트 및 자격 증명과 같은 Kubernetes 클러스터 세부 정보를 저장하기 위해 C:\Users\username.kube\config를 사용합니다. 클러스터를 배포한 경우 해당 위치에서 이 파일을 볼 수 있습니다. 하지만 지금까지 마스터 노드에서 SSH 또는 다른 방법을 통해 모든 kubectl 명령을 실행했다면 이 포스팅이 워크스테이션과 연결할 수 있는 방법을 이해하는 데 도움이 되길 바랍니다.
그런 다음 클러스터에서 kubeconfig 파일을 가져오거나 배포된 구성 파일에서 가져올 수도 있고, SCP를 통해 이 파일의 내용을 가져오거나 마스터 노드에 콘솔 세션을 열고 로컬 윈도우 머신에 복사할 수도 있습니다.
![](/2022/Days/Images/Day52_Kubernetes6.png)
그런 다음 해당 구성 파일의 복사본을 가져와서 `$HOME/.kube/config` 위치로 이동합니다.
![](/2022/Days/Images/Day52_Kubernetes7.png)
이제 로컬 워크스테이션에서 `kubectl cluster-info``kubectl get nodes`를 실행하여 클러스터에 액세스할 수 있는지 확인할 수 있습니다.
![](/2022/Days/Images/Day52_Kubernetes8.png)
이렇게 하면 윈도우 머신에서 연결 및 제어가 가능할 뿐만 아니라 윈도우 머신에서 특정 서비스에 액세스하기 위해 포트 포워딩을 수행할 수 있습니다.
워크스테이션에서 여러 클러스터를 관리하는 방법에 관심이 있으시다면 [여기](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-6)에 더 자세한 안내가 있습니다.
이 목록은 제가 배포 중인 다양한 Kubernetes 클러스터에 대해 수행한 워크스루 블로그입니다.
- [Kubernetes playground How to choose your platform](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-1)
- [Kubernetes playground Setting up your cluster](https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-2)
- [Getting started with Amazon Elastic Kubernetes Service (Amazon EKS)](https://vzilla.co.uk/vzilla-blog/getting-started-with-amazon-elastic-kubernetes-service-amazon-eks)
- [Getting started with Microsoft Azure Kubernetes Service (AKS)](https://vzilla.co.uk/vzilla-blog/getting-started-with-microsoft-azure-kubernetes-service-aks)
- [Getting Started with Microsoft AKS Azure PowerShell Edition](https://vzilla.co.uk/vzilla-blog/getting-started-with-microsoft-aks-azure-powershell-edition)
- [Getting started with Google Kubernetes Service (GKE)](https://vzilla.co.uk/vzilla-blog/getting-started-with-google-kubernetes-service-gke)
- [Kubernetes, How to AWS Bottlerocket + Amazon EKS](https://vzilla.co.uk/vzilla-blog/kubernetes-how-to-aws-bottlerocket-amazon-eks)
- [Getting started with CIVO Cloud](https://vzilla.co.uk/vzilla-blog/getting-started-with-civo-cloud)
- [Minikube - Kubernetes Demo Environment For Everyone](https://vzilla.co.uk/vzilla-blog/project_pace-kasten-k10-demo-environment-for-everyone)
### Kubernetes 시리즈에서 다룰 내용
아래에 언급된 내용 중 일부를 다루기 시작했지만, 내일 두 번째 클러스터 배포를 통해 더 많은 실습을 한 다음 클러스터에 애플리케이션 배포를 시작할 수 있습니다.
- Kubernetes 아키텍처
- Kubectl 커맨드
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm 패키지 관리자
- 영속성 스토리지
- stateful 앱
## 자료
사용하신 무료 리소스가 있으시면 리포지토리에 PR을 통해 여기에 추가해 주시면 기꺼이 포함시켜 드리겠습니다.
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
[Day 53](day53.md)에서 봐요!

129
2022/ko/Days/day53.md Normal file
View File

@ -0,0 +1,129 @@
---
title: '#90DaysOfDevOps - Rancher Overview - Hands On - Day 53'
published: false
description: 90DaysOfDevOps - Rancher Overview - Hands On
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048742
---
## Rancher 개요 - 핸즈온
이 섹션에서는 Rancher에 대해 살펴볼 것인데, 지금까지는 클러스터 관리에 대한 좋은 가시성을 운영팀에 제공하는 몇 가지 좋은 UI와 멀티클러스터 관리 도구가 있지만, 지금까지 한 모든 작업은 cli와 kubectl을 사용했습니다.
Rancher는 [사이트](https://rancher.com/)에 따르면
> Rancher는 컨테이너를 도입하는 팀을 위한 완벽한 소프트웨어 스택입니다. 이 스택은 모든 인프라에서 여러 개의 Kubernetes 클러스터를 관리할 때 발생하는 운영 및 보안 문제를 해결하는 동시에 데브옵스 팀에 컨테이너화된 워크로드를 실행하기 위한 통합 도구를 제공합니다.
Rancher를 사용하면 거의 모든 위치에서 프로덕션급 Kubernetes 클러스터를 배포할 수 있으며 중앙 집중식 인증, 액세스 제어 및 통합 가시성을 제공합니다. 이전 섹션에서 Kubernetes와 관련하여 거의 압도적인 선택의 폭이 있으며, 어디에서 실행해야 하는지 또는 실행할 수 있는지에 대해 언급했지만, Rancher를 사용하면 어디에 있든 상관없습니다.
### Rancher 배포
가장 먼저 해야 할 일은 로컬 워크스테이션에 Rancher를 배포하는 것입니다. 이 단계를 진행하기 위해 선택할 수 있는 몇 가지 방법과 위치가 있는데, 저는 로컬 워크스테이션을 사용하고 Rancher를 docker 컨테이너로 실행하고 싶습니다. 아래 명령을 실행하면 컨테이너 이미지를 가져온 다음 Rancher UI에 액세스할 수 있습니다.
다른 Rancher 배포 방법은 [Rancher 빠른 시작 가이드](https://rancher.com/docs/rancher/v2.6/en/quick-start-guide/deployment/)에서 확인할 수 있습니다.
`sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 --privileged rancher/rancher`
docker 데스크톱에서 볼 수 있듯이 실행 중인 Rancher 컨테이너가 있습니다.
![](/2022/Days/Images/Day53_Kubernetes1.png)
### Rancher UI 액세스
위의 컨테이너가 실행 중이면 웹 페이지를 통해 컨테이너로 이동할 수 있어야 합니다. `https://localhost`를 입력하면 아래와 같이 로그인 페이지가 나타납니다.
![](/2022/Days/Images/Day53_Kubernetes2.png)
아래 안내에 따라 필요한 비밀번호를 입력합니다. 저는 Windows를 사용하고, grep 명령이 필요하기 때문에 Windows용 bash를 사용하기로 했습니다.
![](/2022/Days/Images/Day53_Kubernetes3.png)
이제 위의 비밀번호를 사용하여 로그인하면 다음 페이지에서 새 비밀번호를 정의할 수 있습니다.
![](/2022/Days/Images/Day53_Kubernetes4.png)
위의 작업을 완료하면 로그인이 완료되고 시작 화면을 볼 수 있습니다. Rancher 배포의 일부로 로컬 K3 클러스터가 프로비저닝된 것도 볼 수 있습니다.
![](/2022/Days/Images/Day53_Kubernetes5.png)
### Rancher에 대한 간략한 둘러보기
가장 먼저 살펴볼 것은 로컬로 배포된 K3S 클러스터입니다. 아래에서 클러스터 내부에서 어떤 일이 일어나고 있는지 잘 볼 수 있습니다. 이것은 기본 배포이며 아직 이 클러스터에 아무것도 배포하지 않았습니다. 1개의 노드로 구성되어 있고 5개의 배포가 있는 것을 볼 수 있습니다. 그리고 pod, 코어, 메모리에 대한 몇 가지 통계가 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day53_Kubernetes6.png)
왼쪽 메뉴에는 앱 및 마켓플레이스 탭도 있는데, 이 탭을 통해 클러스터에서 실행할 애플리케이션을 선택할 수 있습니다. 앞서 언급했듯이 Rancher는 여러 개의 다른 클러스터를 실행하거나 관리할 수 있는 기능을 제공합니다. 마켓플레이스를 사용하면 애플리케이션을 매우 쉽게 배포할 수 있습니다.
![](/2022/Days/Images/Day53_Kubernetes7.png)
또 한 가지 언급할 것은 오른쪽 상단에 있는 Rancher에서 관리 중인 클러스터에 액세스해야 하는 경우 선택한 클러스터에 대한 kubectl 셸을 열 수 있다는 것입니다.
![](/2022/Days/Images/Day53_Kubernetes8.png)
### 새 클러스터 생성
지난 두 세션에 걸쳐 로컬에서 Minikube 클러스터를 생성하고 가상박스와 함께 Vagrant를 사용하여 3노드 Kubernetes 클러스터를 생성했으며, Rancher를 사용하여 클러스터를 생성할 수도 있습니다. [Rancher 폴더](/2022/Days/Kubernetes/Rancher)에는 동일한 3개의 노드를 구축할 수 있는 추가 vagrant 파일이 있지만 Kubernetes 클러스터를 생성하는 단계가 없습니다(Rancher가 이 작업을 대신 수행하기를 원합니다).
그러나 각 노드에서 `common.sh` 스크립트가 계속 실행되는 것을 볼 수 있도록 docker가 설치되고 OS가 업데이트되기를 원합니다. 이것은 또한 Kubeadm, Kubectl 등을 설치합니다. 그러나 노드를 클러스터로 생성하고 조인하기 위한 Kubeadm 명령은 실행되지 않습니다.
vagrant 폴더 위치로 이동하여 `vagrant up`을 실행하기만 하면 가상 박스에서 3개의 가상 머신을 생성하는 프로세스가 시작됩니다.
![](/2022/Days/Images/Day53_Kubernetes9.png)
이제 노드 또는 VM이 제자리에 배치되고 준비되었으므로 Rancher를 사용하여 새로운 Kubernetes 클러스터를 생성할 수 있습니다. 클러스터를 생성하는 첫 번째 화면에서는 클러스터가 어디에 있는지, 즉 퍼블릭 클라우드 관리형 Kubernetes 서비스를 사용 중인지, vSphere 또는 다른 것을 사용 중인지에 대한 몇 가지 옵션을 제공합니다.
![](/2022/Days/Images/Day53_Kubernetes10.png)
통합 플랫폼 중 하나를 사용하지 않으므로 "custom"을 선택하겠습니다. 시작 페이지는 클러스터 이름을 정의하는 곳입니다(아래에 로컬이라고 되어 있지만 로컬을 사용할 수 없습니다. 저희 클러스터는 vagrant라고 합니다.) 여기에서 Kubernetes 버전, 네트워크 공급자 및 기타 구성 옵션을 정의하여 Kubernetes 클러스터를 시작하고 실행할 수 있습니다.
![](/2022/Days/Images/Day53_Kubernetes11.png)
다음 페이지에서는 활성화할 적절한 서비스와 함께 각 노드에서 실행해야 하는 등록 코드(etcd, 컨트롤 플레인 및 워커)를 제공합니다. 마스터 노드의 경우, etcd와 컨트롤 플레인이 필요하므로 명령은 아래와 같습니다.
![](/2022/Days/Images/Day53_Kubernetes12.png)
```
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.6.3 --server https://10. 0.0.1 --token mpq8cbjjwrj88z4xmf7blqxcfmwdsmq92bmwjpphdkklfckk5hfwc2 --ca-checksum a81944423cbfeeb92be0784edebba1af799735ebc30ba8cbe5cc5f996094f30b --etcd --controlplane
```
네트워킹이 올바르게 구성되었다면, 이제 첫 번째 마스터 노드가 등록되고 클러스터가 생성되고 있음을 나타내는 Rancher 대시보드에 다음과 같이 빠르게 표시되어야 합니다.
![](/2022/Days/Images/Day53_Kubernetes13.png)
그런 다음 다음 명령으로 각 워커 노드에 대한 등록 프로세스를 반복하면 얼마 후 마켓플레이스를 활용하여 애플리케이션을 배포할 수 있는 클러스터를 실행할 수 있게 됩니다.
```
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.6.3 --server https://10. 0.0.1 --token mpq8cbjjwrj88z4xmf7blqxcfmwdsmq92bmwjpphdkklfckk5hfwc2 --ca-checksum a81944423cbfeeb92be0784edebba1af799735ebc30ba8cbe5cc5f996094f30b --worker
```
![](/2022/Days/Images/Day53_Kubernetes14.png)
지난 세 세션 동안, 우리는 몇 가지 다른 방법으로 Kubernetes 클러스터를 시작하고 실행하는 방법을 사용했으며, 남은 날에는 플랫폼에서 가장 중요한 애플리케이션 측면을 살펴볼 것입니다. 서비스 프로비저닝과 Kubernetes에서 서비스를 프로비저닝하고 사용할 수 있는 방법에 대해 살펴보겠습니다.
부트스트랩 Rancher 노드에 대한 요구사항에 따라 해당 VM에 4GB 램이 있어야 하며 그렇지 않으면 크래시 루프가 발생한다고 들었는데, 이후 워커 노드에 2GB가 있는 것으로 업데이트했습니다.
### Kubernetes 시리즈에서 다룰 내용
아래에 언급된 내용 중 일부를 다루기 시작했지만, 내일 두 번째 클러스터 배포를 통해 더 많은 실습을 한 다음 클러스터에 애플리케이션 배포를 시작할 수 있습니다.
- Kubernetes 아키텍처
- Kubectl 커맨드
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm 패키지 관리자
- 영속성 스토리지
- stateful 앱
## 자료
사용하신 무료 리소스가 있으시면 리포지토리에 PR을 통해 여기에 추가해 주시면 기꺼이 포함시켜 드리겠습니다.
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
[Day 54](day54.md)에서 봐요!

223
2022/ko/Days/day54.md Normal file
View File

@ -0,0 +1,223 @@
---
title: '#90DaysOfDevOps - Kubernetes Application Deployment - Day 54'
published: false
description: 90DaysOfDevOps - Kubernetes Application Deployment
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048764
---
## Kubernetes 애플리케이션 배포
이제 드디어 일부 애플리케이션을 클러스터에 배포하게 되었는데, 일부 사람들은 이것이 바로 애플리케이션 배포를 위해 Kubernetes가 존재하는 이유라고 말할 수 있습니다.
여기서 아이디어는 컨테이너 이미지를 가져와서 이제 컨테이너 오케스트레이터로서 Kubernetes를 활용하기 위해 컨테이너 이미지를 Kubernetes 클러스터에 pod로 배포할 수 있다는 것입니다.
### Kubernetes에 앱 배포하기
애플리케이션을 Kubernetes 클러스터에 배포하는 방법에는 여러 가지가 있지만, 가장 일반적인 두 가지 접근 방식인 YAML 파일과 Helm 차트를 다뤄보겠습니다.
이러한 애플리케이션 배포에는 Minikube 클러스터를 사용할 것입니다. 앞서 언급한 Kubernetes의 구성 요소 또는 빌딩 블록 중 일부를 살펴볼 것입니다.
이 섹션과 컨테이너 섹션을 통해 이미지와 Kubernetes의 장점, 그리고 이 플랫폼에서 확장을 매우 쉽게 처리할 수 있는 방법에 대해 논의했습니다.
이 첫 번째 단계에서는 Minikube 클러스터 내에 상태 비저장 애플리케이션을 간단히 생성해 보겠습니다. 사실상의 표준 상태 비저장 애플리케이션인 `nginx`를 사용하여 첫 번째 데모에서 배포를 구성하여 pod를 제공한 다음 nginx pod에서 호스팅하는 간단한 웹 서버로 이동할 수 있는 서비스도 생성할 것입니다. 이 모든 것이 네임스페이스에 포함될 것입니다.
![](/2022/Days/Images/Day54_Kubernetes1.png)
### YAML 생성
첫 번째 데모에서는 YAML로 수행하는 모든 작업을 정의하고자 합니다. YAML에 대한 전체 섹션이 있을 수 있지만, 여기서는 간략히 살펴보고 마지막에 YAML을 더 자세히 다룰 몇 가지 리소스를 남겨두려고 합니다.
다음을 하나의 YAML 파일로 만들 수도 있고, 애플리케이션의 각 측면별로 나눌 수도 있습니다. 즉, 네임스페이스, 배포 및 서비스 생성을 위한 별도의 파일일 수 있지만 이 파일에서는 아래에서 `---`를 사용하여 하나의 파일로 구분했습니다. 이 파일은 [여기](/2022/Days/Kubernetes)에서 찾을 수 있습니다(파일명:- nginx-stateless-demo.YAML).
```Yaml
apiVersion: v1
kind: Namespace
metadata:
name: nginx
"labels": {
"name": "nginx"
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: nginx
spec:
selector:
app: nginx-deployment
ports:
- protocol: TCP
port: 80
targetPort: 80
```
### 클러스터 확인
배포하기 전에 `nginx`라는 네임스페이스가 없는지 확인해야 하는데, `kubectl get namespace` 명령을 실행하여 확인할 수 있으며, 아래에서 볼 수 있듯이 `nginx`라는 네임스페이스가 없습니다.
![](/2022/Days/Images/Day54_Kubernetes2.png)
### 앱을 배포할 시간
이제 Minikube 클러스터에 애플리케이션을 배포할 준비가 되었으며, 이 프로세스는 다른 모든 Kubernetes 클러스터에서도 동일하게 작동합니다.
YAML 파일 위치로 이동한 다음 `kubectl create -f nginx-stateless-demo.yaml`을 실행하면 3개의 오브젝트가 생성되고 네임스페이스, 배포 및 서비스가 생성된 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes3.png)
클러스터에서 사용 가능한 네임스페이스를 확인하기 위해 `kubectl get namespace` 명령을 다시 실행하면 이제 새 네임스페이스가 있는 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes5.png)
이제 `kubectl get pods -n nginx`를 사용하여 네임스페이스에 pod가 있는지 확인하면 준비 및 실행 상태의 pod 1개가 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes4.png)
또한 `kubectl get service -n nginx`를 실행하여 서비스가 생성되었는지 확인할 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes6.png)
마지막으로, 배포를 확인하여 원하는 구성을 어디에 어떻게 유지하는지 확인할 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes7.png)
위는 몇 가지 알아두면 좋은 명령어를 사용했지만, `kubectl get all -n nginx`를 사용하여 하나의 YAML 파일로 배포한 모든 것을 볼 수도 있습니다.
![](/2022/Days/Images/Day54_Kubernetes8.png)
위 그림에서 replicaset가 있는 것을 볼 수 있는데, 배포에서 배포할 이미지의 레플리카 개수를 정의합니다. 처음에는 1로 설정되었지만, 애플리케이션을 빠르게 확장하려면 여러 가지 방법으로 확장할 수 있습니다.
터미널 내에서 텍스트 편집기를 열고 배포를 수정할 수 있는 `kubectl edit deployment nginx-deployment -n nginx`를 사용하여 파일을 편집할 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes9.png)
터미널 내의 텍스트 편집기에서 위의 내용을 저장했을 때 문제가 없고 올바른 서식이 사용되었다면 네임스페이스에 추가로 배포된 것을 볼 수 있을 것입니다.
![](/2022/Days/Images/Day54_Kubernetes10.png)
또한 kubectl과 `kubectl scale deployment nginx-deployment --replicas=10 -n nginx`를 사용하여 레플리카 수를 변경할 수 있습니다.
![](/2022/Days/Images/Day54_Kubernetes11.png)
두 방법 중 하나를 사용하려는 경우 이 방법을 사용하여 애플리케이션을 다시 1로 축소할 수 있습니다. 저는 편집 옵션을 사용했지만, 위의 스케일 명령을 사용할 수도 있습니다.
![](/2022/Days/Images/Day54_Kubernetes12.png)
여기서 사용 사례를 통해 매우 빠르게 스핀업 및 스핀다운할 수 있을 뿐만 아니라 애플리케이션을 빠르게 확장 및 축소할 수 있다는 것을 알 수 있기를 바랍니다. 이것이 웹 서버라면 부하가 많을 때는 확장하고 부하가 적을 때는 축소할 수 있습니다.
### 앱 노출하기
그렇다면 어떻게 웹 서버에 접속할 수 있을까요?
위에서 저희 서비스를 보면 사용 가능한 외부 IP가 없으므로 웹 브라우저를 열고 마술처럼 접속할 수는 없습니다. 접속을 위해 몇 가지 옵션이 있습니다.
**ClusterIP** - 표시되는 IP는 클러스터 내부 네트워크에 있는 클러스터IP입니다. 클러스터 내의 사물만 이 IP에 연결할 수 있습니다.
**NodePort** - NAT를 사용하여 클러스터에서 선택한 각 노드의 동일한 포트에 서비스를 노출합니다.
**로드 밸런서** - 현재 클라우드에 외부 로드 밸런서를 생성합니다. 저희는 Minikube를 사용하고 있지만, VirtualBox에서 했던 것과 같이 자체 Kubernetes 클러스터를 구축한 경우 이 기능을 제공하려면 metallb와 같은 로드밸런서를 클러스터에 배포해야 합니다.
**포트 포워드** - 로컬 호스트에서 내부 Kubernetes 클러스터 프로세스에 액세스하고 상호 작용할 수 있는 포트 포워드 기능도 있습니다. 이 옵션은 테스트 및 결함 발견에만 사용됩니다.
이제 선택할 수 있는 몇 가지 옵션이 생겼습니다. Minikube에는 본격적인 Kubernetes 클러스터와 비교했을 때 몇 가지 제한 사항이나 차이점이 있습니다.
다음 명령을 실행하여 로컬 워크스테이션을 사용하여 액세스를 포트 포워딩할 수 있습니다.
`kubectl port-forward deployment/nginx-deployment -n nginx 8090:80`
![](/2022/Days/Images/Day54_Kubernetes13.png)
위 명령을 실행하면 로컬 머신과 포트에 대한 포트 포워딩 역할을 하므로 이 터미널을 사용할 수 없게 됩니다.
![](/2022/Days/Images/Day54_Kubernetes14.png)
이제 Minikube를 통해 애플리케이션을 노출하는 방법을 구체적으로 살펴보겠습니다. Minikube를 사용하여 서비스에 연결하기 위한 URL을 생성할 수도 있습니다. [자세한 내용](https://minikube.sigs.k8s.io/docs/commands/service/)
먼저, `kubectl delete service nginx-service -n nginx`를 사용하여 서비스를 삭제합니다.
다음으로 `kubectl expose deployment nginx-deployment --name nginx-service --namespace nginx --port=80 --type=NodePort`를 사용하여 새 서비스를 생성합니다. 여기서 expose를 사용하고 유형을 NodePort로 변경한다는 점에 유의하세요.
![](/2022/Days/Images/Day54_Kubernetes15.png)
마지막으로 새 터미널에서 `minikube --profile='mc-demo' service nginx-service --url -n nginx`를 실행하여 서비스에 대한 터널을 생성합니다.
![](/2022/Days/Images/Day54_Kubernetes16.png)
브라우저 또는 제어를 열고 터미널에서 링크를 클릭합니다.
![](/2022/Days/Images/Day54_Kubernetes17.png)
### Helm
Helm은 애플리케이션을 배포할 수 있는 또 다른 방법입니다. "Kubernetes를 위한 패키지 관리자"로 알려진 Helm에 대한 자세한 내용은 [여기](https://helm.sh/)에서 확인할 수 있습니다.
Helm은 Kubernetes를 위한 패키지 매니저입니다. Helm은 Kubernetes에서 yum이나 apt에 해당하는 것으로 간주할 수 있습니다. Helm은 패키지 애플리케이션처럼 생각할 수 있는 차트를 배포하는데, 이는 미리 구성된 애플리케이션 리소스를 사용하기 쉬운 하나의 차트로 배포할 수 있는 청사진입니다. 그런 다음 다른 구성 세트로 차트의 다른 버전을 배포할 수 있습니다.
사용 가능한 모든 Helm 차트를 찾아볼 수 있는 사이트가 있으며 물론 직접 만들 수도 있습니다. 문서도 명확하고 간결하며 이 분야의 다른 모든 신조어들 사이에서 Helm이라는 용어를 처음 들었을 때처럼 어렵지 않습니다.
Helm을 시작하고 실행하거나 설치하는 것은 매우 간단합니다. 간단합니다. RaspberryPi arm64 장치를 포함한 거의 모든 배포판에 대한 바이너리와 다운로드 링크는 여기에서 찾을 수 있습니다.
또는 설치 스크립트를 사용할 수도 있는데, 이 경우 최신 버전의 Helm이 다운로드되어 설치된다는 이점이 있습니다.
```Shell
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
```
마지막으로, 애플리케이션 관리자를 위한 패키지 관리자, 맥용 homebrew, 윈도우용 chocolatey, Ubuntu/Debian용 apt, snap 및 pkg도 사용할 수 있습니다.
지금까지는 Helm이 클러스터에 다양한 테스트 애플리케이션을 다운로드하고 설치하는 데 가장 적합한 방법인 것 같습니다.
여기에 링크할 수 있는 좋은 리소스로는 Kubernetes 패키지를 찾고, 설치하고, 게시할 수 있는 리소스인 [ArtifactHUB](https://artifacthub.io/)를 들 수 있습니다. 또한 Helm 차트를 표시하는 UI인 [KubeApps](https://kubeapps.com/)에 대해서도 언급하겠습니다.
### Kubernetes에서 다룰 내용
아래에 언급된 내용 중 일부를 다루기 시작했지만, 내일 두 번째 클러스터 배포를 통해 더 많은 실습을 한 후 클러스터에 애플리케이션 배포를 시작할 수 있습니다.
- Kubernetes 아키텍처
- Kubectl 커맨드
- Kubernetes YAML
- Kubernetes Ingress
- Kubernetes Services
- Helm 패키지 관리자
- 영속성 스토리지
- stateful 앱
## 자료
사용하신 무료 리소스가 있으시면 리포지토리에 PR을 통해 여기에 추가해 주시면 기꺼이 포함시켜 드리겠습니다.
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
[Day 55](day55.md)에서 봐요!

239
2022/ko/Days/day55.md Normal file
View File

@ -0,0 +1,239 @@
---
title: '#90DaysOfDevOps - State and Ingress in Kubernetes - Day 55'
published: false
description: 90DaysOfDevOps - State and Ingress in Kubernetes
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048779
---
## Kubernetes의 State와 Ingress
이번 Kubernetes 마지막 섹션에서는 State와 Ingress에 대해 살펴보겠습니다.
지금까지 설명한 모든 것은 상태 비저장에 관한 것이며, 상태 비저장은 실제로 애플리케이션이 어떤 네트워크를 사용하든 상관하지 않고 영구적인 저장소가 필요하지 않은 경우입니다. 예를 들어 Stateful 애플리케이션과 데이터베이스가 제대로 작동하려면, 호스트 이름, IP 등 변경되지 않는 고유 ID를 통해 pod가 서로 연결될 수 있도록 해야 합니다. Stateful 애플리케이션의 예로는 MySQL 클러스터, Redis, Kafka, MongoDB 등이 있습니다. 기본적으로 데이터를 저장하는 모든 애플리케이션을 통해 가능합니다.
### Stateful 애플리케이션
StatefulSet은 Kubernetes가 스케줄링 위치에 관계없이 유지 관리하는 고유하고 영구적인 ID와 안정적인 호스트 이름을 가진 pod의 집합을 나타냅니다. 특정 StatefulSet pod의 상태 정보 및 기타 복원력 있는 데이터는 StatefulSet과 연결된 영속성 디스크 스토리지에 유지됩니다.
### Deployment vs StatefulSet
- Stateful 애플리케이션을 복제하는 것은 더 어렵다.
- 배포(Stateless 애플리케이션)에서 pod를 복제하는 것은 동일하며 상호 교환이 가능하다.
- 임의의 해시를 사용하여 임의의 순서로 pod를 생성한다.
- 모든 pod에 로드 밸런싱하는 하나의 서비스이다.
StatefulSet 또는 Stateful 애플리케이션의 경우 위의 내용이 더 어렵습니다.
- 동시에 생성하거나 삭제할 수 없다.
- 임의로 주소를 지정할 수 없다.
- 레플리카 pod는 동일하지 않다.
곧 데모에서 보게 될 것은 각 pod가 고유한 식별자를 가지고 있다는 것입니다. 상태 비저장 애플리케이션을 사용하면 임의의 이름을 볼 수 있습니다. 예를 들어 `app-7469bbb6d7-9mhxd`인 반면, 상태 저장 애플리케이션은 `mongo-0`에 더 가깝고 확장 시 `mongo-1`이라는 새 pod를 생성합니다.
이러한 pod는 동일한 사양으로 생성되지만 상호 교환할 수는 없습니다. 각 StatefulSet pod는 모든 스케줄링에 걸쳐 영구 식별자를 가지고 있습니다. 이는 데이터베이스에 쓰고 읽어야 하는 데이터베이스와 같은 Stateful 워크로드가 필요할 때, 데이터 불일치를 초래할 수 있기 때문에 두 개의 pod가 인식 없이 동시에 쓰게 할 수 없기 때문에 필요합니다. 주어진 시간에 데이터베이스에 하나의 pod만 쓰도록 해야 하지만 여러 개의 pod가 해당 데이터를 읽을 수 있습니다.
StatefulSet의 각 pod는 영구 볼륨과 데이터베이스의 복제본에 액세스하여 읽을 수 있으며, 이는 마스터로부터 지속적으로 업데이트됩니다. 또한 각 pod는 이 영속성 볼륨에 pod 상태도 저장하는데, 만약 `mongo-0`이 죽으면 새 pod가 프로비저닝될 때 스토리지에 저장된 pod 상태를 이어받게 된다는 점도 흥미롭습니다.
TLDR; StatefulSet vs Deployment
- 예측 가능한 pod 이름 = `mongo-0`
- 고정된 개별 DNS 이름
- pod 아이덴티티 - 상태 유지, 역할 유지
- Stateful 앱 복제는 복잡함
- 해야 할 일이 많음:
- 복제 및 데이터 동기화를 구성
- 원격 공유 스토리지를 사용할 수 있도록 설정
- 관리 및 백업
### 영속성 볼륨 | Claims | StorageClass
Kubernetes에서 데이터를 어떻게 지속하나요?
위에서 상태 저장 애플리케이션이 있을 때 상태를 어딘가에 저장해야 한다고 언급했는데, 바로 이 부분에서 볼륨의 필요성이 대두되는데, Kubernetes는 기본적으로 지속성을 제공하지 않습니다.
pod 라이프사이클에 의존하지 않는 스토리지 계층이 필요합니다. 이 스토리지는 모든 Kubernetes 노드에서 사용할 수 있고 액세스할 수 있어야 합니다. 또한 이 스토리지는 Kubernetes 클러스터가 충돌하더라도 생존할 수 있도록 Kubernetes 클러스터 외부에 있어야 합니다.
### 영속성 볼륨
- 데이터를 저장하기 위한 클러스터 리소스(예: CPU 및 RAM)
- YAML 파일을 통해 생성
- 실제 물리적 스토리지(NAS)가 필요
- Kubernetes 클러스터에 대한 외부 통합
- 스토리지에 다양한 유형의 스토리지를 사용
- PV는 네임스페이스가 없음
- 로컬 스토리지를 사용할 수 있지만 클러스터의 한 노드에 한정
- 데이터베이스 지속성은 원격 스토리지(NAS)를 사용
### 영구 볼륨 Claims
위의 영구 볼륨만 있어도 사용할 수 있지만 애플리케이션에서 Claims하지 않으면 사용되지 않습니다.
- YAML 파일을 통해 생성
- 영속성 볼륨 Claims은 pod 구성(볼륨 어트리뷰트)에서 사용
- PVC는 pod와 동일한 네임스페이스에 존재
- 볼륨이 pod에 마운트됨
- pod는 여러 가지 볼륨 유형(ConfigMaps, Secrets, PVC)을 사용
PV와 PVC를 생각하는 또 다른 방법은 다음과 같습니다.
PV는 Kubernetes 어드민에 의해 생성됩니다.
PVC는 사용자 또는 애플리케이션 개발자가 생성합니다.
또한 자세히 설명하지는 않겠지만 언급할 가치가 있는 두 가지 다른 유형의 볼륨이 있습니다:
### ConfigMaps | Secrets
- pod의 구성 파일
- pod의 인증서 파일
### StorageClass
- YAML 파일을 통해 생성
- PVC가 영속성 볼륨을 Claims할 때 동적으로 프로비저닝
- 각 스토리지 백엔드에는 프로비저너가 있음
- 스토리지 백엔드는 (프로비저너 속성을 통해) YAML에 정의됨
- 기본 스토리지 공급자 추상화
- 해당 스토리지에 대한 파라미터 정의
### 연습 시간
어제 세션에서는 상태 비저장 애플리케이션을 생성하는 방법을 살펴봤는데, 여기서는 동일한 작업을 수행하되 Minikube 클러스터를 사용하여 상태 저장 워크로드를 배포하고자 합니다.
지속성을 사용하는 기능과 애드온을 갖기 위해 사용하는 Minikube 명령에 대한 요약은 `minikube start --addons volumesnapshots,csi-hostpath-driver --apiserver-port=6443 --container-runtime=containerd -p mc-demo --kubernetes-version=1.21.2`입니다.
이 명령은 나중에 보여드리는 스토리지 클래스를 제공하는 CSI-hostpath-driver를 사용합니다.
애플리케이션의 빌드 아웃은 아래와 같습니다:
![](/2022/Days/Images/Day55_Kubernetes1.png)
이 애플리케이션의 YAML 구성 파일은 여기에서 찾을 수 있습니다. [pacman-stateful-demo.yaml](/2022/Days/Kubernetes)
### StorageClass 구성
애플리케이션 배포를 시작하기 전에 실행해야 하는 한 단계가 더 있는데, 그것은 StorageClass(CSI-hostpath-sc)가 기본 StorageClass인지 확인하는 것입니다. 먼저 `kubectl get storageclass` 명령을 실행하여 확인할 수 있지만, 기본적으로 Minikube 클러스터는 표준 스토리지 클래스를 기본값으로 표시하므로 다음 명령으로 변경해야 합니다.
이 첫 번째 명령은 CSI-hostpath-sc 스토리지 클래스를 기본값으로 설정합니다.
`kubectl patch storageclass csi-hostpath-sc -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'`
이 명령은 표준 StorageClass에서 기본 어노테이션을 제거합니다.
`kubectl patch storageclass standard -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'`
![](/2022/Days/Images/Day55_Kubernetes2.png)
클러스터에 Pacman 네임스페이스가 없는 상태에서 시작합니다. `kubectl get namespace`
![](/2022/Days/Images/Day55_Kubernetes3.png)
그런 다음 YAML 파일을 배포합니다. `kubectl create -f pacman-stateful-demo.yaml` 이 명령에서 우리는 Kubernetes 클러스터 내에 여러 개의 오브젝트를 생성하고 있음을 볼 수 있습니다.
![](/2022/Days/Images/Day55_Kubernetes4.png)
이제 새로 생성된 네임스페이스가 생겼습니다.
![](/2022/Days/Images/Day55_Kubernetes5.png)
다음 이미지와 `kubectl get all -n pacman` 명령에서 네임스페이스 내부에서 여러 가지 일이 일어나고 있음을 확인할 수 있습니다. 우리는 NodeJS 웹 프론트엔드를 실행하는 pod를 가지고 있고, 백엔드 데이터베이스를 실행하는 mongo를 가지고 있습니다. Pacman과 mongo 모두 해당 pod에 액세스하기 위한 서비스가 있습니다. Pacman을 위한 배포와 mongo를 위한 StatefulSet이 있습니다.
![](/2022/Days/Images/Day55_Kubernetes6.png)
또한 영속성 볼륨과 영속성 볼륨 Claims도 가지고 있는데, `kubectl get pv`를 실행하면 네임스페이스가 없는 영속성 볼륨을 얻을 수 있고, `kubectl get pvc -n pacman`을 실행하면 네임스페이스가 있는 영속성 볼륨 Claims을 얻을 수 있습니다.
![](/2022/Days/Images/Day55_Kubernetes7.png)
### 게임 플레이하기 | 미션 크리티컬 애플리케이션에 액세스하기
앞서 언급한 바와 같이 상태 비저장 애플리케이션에서 Minikube를 사용하고 있기 때문에 애플리케이션에 액세스하는 데 있어 몇 가지 장애물이 있지만, 클러스터 내에서 Ingress 또는 로드 밸런서에 액세스하여 외부에서 액세스하기 위해 자동으로 IP를 받도록 설정되어 있습니다. (위의 Pacman 네임스페이스의 모든 구성 요소 이미지에서 이를 확인할 수 있습니다).
이 데모에서는 포트 포워드 방법을 사용하여 애플리케이션에 액세스하겠습니다. 새 터미널을 열고 다음 `kubectl port-forward svc/pacman 9090:80 -n pacman` 명령을 실행하고 브라우저를 열면 이제 애플리케이션에 액세스할 수 있습니다. AWS 또는 특정 위치에서 실행하는 경우, 위의 스크린샷에서 이 pod 이름을 다시 한번 확인하면 클라우드와 영역은 물론 Kubernetes 내의 pod와 동일한 호스트에 대해서도 보고됩니다.
![](/2022/Days/Images/Day55_Kubernetes8.png)
이제 데이터베이스에 저장할 높은 점수를 생성할 수 있습니다.
![](/2022/Days/Images/Day55_Kubernetes9.png)
좋아요, 이제 높은 점수를 얻었지만 `mongo-0` pod를 삭제하면 어떻게 되나요? `kubectl delete pod mongo-0 -n pacman`을 실행하면 삭제할 수 있으며, 아직 앱에 있는 경우 적어도 몇 초 동안은 높은 점수를 사용할 수 없는 것을 볼 수 있을 것입니다.
![](/2022/Days/Images/Day55_Kubernetes10.png)
이제 게임으로 돌아가서 새 게임을 만들면 제 높은 점수를 확인할 수 있습니다. 하지만 제 말을 진정으로 믿을 수 있는 유일한 방법은 직접 시도해보고 소셜 미디어에 최고 점수를 공유하는 것입니다!
![](/2022/Days/Images/Day55_Kubernetes11.png)
배포를 통해 이전 세션에서 다룬 커맨드를 사용하여 확장할 수 있지만, 특히 대규모 Pacman 파티를 주최하려는 경우 `kubectl scale deployment pacman --replicas=10 -n pacman`을 사용하여 확장할 수 있습니다.
![](/2022/Days/Images/Day55_Kubernetes12.png)
### Ingress 설명
Kubernetes에 대해 마무리하기 전에 Kubernetes의 중요한 측면인 Ingress에 대해서도 다루고 싶었습니다.
### Ingress란 무엇인가요?
지금까지 예제에서는 포트 포워드를 사용하거나 Minikube 내에서 특정 명령을 사용하여 애플리케이션에 액세스했지만, 프로덕션 환경에서는 이 방법이 작동하지 않습니다. 여러 사용자가 대규모로 애플리케이션에 액세스할 수 있는 더 나은 방법이 필요할 것입니다.
또한 NodePort가 옵션이라고 말씀드렸지만, 이 역시 테스트 목적으로만 사용해야 합니다.
Ingress는 애플리케이션을 노출하는 더 나은 방법을 제공하며, 이를 통해 Kubernetes 클러스터 내에서 라우팅 규칙을 정의할 수 있습니다.
Ingress의 경우, 애플리케이션의 내부 서비스에 대한 포워드 요청을 생성합니다.
### 언제 Ingress가 필요한가요?
클라우드 제공자를 사용하는 경우, 관리형 Kubernetes 제품에는 클러스터에 대한 Ingress 옵션이 있거나 로드 밸런서 옵션이 제공될 가능성이 높습니다. 이를 직접 구현할 필요가 없다는 것이 관리형 Kubernetes의 장점 중 하나입니다.
클러스터를 실행하는 경우 엔트리포인트를 구성해야 합니다.
### Minikube에서 Ingress 구성하기
제가 실행 중인 mc-demo라는 특정 클러스터에서 다음 명령을 실행하여 클러스터에서 Ingress를 활성화할 수 있습니다.
`minikube --profile='mc-demo' addons enable ingress`
![](/2022/Days/Images/Day55_Kubernetes13.png)
이제 네임스페이스를 확인하면 새로운 ingress-nginx 네임스페이스가 있는 것을 볼 수 있습니다. `kubectl get ns`
![](/2022/Days/Images/Day55_Kubernetes14.png)
이제 Pacman 서비스를 실행하기 위해 Ingress YAML 구성을 생성해야 합니다. 이 파일을 리포지토리 [pacman-ingress.yaml](/2022/Days/Kubernetes)에 추가했습니다.
그런 다음 `kubectl create -f pacman-ingress.yaml`을 사용하여 Ingress 네임스페이스에 이 파일을 생성할 수 있습니다.
![](/2022/Days/Images/Day55_Kubernetes15.png)
그런 다음 `kubectl get ingress -n pacman`을 실행하면 다음과 같이 출력됩니다.
![](/2022/Days/Images/Day55_Kubernetes16.png)
그러면 윈도우에서 WSL2에서 실행되는 Minikube를 사용하고 있기 때문에 `minikube tunnel --profile=mc-demo`를 사용하여 Minikube 터널을 생성해야 한다는 메시지가 표시됩니다.
하지만 여전히 192.168.49.2에 액세스하여 Pacman 게임을 플레이할 수 없습니다.
누구든지 Windows 및 WSL에서 이 기능을 사용할 수 있거나 사용할 수 있다면 피드백을 보내 주시면 감사하겠습니다. 리포지토리에 이 문제를 제기하고 시간과 수정 사항이 생기면 다시 돌아오겠습니다.
업데이트: 이 블로그가 WSL에서 작동하지 않는 원인을 파악하는 데 도움이 될 것 같습니다 [Docker 런타임을 사용하여 WSL2에서 Minikube를 실행하도록 Ingress 구성하기](https://hellokube.dev/posts/configure-minikube-ingress-on-wsl2/).
## 자료
사용하신 무료 리소스가 있으시면 리포지토리에 PR을 통해 여기에 추가해 주시면 기꺼이 포함시켜 드리겠습니다.
- [Kubernetes StatefulSet simply explained](https://www.youtube.com/watch?v=pPQKAR1pA9U)
- [Kubernetes Volumes explained](https://www.youtube.com/watch?v=0swOh5C3OVM)
- [Kubernetes Ingress Tutorial for Beginners](https://www.youtube.com/watch?v=80Ew_fsV4rM)
- [Kubernetes Documentation](https://kubernetes.io/docs/home/)
- [TechWorld with Nana - Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]](https://www.youtube.com/watch?v=X48VuDVv0do)
- [TechWorld with Nana - Kubernetes Crash Course for Absolute Beginners](https://www.youtube.com/watch?v=s_o8dwzRlu4)
- [Kunal Kushwaha - Kubernetes Tutorial for Beginners | What is Kubernetes? Architecture Simplified!](https://www.youtube.com/watch?v=KVBON1lA9N8)
이것으로 Kubernetes 섹션을 마무리합니다. Kubernetes에 대해 다룰 수 있는 추가 콘텐츠는 매우 많으며 7일 동안 기초적인 지식을 얻을 수 있지만, 사람들은 [100DaysOfKubernetes](https://100daysofkubernetes.io/overview.html)를 통해 심도 있게 살펴볼 수 있습니다.
다음 시간에는 IaC(Infrastructure as Code)와 이것이 데브옵스 관점에서 수행하는 중요한 역할에 대해 살펴보겠습니다.
[Day 56](day56.md)에서 봐요!

133
2022/ko/Days/day56.md Normal file
View File

@ -0,0 +1,133 @@
---
title: '#90DaysOfDevOps - The Big Picture: IaC - Day 56'
published: false
description: 90DaysOfDevOps - The Big Picture IaC
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048709
---
## 큰 그림: IaC
인간은 실수를 합니다! 자동화를 도입해야 합니다!
현재 시스템을 어떻게 구축하고 계신가요?
오늘 물리 머신, 가상 머신, 클라우드 VM, 클라우드 PaaS 등 모든 것을 잃게 된다면 어떤 계획을 세우시겠습니까?
모든 것을 교체하는 데 얼마나 걸리나요?
IaC는 이를 테스트할 수 있는 동시에 이를 수행할 수 있는 솔루션을 제공하며, 이를 백업 및 복구와 혼동해서는 안 되지만 인프라와 환경, 플랫폼 측면에서 이를 스핀업하여 가축과 반려동물로 취급할 수 있어야 합니다.
결론은 코드를 사용하여 전체 환경을 재구축할 수 있다는 것입니다.
처음부터 데브옵스에 대해 일반적으로 장벽을 허물어 시스템을 안전하고 신속하게 프로덕션에 배포하는 방법이라고 말씀드린 것을 기억하세요.
IaC는 시스템을 제공하는 데 도움이 되며, 우리는 많은 프로세스와 도구에 대해 이야기했습니다. IaC는 프로세스의 이 부분을 구현하기 위해 익숙한 더 많은 도구를 제공합니다.
이 섹션에서는 IaC에 대해 집중적으로 살펴보겠습니다. 이를 코드의 인프라 또는 코드로서의 구성이라고도 합니다. 가장 잘 알려진 용어는 아마도 IaC가 아닐까 생각합니다.
### 반려동물 대 가축
데브옵스 이전을 살펴보면, 새로운 애플리케이션을 빌드해야 하는 경우 대부분의 경우 서버를 수동으로 준비해야 합니다.
- 가상 머신 배포 | 물리적 서버 및 운영 체제 설치
- 네트워킹 구성
- 라우팅 테이블 생성
- 소프트웨어 및 업데이트 설치
- 소프트웨어 구성
- 데이터베이스 설치
이는 시스템 관리자가 수동으로 수행하는 프로세스입니다. 애플리케이션의 규모가 클수록 더 많은 리소스와 서버가 필요하며, 이러한 시스템을 가동하는 데 더 많은 수작업이 필요합니다. 이 작업에는 엄청난 인력과 시간이 소요될 뿐만 아니라 기업 입장에서도 이러한 환경을 구축하기 위해 리소스에 대한 비용을 지불해야 합니다. "인간은 실수를 합니다! 자동화를 도입해야 합니다!"로 섹션을 시작한 이유입니다.
위의 초기 설정 단계에 이어서 이러한 서버를 유지 관리해야 합니다.
- 버전 업데이트
- 새 릴리스 배포
- 데이터 관리
- 애플리케이션 복구
- 서버 추가, 제거 및 확장
- 네트워크 구성
여러 테스트 및 개발 환경의 복잡성을 추가하세요.
위에서 언급한 서버를 마치 반려동물처럼 돌보던 시절에는 서버에 애칭을 붙이거나 적어도 한동안 '가족'의 일원이 되기를 바라며 이름을 지어주기도 했습니다.
IaC를 사용하면 이러한 모든 작업을 처음부터 끝까지 자동화할 수 있습니다. IaC는 인프라를 자동으로 프로비저닝하는 개념으로, 일부 툴은 서버에 문제가 발생하면 서버를 폐기하고 새 서버를 스핀업하는 작업을 수행합니다. 이 프로세스는 자동화되어 있으며 서버는 코드에 정의된 대로 정확하게 작동합니다. 이 시점에서는 장애가 발생하거나 애플리케이션의 일부 또는 전부를 업데이트하여 더 이상 현장에 존재하지 않고 이를 대체할 다른 서버가 있을 때까지는 서버의 명칭이 무엇이든 상관없습니다.
이는 거의 모든 플랫폼, 가상화, 클라우드 기반 워크로드, 그리고 Kubernetes 및 컨테이너와 같은 클라우드 네이티브 인프라에서 사용할 수 있습니다.
### 인프라 프로비저닝
이 섹션에서 사용할 도구는 아래의 처음 두 가지 영역만 다루고 있습니다. Terraform은 우리가 다룰 도구이며, 이를 통해 무에서 시작하여 인프라의 모양을 코드로 정의한 다음 배포할 수 있으며, 인프라를 관리하고 애플리케이션을 처음 배포할 수도 있지만 그 시점에서는 애플리케이션을 추적할 수 없게 되므로 다음 섹션에서 구성 관리 도구로서 Ansible과 같은 것이 이 부분에서 더 잘 작동할 수 있습니다.
너무 앞서 나가지 않고 초기 애플리케이션 설정을 처리한 다음 해당 애플리케이션과 그 구성을 관리하는 데는 chef, puppet 및 ansible과 같은 도구가 가장 적합합니다.
소프트웨어의 초기 설치 및 구성
- 새 서버 스핀업
- 네트워크 구성
- 로드 밸런서 생성
- 인프라 수준에서 구성
### 프로비저닝된 인프라 구성
- 서버에 애플리케이션 설치
- 애플리케이션을 배포할 서버를 준비합니다.
### 애플리케이션 배포
- 애플리케이션 배포 및 관리
- 유지 관리 단계
- 소프트웨어 업데이트
- 재구성
### IaC 도구의 차이점
선언적 방식과 절차적 방식
절차적
- 단계별 지침
- 서버 생성 > 서버 추가 > 이 변경하기
선언적
- 결과 선언
- 서버 2개
변경 가능(반려동물) vs 변경 불가(가축)
변경 가능
- 대체 대신 변경
- 일반적으로 수명이 길다
변경 불가
- 변경 대신 교체
- 수명이 짧을 수 있음
이것이 바로 IaC를 위한 다양한 옵션이 있는 이유입니다. 모든 것을 지배하는 하나의 도구가 없기 때문입니다.
저희는 주로 Terraform을 사용하며 직접 실습해볼 예정인데, 이것이 IaC가 실제로 작동할 때 그 이점을 확인할 수 있는 가장 좋은 방법이기 때문입니다. 실습은 코드 작성에 필요한 기술을 익힐 수 있는 가장 좋은 방법이기도 합니다.
다음에는 직접 사용해 보기 전에 101을 통해 Terraform에 대해 살펴보겠습니다.
## 자료
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
[Day 57](day57.md)에서 봐요!

98
2022/ko/Days/day57.md Normal file
View File

@ -0,0 +1,98 @@
---
title: '#90DaysOfDevOps - An intro to Terraform - Day 57'
published: false
description: 90DaysOfDevOps - An intro to Terraform
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048710
---
## Terraform 소개
"Terraform은 인프라를 안전하고 효율적으로 구축, 변경, 버전 관리할 수 있는 도구입니다."
위의 인용문은 Terraform의 개발사인 HashiCorp에서 인용한 것입니다.
"Terraform은 수백 개의 클라우드 서비스를 관리하기 위한 일관된 CLI workflow를 제공하는 코드 소프트웨어 도구로서 오픈 소스 인프라입니다. Terraform은 클라우드 API를 선언적 구성 파일로 코드화합니다."
해시코프는 [HashiCorp 배우기](https://learn.hashicorp.com/terraform?utm_source=terraform_io&utm_content=terraform_io_hero)에서 모든 제품을 다루는 훌륭한 리소스를 제공하고 있으며, IaC로 무언가를 달성하려고 할 때 유용한 데모를 제공합니다.
모든 클라우드 제공업체와 온프레미스 플랫폼은 일반적으로 UI를 통해 리소스를 생성할 수 있는 관리 콘솔에 대한 액세스를 제공하며, 일반적으로 이러한 플랫폼은 동일한 리소스를 생성할 수 있는 CLI 또는 API 액세스도 제공하지만, API를 사용하면 빠르게 프로비저닝할 수 있습니다.형
IaC를 사용하면 이러한 API에 연결하여 원하는 상태로 리소스를 배포할 수 있습니다.
아래에 배타적이거나 완전한 도구가 아닌 다른 도구가 있습니다. 다른 도구가 있다면 PR을 통해 공유해 주세요.
| Cloud Specific | Cloud Agnostic |
| ------------------------------- | -------------- |
| AWS CloudFormation | Terraform |
| Azure Resource Manager | Pulumi |
| Google Cloud Deployment Manager | |
데모뿐만 아니라 일반적으로 사용하고자 하는 클라우드와 플랫폼에 구애받지 않으려는 것이 바로 우리가 Terraform을 사용하는 또 다른 이유입니다.
## Terraform 개요
Terraform은 프로비저닝에 중점을 둔 도구로, 복잡한 인프라 환경을 프로비저닝할 수 있는 기능을 제공하는 CLI입니다. 로컬 또는 원격(클라우드)에 존재하는 복잡한 인프라 요구 사항을 정의할 수 있습니다. Terraform을 사용하면 처음에 구축할 수 있을 뿐만 아니라 해당 리소스의 수명 기간 동안 유지 관리 및 업데이트할 수 있습니다.
여기서는 개략적인 내용만 다루겠지만, 더 자세한 내용과 다양한 리소스를 보려면 [terraform.io](https://www.terraform.io/)를 방문하세요.
### 쓰기
Terraform을 사용하면 환경을 구축할 선언적 구성 파일을 만들 수 있습니다. 이 파일은 블록, 인수, 표현식을 사용하여 리소스를 간결하게 설명할 수 있는 해시코프 구성 언어(HCL)를 사용하여 작성됩니다. 물론 가상 머신, 컨테이너를 배포할 때와 쿠버네티스 내에서 이를 자세히 살펴볼 것입니다.
### 계획
위의 구성 파일들이 우리가 보고자 하는 것을 배포할 것인지 확인하기 위해 Terraform cli의 특정 기능을 사용하여 배포하거나 변경하기 전에 해당 계획을 테스트할 수 있는 기능입니다. Terraform은 인프라를 위한 지속적인 도구이므로 인프라의 측면을 변경하려면 코드에서 모두 캡처되도록 Terraform을 통해 변경해야 한다는 점을 기억하세요.
### 적용
만족스러우면 계속해서 이 구성을 Terraform 내에서 사용할 수 있는 많은 제공업체에 적용할 수 있습니다. [여기](https://registry.terraform.io/browse/providers)에서 사용 가능한 수많은 제공자를 확인할 수 있습니다.
또 한 가지 언급할 것은 사용 가능한 모듈도 있다는 것인데, 이러한 모듈은 공개적으로 생성 및 공유되어 있으므로 특정 인프라 리소스를 모든 곳에 동일한 방식으로 배포하는 모범 사례를 반복해서 생성할 필요가 없다는 점에서 컨테이너 이미지와 유사합니다. 사용 가능한 모듈은 [여기](https://registry.terraform.io/browse/modules)에서 찾을 수 있습니다.
Terraform workflow는 다음과 같습니다. (_Terraform 사이트에서 가져옴_)
![](/2022/Days/Images/Day57_IAC3.png)
### Terraform vs Vagrant
이번 챌린지에서는 개발 환경에 집중하는 또 다른 해시코프 오픈소스 도구인 Vagrant를 사용했습니다.
- Vagrant는 개발 환경 관리에 중점을 둔 도구입니다.
- Terraform은 인프라 구축을 위한 도구입니다.
두 도구에 대한 자세한 비교는 공식 [HashiCorp 사이트](https://www.vagrantup.com/intro/vs/terraform)에서 확인할 수 있습니다.
## Terraform 설치
Terraform을 설치하는 데에는 많은 것이 필요하지 않습니다.
Terraform은 크로스 플랫폼이며, 제 리눅스 머신에서 아래에서 CLI를 다운로드하고 설치하는 몇 가지 옵션을 볼 수 있습니다.
![](/2022/Days/Images/Day57_IAC2.png)
`arkade`를 사용하여 Terraform을 설치하면, 아케이드는 필요한 도구, 앱, 클리스를 시스템에 설치할 수 있는 편리한 작은 도구입니다. 간단한 `arkade get terraform`으로 Terraform을 업데이트할 수 있으며, Terraform이 있다면 같은 명령으로 Terraform CLI도 설치할 수 있습니다.
![](/2022/Days/Images/Day57_IAC1.png)
앞으로 HCL에 대해 좀 더 자세히 살펴본 다음 다양한 플랫폼에서 인프라 리소스를 생성하는 데 Terraform을 사용해 보도록 하겠습니다.
## 자료
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
[Day 58](day58.md)에서 봐요!

234
2022/ko/Days/day58.md Normal file
View File

@ -0,0 +1,234 @@
---
title: '#90DaysOfDevOps - HashiCorp Configuration Language (HCL) - Day 58'
published: false
description: 90DaysOfDevOps - HashiCorp Configuration Language (HCL)
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048741
---
## HashiCorp 구성 언어(HCL)
Terraform으로 무언가를 만들기 시작하기 전에 HashiCorp 구성 언어(HCL)에 대해 조금 알아볼 필요가 있습니다. 지금까지 챌린지를 진행하면서 몇 가지 다른 스크립팅 및 프로그래밍 언어를 살펴봤는데, 여기에 또 다른 언어가 있습니다. [Go 프로그래밍 언어](day07.md)에 이어 [bash 스크립트](day19.md)를 다루었고, [네트워크 자동화](day27.md)와 관련해서는 파이썬도 조금 다뤄봤습니다.
이제 HashiCorp 구성 언어(HCL)를 다뤄야 하는데, 이 언어를 처음 접하는 분들에게는 다소 어렵게 느껴질 수 있지만 매우 간단하고 강력한 언어입니다.
이 섹션을 진행하면서 어떤 OS를 사용하든 시스템에서 로컬로 실행할 수 있는 예제를 사용할 것이며, 일반적으로 Terraform에서 사용하는 인프라 플랫폼은 아니지만 VirtualBox를 사용할 것입니다. 그러나 로컬에서 실행하는 것은 무료이며 이 게시물에서 원하는 것을 달성할 수 있습니다. 이 포스팅의 개념을 도커나 쿠버네티스로 확장할 수도 있습니다.
하지만 일반적으로는 퍼블릭 클라우드(AWS, Google, Microsoft Azure)뿐만 아니라 가상화 환경(VMware, Microsoft Hyper-V, Nutanix AHV)에도 인프라를 배포하는 데 Terraform을 사용하거나 사용해야 합니다. 퍼블릭 클라우드에서 Terraform을 사용하면 가상 머신 자동 배포뿐 아니라 PaaS 워크로드와 같은 모든 필수 인프라와 VPC 및 보안 그룹과 같은 모든 네트워킹 필수 자산을 생성할 수 있습니다.
Terraform에는 두 가지 중요한 측면이 있는데, 이 포스팅에서 다룰 code와 state입니다. 이 두 가지를 함께 Terraform의 핵심이라고 부를 수 있습니다. 그런 다음 우리가 대화하고 배포하고자 하는 환경이 있는데, 이는 지난 세션에서 간략히 언급했지만, AWS 공급자, Azure 공급자 등을 사용하여 실행되는 Terraform 공급자를 사용하여 실행됩니다. 수백 개가 있습니다.
### 기본 Terraform 사용법
Terraform `.tf` 파일이 어떻게 구성되는지 살펴보겠습니다. 첫 번째로 살펴볼 예제는 AWS에 리소스를 배포하는 코드이며, 이를 위해서는 시스템에 AWS CLI를 설치하고 계정에 맞게 구성해야 합니다.
### 공급자
더 복잡하게 만들 때까지는 일반적으로 `main.tf`라고 부르는 `.tf` 파일 구조의 맨 위에 있습니다. 여기서는 앞서 언급했던 공급자를 정의합니다. 보시다시피 AWS 공급자의 소스는 `hashicorp/aws`이며, 이는 공급자가 HashiCorp에서 직접 유지 관리하거나 게시했음을 의미합니다. 기본적으로 [Terraform 레지스트리](https://registry.terraform.io/)에서 사용할 수 있는 제공자를 참조하게 되며, 제공자를 작성하여 로컬에서 사용하거나 Terraform 레지스트리에 자체 게시할 수도 있습니다.
```
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
```
프로비저닝할 AWS 리전을 결정하기 위해 여기에 리전을 추가할 수도 있는데, 이를 위해 다음을 추가할 수 있습니다:
```
provider "aws" {
region = "ap-southeast-1" //리소스를 배포해야 하는 지역
}
```
### Terraform 리소스
- EC2, 로드 밸런서, VPC 등과 같은 하나 이상의 인프라 개체를 설명하는 Terraform 구성 파일의 또 다른 중요한 구성 요소입니다.
- 리소스 블록은 지정된 유형("aws_instance")의 리소스를 지정된 로컬 이름("90daysofdevops")으로 선언합니다.
- 리소스 유형과 이름은 함께 지정된 리소스의 식별자 역할을 합니다.
```
resource "aws_instance" "90daysofdevops" {
ami = data.aws_ami.instance_id.id
instance_type = "t2.micro"
availability_zone = "us-west-2a"
security_groups = [aws_security_group.allow_web.name]
user_data = <<-EOF
#! /bin/bash
sudo yum update
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
echo "
<h1>Deployed via Terraform</h1>
" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "Created by Terraform"
}
}
```
위에서 `yum` 업데이트를 실행하고 ec2 인스턴스에 `httpd`를 설치하는 것을 볼 수 있습니다.
이제 전체 main.tf 파일을 보면 다음과 같이 보일 수 있습니다.
```
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = "default"
region = "us-west-2"
}
resource "aws_instance" "90daysofdevops" {
ami = "ami-830c94e3"
instance_type = "t2.micro"
availability_zone = "us-west-2a"
user_data = <<-EOF
#! /bin/bash
sudo yum update
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
echo "
<h1>Deployed via Terraform</h1>
" | sudo tee /var/www/html/index.html
EOF
tags = {
Name = "Created by Terraform"
tags = {
Name = "ExampleAppServerInstance"
}
}
```
위의 코드는 AWS에서 매우 간단한 웹 서버를 ec2 인스턴스로 배포합니다. 이 코드와 이와 같은 다른 구성의 가장 큰 장점은 이 작업을 반복할 수 있고 매번 동일한 출력을 얻을 수 있다는 것입니다. 제가 코드를 엉망으로 만들었을 가능성을 제외하고는 위와 같이 사람이 개입할 여지가 없습니다.
한 번도 사용하지 않을 것 같은 아주 간단한 예제를 살펴볼 수 있지만, 어쨌든 유머러스하게 만들어 보겠습니다. 모든 훌륭한 스크립팅 및 프로그래밍 언어가 그렇듯, Hello World부터 시작해야 합니다.
```
terraform {
# 이 모듈은 현재 Terraform 0.13.x에서만 테스트 중입니다. 그러나 더 쉽게 업그레이드할 수 있도록 다음과 같이 설정하고 있습니다.
# 0.12.26을 최소 버전으로 설정했는데, 이 버전은 소스 URL이 있는 required_providers에 대한 지원이 추가되었기 때문입니다.
# 0.13.x 코드와 호환됩니다.
required_version = ">= 0.12.26"
}
# website::tag::1:: 가장 간단한 Terraform 모듈: "Hello, World!"를 출력하기만 하면 됩니다.
output "hello_world" {
value = "Hello, 90DaysOfDevOps from Terraform"
}
```
이 파일은 IaC 폴더 안의 Hello-world 폴더에서 찾을 수 있지만, Terraform 코드를 사용하기 위해 실행해야 하는 몇 가지 명령이 있기 때문에 바로 작동하지는 않습니다.
터미널에서 main.tf가 생성된 폴더로 이동합니다. 이 저장소에서 가져올 수도 있고 위의 코드를 사용하여 새 저장소를 생성할 수도 있습니다.
해당 폴더에서 `terraform init`을 실행합니다.
Terraform 코드가 있는 모든 디렉토리에서 또는 Terraform 코드를 실행하기 전에 이 작업을 수행해야 합니다. 구성 디렉터리를 초기화하면 구성에 정의된 공급자를 다운로드하여 설치합니다. 이 경우에는 공급자가 없지만 위의 예제에서는 이 구성에 대한 AWS 공급자를 다운로드합니다.
![](/2022/Days/Images/Day58_IAC1.png)
다음 명령은 `terraform plan`입니다.
`terraform plan` 명령은 실행 계획을 생성하여 Terraform이 인프라에 적용하려는 변경 사항을 미리 볼 수 있게 해줍니다.
hello-world 예제를 통해 아래에서 간단히 볼 수 있듯이, 이것이 AWS ec2 인스턴스였다면 생성할 모든 단계가 출력되는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day58_IAC2.png)
이 시점에서 리포지토리를 초기화했고 필요한 경우 제공자를 다운로드했으며, 테스트 워크스루를 실행하여 원하는 대로 표시되는지 확인했으므로 이제 코드를 실행하고 배포할 수 있습니다.
`terraform apply`를 사용하면 이 작업을 수행할 수 있으며, 이 명령에는 안전 조치가 내장되어 있어 앞으로 일어날 일에 대한 계획 보기가 다시 제공되므로 계속할 것인지에 대한 응답을 보장합니다.
![](/2022/Days/Images/Day58_IAC3.png)
값을 입력하기 위해 yes를 입력하면 코드가 배포됩니다. 그다지 흥미롭지는 않지만, 코드에서 정의한 출력이 나오는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day58_IAC4.png)
이제 우리는 아무것도 배포하지 않았고, 아무것도 추가, 변경 또는 삭제하지 않았지만, 만약 배포했다면 위와 같이 표시된 것을 볼 수 있을 것입니다. 그러나 무언가를 배포한 후 배포한 모든 것을 제거하려면 `terraform destroy` 명령을 사용할 수 있습니다. 이 경우에도 `apply``delete` 명령 끝에 `--auto-approve`을 사용하여 수동 개입을 우회할 수 있지만 예라고 입력해야 하는 안전성이 있습니다. 하지만 이 단축키는 학습 및 테스트 시에만 사용하는 것이 좋으며, 때로는 모든 것이 빌드된 것보다 빨리 사라질 수 있습니다.
지금까지 Terraform CLI에서 다룬 명령어는 총 4가지입니다.
- `terraform init` = 프로바이더로 프로젝트 폴더 준비하기
- `terraform plan` = 코드를 기반으로 다음 명령 중에 생성 및 변경될 내용을 표시합니다.
- `terraform apply`= 코드에 정의된 리소스를 배포합니다.
- `terraform destroy` = 프로젝트에서 생성한 리소스를 파괴합니다.
코드 파일에서 두 가지 중요한 측면도 다루었습니다.
- providers = API를 통해 Terraform이 최종 플랫폼과 대화하는 방법
- resources = 우리가 코드로 배포하고자 하는 것
또 한 가지 주의해야 할 점은 `terraform init`을 실행할 때 폴더의 트리를 전후로 살펴보고 어떤 일이 발생하고 제공자와 모듈을 어디에 저장하는지 확인하는 것입니다.
### Terraform state
또한 디렉터리 내부에 생성되는 state 파일도 알아야 하는데, 이 hello-world 예제에서 state 파일은 간단합니다. 이것은 Terraform에 따라 세계를 표현하는 JSON 파일입니다. 상태는 민감한 데이터를 기꺼이 보여줄 수 있으므로 주의해야 하며, 모범 사례로 GitHub에 업로드하기 전에 `.tfstate` 파일을 `.gitignore` 폴더에 넣는 것이 좋습니다.
기본적으로 상태 파일은 프로젝트 코드와 같은 디렉터리에 있지만 옵션으로 원격으로 저장할 수도 있습니다. 프로덕션 환경에서는 S3 버킷과 같은 공유 위치가 될 가능성이 높습니다.
또 다른 옵션으로는 유료 관리형 서비스인 Terraform Cloud가 있습니다. (최대 5명의 사용자까지 무료)
원격 위치에 상태를 저장할 때 얻을 수 있는 장점은 다음과 같습니다:
- 민감한 데이터 암호화
- 협업
- 자동화
- 그러나 복잡성이 증가할 수 있습니다.
```JSON
{
"version": 4,
"terraform_version": "1.1.6",
"serial": 1,
"lineage": "a74296e7-670d-0cbb-a048-f332696ca850",
"outputs": {
"hello_world": {
"value": "Hello, 90DaysOfDevOps from Terraform",
"type": "string"
}
},
"resources": []
}
```
## 자료
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
[Day 59](day59.md)에서 봐요!

130
2022/ko/Days/day59.md Normal file
View File

@ -0,0 +1,130 @@
---
title: '#90DaysOfDevOps - Create a VM with Terraform & Variables - Day 59'
published: false
description: 90DaysOfDevOps - Create a VM with Terraform & Variables
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049051
---
## Terraform 및 변수를 사용하여 VM 생성하기
이 세션에서는 VirtualBox 내에서 Terraform을 사용하여 VM을 한두 개 생성해 보겠습니다. VirtualBox는 워크스테이션 가상화 옵션이므로 Terraform의 사용 사례는 아니지만, 저는 현재 36,000피트 상공에 있으며 이 정도 높이의 클라우드에 퍼블릭 클라우드 리소스를 배포한 만큼 노트북에서 로컬로 이 작업을 수행하는 것이 훨씬 더 빠릅니다.
순전히 데모 목적이지만 개념은 동일합니다. 원하는 상태 구성 코드를 만든 다음 VirtualBox 공급자에 대해 실행할 것입니다. 과거에는 여기서는 vagrant를 사용했으며 이 섹션의 시작 부분에서 vagrant와 Terraform의 차이점에 대해 다루었습니다.
### VirtualBox에서 가상 머신 생성하기
가장 먼저 할 일은 VirtualBox라는 새 폴더를 생성한 다음 VirtualBox.tf 파일을 생성하고 여기에서 리소스를 정의하는 것입니다. VirtualBox 폴더에서 VirtualBox.tf로 찾을 수 있는 아래 코드는 Virtualbox에 2개의 VM을 생성합니다.
커뮤니티 VirtualBox 제공업체에 대한 자세한 내용은 [여기](https://registry.terraform.io/providers/terra-farm/virtualbox/latest/docs/resources/vm)에서 확인할 수 있습니다.
```
terraform {
required_providers {
virtualbox = {
source = "terra-farm/virtualbox"
version = "0.2.2-alpha.1"
}
}
}
# 현재 공급자 자체에 대한 구성 옵션이 없습니다.
resource "virtualbox_vm" "node" {
count = 2
name = format("node-%02d", count.index + 1)
image = "https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20180903.0.0/providers/virtualbox.box"
cpus = 2
memory = "512 mib"
network_adapter {
type = "hostonly"
host_interface = "vboxnet1"
}
}
output "IPAddr" {
value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 1)
}
output "IPAddr_2" {
value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 2)
}
```
이제 코드가 정의되었으므로 이제 폴더에서 `terraform init`을 수행하여 Virtualbox용 공급자를 다운로드할 수 있습니다.
![](/2022/Days/Images/Day59_IAC1.png)
또한 시스템에도 VirtualBox가 설치되어 있어야 합니다. 그런 다음 `terraform plan`을 실행하여 코드가 무엇을 생성하는지 확인할 수 있습니다. 이어서 `terraform apply`를 실행하면 아래 이미지에 완성된 프로세스가 표시됩니다.
![](/2022/Days/Images/Day59_IAC2.png)
이제 Virtualbox에서 2개의 가상 머신을 볼 수 있습니다.
![](/2022/Days/Images/Day59_IAC3.png)
### 구성 변경
배포에 다른 노드를 추가해 보겠습니다. 카운트 라인을 변경하여 원하는 새로운 노드 수를 표시하면 됩니다. `terraform apply`를 실행하면 아래와 같이 표시됩니다.
![](/2022/Days/Images/Day59_IAC4.png)
VirtualBox에서 완료되면 이제 3개의 노드가 실행되고 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day59_IAC5.png)
완료되면 `terraform destroy`를 사용하여 이를 지우면 머신이 제거됩니다.
![](/2022/Days/Images/Day59_IAC6.png)
### 변수 및 출력
지난 세션에서 hello-world 예제를 실행할 때 출력을 언급했습니다. 여기서 더 자세히 살펴볼 수 있습니다.
하지만 여기에도 사용할 수 있는 다른 많은 변수가 있으며, 변수를 정의하는 몇 가지 다른 방법도 있습니다.
- `terraform plan` 또는 `terraform apply` 명령을 사용하여 변수를 수동으로 입력할 수 있습니다.
- 블록 내의 .tf 파일에 변수를 정의할 수 있습니다.
- `TF_VAR_NAME` 형식을 사용하여 시스템 내에서 환경 변수를 사용할 수 있습니다.
- 저는 프로젝트 폴더에 terraform.tfvars 파일을 사용하는 것을 선호합니다.
- \*auto.tfvars 파일 옵션이 있습니다.
- 또는 `-var` 또는 `-var-file`을 사용하여 `terraform plan` 또는 `terraform apply`을 실행할 때를 정의할 수 있습니다.
아래에서 위로 올라가는 것이 변수를 정의하는 순서입니다.
또한 상태 파일에 민감한 정보가 포함될 것이라고 언급했습니다. 민감한 정보를 변수로 정의하고 이를 민감한 정보로 정의할 수 있습니다.
```
variable "some resource" {
description = "something important"
type= string
sensitive = true
}
```
## 자료
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
[Day 60](day60.md)에서 봐요!

194
2022/ko/Days/day60.md Normal file
View File

@ -0,0 +1,194 @@
---
title: '#90DaysOfDevOps - Docker Containers, Provisioners & Modules - Day 60'
published: false
description: '90DaysOfDevOps - Docker Containers, Provisioners & Modules'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049052
---
## Docker 컨테이너, Provisioners 및 모듈
[Day 59](day59.md)에는 Terraform을 사용하여 로컬 무료 VirtualBox 환경에 가상 머신을 프로비저닝했습니다. 이 섹션에서는 몇 가지 구성이 포함된 Docker 컨테이너를 로컬 Docker 환경에 배포해 보겠습니다.
### Docker 데모
먼저 아래 코드 블록을 사용하여 간단한 웹 앱을 Docker에 배포하고 이를 게시하여 네트워크에서 사용할 수 있도록 하겠습니다. nginx를 사용할 것이며 로컬 호스트와 포트 8000을 통해 노트북에서 외부에서 사용할 수 있도록 할 것입니다. 커뮤니티에서 제공하는 Docker 공급자를 사용하고 있으며 구성에서도 사용 중인 Docker 이미지를 확인할 수 있습니다.
```
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
}
}
provider "docker" {}
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "tutorial"
ports {
internal = 80
external = 8000
}
}
```
첫 번째 작업은 `terraform init` 명령을 사용하여 로컬 머신에 프로바이더를 다운로드하는 것입니다.
![](/2022/Days/Images/Day60_IAC1.png)
그런 다음 `terraform apply`를 실행한 다음 `docker ps`를 실행하면 컨테이너가 실행되는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day60_IAC2.png)
이제 브라우저를 열어 `http://localhost:8000/`으로 이동하면 NGINX 컨테이너에 액세스할 수 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day60_IAC3.png)
자세한 내용은 [Docker Provider](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container)에서 확인할 수 있습니다.
위는 Terraform과 Docker로 무엇을 할 수 있는지, 그리고 Terraform 상태에서 어떻게 관리할 수 있는지에 대한 아주 간단한 데모입니다. 컨테이너 섹션에서 docker-compose에 대해 다뤘고, 이것과 IaC, 그리고 Kubernetes 사이에는 약간의 교차점이 있습니다.
이를 보여드리고 Terraform이 어떻게 좀 더 복잡한 것을 처리할 수 있는지 보여드리기 위해, 우리가 docker-compose로 만든 워드프레스와 MySQL용 docker-compose 파일을 가져와서 이것을 Terraform에 넣도록 하겠습니다. [docker-wordpress.tf](2022/Days/IaC/Docker-WordPress/docker-WordPress.tf)를 찾을 수 있습니다.
```
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
}
}
provider "docker" {}
variable wordpress_port {
default = "8080"
}
resource "docker_volume" "db_data" {
name = "db_data"
}
resource "docker_network" "wordpress_net" {
name = "wordpress_net"
}
resource "docker_container" "db" {
name = "db"
image = "mysql:5.7"
restart = "always"
network_mode = "wordpress_net"
env = [
"MYSQL_ROOT_PASSWORD=wordpress",
"MYSQL_PASSWORD=wordpress",
"MYSQL_USER=wordpress",
"MYSQL_DATABASE=wordpress"
]
mounts {
type = "volume"
target = "/var/lib/mysql"
source = "db_data"
}
}
resource "docker_container" "wordpress" {
name = "wordpress"
image = "wordpress:latest"
restart = "always"
network_mode = "wordpress_net"
env = [
"WORDPRESS_DB_HOST=db:3306",
"WORDPRESS_DB_USER=wordpress",
"WORDPRESS_DB_NAME=wordpress",
"WORDPRESS_DB_PASSWORD=wordpress"
]
ports {
internal = "80"
external = "${var.wordpress_port}"
}
}
```
이 파일을 다시 새 폴더에 넣은 다음 `terraform init` 명령을 실행하여 필요한 Provisioners를 내려놓습니다.
![](/2022/Days/Images/Day60_IAC4.png)
그런 다음 `terraform apply` 명령을 실행한 다음 `docker ps` 출력을 살펴보면 새로 생성된 컨테이너를 볼 수 있습니다.
![](/2022/Days/Images/Day60_IAC5.png)
이제 WordPress 프론트엔드로 이동할 수도 있습니다. 컨테이너 섹션에서 docker-compose로 이 과정을 거쳤을 때와 마찬가지로 이제 설정을 실행할 수 있으며 WordPress 게시물이 MySQL 데이터베이스에 저장됩니다.
![](/2022/Days/Images/Day60_IAC6.png)
이제 컨테이너와 Kubernetes에 대해 자세히 살펴봤는데요, 테스트용으로는 괜찮지만, 실제 웹사이트를 운영할 계획이라면 컨테이너만으로는 이 작업을 수행하지 않고 Kubernetes를 사용하여 이를 달성할 것입니다. 다음에는 Terraform과 Kubernetes를 사용하여 살펴보도록 하겠습니다.
### Provisioners
Provisioners는 어떤 것이 선언적일 수 없는 경우 이를 배포에 파싱할 수 있는 방법을 제공하기 위해 존재합니다.
다른 대안이 없고 코드에 이러한 복잡성을 추가해야 하는 경우 다음 코드 블록과 유사한 것을 실행하여 이를 수행할 수 있습니다.
```
resource "docker_container" "db" {
# ...
provisioner "local-exec" {
command = "echo The server's IP address is ${self.private_ip}"
}
}
```
원격 실행 Provisioners는 원격 리소스가 생성된 후 원격 리소스에서 스크립트를 호출합니다. 이 스크립트는 OS에 따라 다르거나 구성 관리 도구에서 래핑하는 데 사용될 수 있습니다. 이 중 일부는 Provisioners에서 다루고 있습니다.
[Provisioners에 대한 자세한 내용](https://www.terraform.io/language/resources/provisioners/syntax)
- file
- local-exec
- remote-exec
- vendor
- ansible
- chef
- puppet
### 모듈
모듈은 함께 사용되는 여러 리소스를 위한 컨테이너입니다. 모듈은 동일한 디렉터리에 있는 .tf 파일 모음으로 구성됩니다.
모듈은 인프라 리소스를 분리할 수 있는 좋은 방법일 뿐만 아니라 이미 만들어진 타사 모듈을 가져올 수 있으므로 처음부터 다시 만들 필요가 없습니다.
예를 들어, 동일한 프로젝트를 사용하여 일부 VM, VPC, 보안 그룹을 구축한 다음 Kubernetes 클러스터도 구축하려는 경우 리소스를 모듈로 분할하여 리소스와 그룹화 위치를 더 잘 정의하고 싶을 것입니다.
모듈의 또 다른 장점은 이러한 모듈을 가져와 다른 프로젝트에 사용하거나 커뮤니티를 돕기 위해 공개적으로 공유할 수 있다는 것입니다.
저희는 인프라를 구성 요소로 나누고 있으며, 여기서 구성 요소는 모듈로 알려져 있습니다.
## 자료
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
[Day 61](day61.md)에서 봐요!

172
2022/ko/Days/day61.md Normal file
View File

@ -0,0 +1,172 @@
---
title: '#90DaysOfDevOps - Kubernetes & Multiple Environments - Day 61'
published: false
description: 90DaysOfDevOps - Kubernetes & Multiple Environments
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048743
---
## Kubernetes 및 다중 환경
지금까지 IaC에 대한 이 섹션에서는 가상 머신을 배포하는 방법을 살펴보았지만, 가상 머신의 모양을 코드에서 정의한 다음 배포한다는 전제는 실제로 동일합니다. Docker 컨테이너도 마찬가지이며, 이 세션에서는 Terraform을 사용하여 Kubernetes에서 지원하는 리소스와 상호 작용하는 방법을 살펴보겠습니다.
저는 데모 목적으로 3개의 주요 클라우드 제공업체에 Terraform을 사용하여 Kubernetes 클러스터를 배포해 왔으며, 리포지토리 [tf_k8deploy](https://github.com/MichaelCade/tf_k8deploy)를 찾을 수 있습니다.
그러나 Terraform을 사용하여 Kubernetes 클러스터 내의 객체와 상호 작용할 수도 있는데, 이는 [Kubernetes 공급자](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs)를 사용하거나 [Helm 공급자](https://registry.terraform.io/providers/hashicorp/helm/latest)를 사용하여 차트 배포를 관리할 수 있습니다.
이제 이전 섹션에서 살펴본 것처럼 `kubectl`을 사용할 수 있습니다. 하지만 Kubernetes 환경에서 Terraform을 사용하면 몇 가지 이점이 있습니다.
- 통합 workflow - 클러스터 배포에 Terraform을 사용했다면, 동일한 workflow와 도구를 사용하여 Kubernetes 클러스터 내에 배포할 수 있습니다.
- 라이프사이클 관리 - Terraform은 단순한 프로비저닝 도구가 아니라 변경, 업데이트, 삭제를 가능하게 합니다.
### 간단한 Kubernetes 데모
지난 세션에서 만든 데모와 마찬가지로 이제 Kubernetes 클러스터에 nginx를 배포할 수 있습니다. 여기서는 데모 목적으로 Minikube를 다시 사용하겠습니다. Kubernetes.tf 파일을 생성하고 [여기](2022/Days/IaC/Kubernetes/Kubernetes.tf)에서 이 파일을 찾을 수 있습니다.
이 파일에서 Kubernetes 공급자를 정의하고, kubeconfig 파일을 가리키고, nginx라는 네임스페이스를 생성한 다음, 2개의 복제본과 마지막으로 서비스를 포함하는 배포를 생성하겠습니다.
```
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.0"
}
}
}
provider "kubernetes" {
config_path = "~/.kube/config"
}
resource "kubernetes_namespace" "test" {
metadata {
name = "nginx"
}
}
resource "kubernetes_deployment" "test" {
metadata {
name = "nginx"
namespace = kubernetes_namespace.test.metadata.0.name
}
spec {
replicas = 2
selector {
match_labels = {
app = "MyTestApp"
}
}
template {
metadata {
labels = {
app = "MyTestApp"
}
}
spec {
container {
image = "nginx"
name = "nginx-container"
port {
container_port = 80
}
}
}
}
}
}
resource "kubernetes_service" "test" {
metadata {
name = "nginx"
namespace = kubernetes_namespace.test.metadata.0.name
}
spec {
selector = {
app = kubernetes_deployment.test.spec.0.template.0.metadata.0.labels.app
}
type = "NodePort"
port {
node_port = 30201
port = 80
target_port = 80
}
}
}
```
새 프로젝트 폴더에서 가장 먼저 해야 할 일은 `terraform init` 명령을 실행하는 것입니다.
![](/2022/Days/Images/Day61_IAC1.png)
그리고 `terraform apply` 명령을 실행하기 전에 네임스페이스가 없다는 것을 보여드리겠습니다.
![](/2022/Days/Images/Day61_IAC2.png)
apply 명령을 실행하면 Kubernetes 클러스터 내에 3개의 새로운 리소스, 네임스페이스, 배포 및 서비스가 생성됩니다.
![](/2022/Days/Images/Day61_IAC3.png)
이제 클러스터 내에 배포된 리소스를 살펴볼 수 있습니다.
![](/2022/Days/Images/Day61_IAC4.png)
이전 섹션에서 보셨듯이 Minikube를 사용하고 있기 때문에 도커 네트워킹으로 인그레스를 시도할 때 한계가 있습니다. 하지만 `kubectl port-forward -n nginx svc/nginx 30201:80` 명령을 실행하고 `http://localhost:30201/`으로 브라우저를 열면 NGINX 페이지를 볼 수 있습니다.
![](/2022/Days/Images/Day61_IAC5.png)
Terraform과 Kubernetes에 대해 더 자세한 데모를 해보고 싶으시다면 [HashiCorp 학습 사이트](https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider)를 방문해 보시기 바랍니다.
### 여러 환경
우리가 실행한 데모를 이제 특정 프로덕션, 스테이징 및 개발 환경이 동일하게 보이고 이 코드를 활용하기를 원한다면 Terraform을 사용하여 이를 달성하는 두 가지 접근 방식이 있습니다.
- `terraform workspaces` - 단일 백엔드 내의 여러 개의 명명된 섹션
- 파일 구조 - 디렉토리 레이아웃은 분리를 제공하고, 모듈은 재사용을 제공합니다.
하지만 위의 각 방법에는 장단점이 있습니다.
### Terraform workspaces
장점
- 쉬운 시작
- 편리한 terraform.workspace 표현식
- 코드 중복 최소화
단점
- 인적 오류가 발생하기 쉬움(TF를 사용하여 이를 제거하려고 노력 중임)
- 동일한 백엔드 내에 저장된 상태
- 코드베이스가 배포 구성을 명확하게 보여주지 않음.
### 파일 구조
장점
- 백엔드 격리
- 보안 향상
- 인적 오류 가능성 감소
- 배포된 상태를 완벽하게 나타내는 코드베이스
단점
- 프로비저닝 환경에 여러 Terraform 적용 필요
- 코드 중복이 더 많지만, 모듈을 사용하여 최소화할 수 있습니다.
## 자료
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
[Day 62](day62.md)에서 봐요!

135
2022/ko/Days/day62.md Normal file
View File

@ -0,0 +1,135 @@
---
title: '#90DaysOfDevOps - Testing, Tools & Alternatives - Day 62'
published: false
description: '90DaysOfDevOps - Testing, Tools & Alternatives'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049053
---
## 테스트, 도구 및 대안
IaC에 대한 이 섹션을 마무리하면서 코드 테스트, 사용 가능한 다양한 도구, 그리고 이를 달성하기 위한 Terraform의 몇 가지 대안에 대해 언급하지 않을 수 없습니다. 이 섹션의 시작 부분에서 말씀드렸듯이 제가 Terraform에 초점을 맞춘 이유는 첫째로 무료이며 오픈 소스이고 둘째로 크로스 플랫폼이며 환경에 구애받지 않기 때문입니다. 하지만 고려해야 할 다른 대안도 있지만, 전반적인 목표는 이것이 인프라를 배포하는 방법이라는 것을 사람들에게 알리는 것입니다.
### Code Rot
이 세션에서 다루고자 하는 첫 번째 영역은 Code Rot으로, 애플리케이션 코드와 달리 코드로서의 인프라는 한 번 사용되었다가 오랫동안 사용하지 않을 수도 있습니다. Terraform을 사용하여 AWS에 VM 환경을 배포하려고 하는데, 처음에 완벽하게 작동하고 환경이 갖춰졌지만, 이 환경이 자주 변경되지 않아 코드가 중앙 위치에 저장되기를 바라지만 코드가 변경되지 않는 상태를 그대로 유지한다고 가정해 보겠습니다.
인프라에 변화가 생기면 어떻게 될까요? 하지만 대역 외에서 수행되거나 다른 환경이 변경되는 경우가 있습니다.
- 대역 외 변경 사항
- 고정되지 않은 버전
- 더 이상 사용되지 않는 종속성
- 적용되지 않은 변경 사항
### 테스트
코드 썩음과 일반적으로 뒤따르는 또 다른 큰 영역은 IaC를 테스트하고 모든 영역이 정상적으로 작동하는지 확인하는 기능입니다.
먼저 살펴볼 수 있는 몇 가지 기본 제공 테스트 명령어가 있습니다:
| Command | Description |
| -------------------- | ------------------------------------------------------------------------ |
| `terraform fmt` | Terraform 구성 파일을 표준 형식과 스타일로 다시 작성합니다. |
| `terraform validate` | 디렉터리에 있는 구성 파일의 유효성을 검사하여 구성만 참조합니다. |
| `terraform plan` | 실행 계획을 생성하여 Terraform이 계획한 변경 사항을 미리 볼 수 있습니다. |
| Custom validation | 입력 변수가 예상과 일치하는지 확인하기 위한 입력 변수 유효성 검사 |
Terraform 외부에서 사용할 수 있는 몇 가지 테스트 도구도 있습니다:
- [tflint](https://github.com/terraform-linters/tflint)
- 가능한 오류를 찾습니다.
- 더 이상 사용되지 않는 구문과 사용되지 않는 선언에 대해 경고합니다.
- 모범 사례와 명명 규칙을 적용합니다.
검사 도구
- [checkov](https://www.checkov.io/) - 클라우드 인프라 구성을 스캔하여 배포하기 전에 잘못된 구성을 찾습니다.
- [tfsec](https://aquasecurity.github.io/tfsec/v1.4.2/) - Terraform 코드에 대한 정적 분석 보안 스캐너입니다.
- [terrascan](https://github.com/accurics/terrascan) - IaC를 위한 정적 코드 분석기입니다.
- [terraform-compliance](https://terraform-compliance.com/) - IaC에 대한 네거티브 테스트 기능을 지원하는 Terraform에 대한 경량의 보안 및 규정 준수 중심 테스트 프레임워크입니다.
- [snyk](https://docs.snyk.io/products/snyk-infrastructure-as-code/scan-terraform-files/scan-and-fix-security-issues-in-terraform-files) - Terraform 코드에서 잘못된 구성과 보안 문제를 스캔합니다.
관리형 클라우드 제품
- [Terraform Sentinel](https://www.terraform.io/cloud-docs/sentinel) - HashCorp 엔터프라이즈 제품과 통합된 임베디드 정책 기반 프레임워크로 세분화된 로직 기반 정책 결정을 가능하게 하며, 외부 소스의 정보를 사용하도록 확장할 수 있습니다.
### 자동화된 테스트
- [Terratest](https://terratest.gruntwork.io/) - Terratest는 인프라 테스트를 위한 패턴과 도우미 함수를 제공하는 Go 라이브러리입니다.
- Terratest는 인프라 코드에 대한 자동화된 테스트 작성을 용이하게 합니다. 일반적인 인프라 테스트를 위한 다양한 도우미 함수와 패턴을 제공합니다.
- 코드는 2022/Days/IaC/Terratest에서 찾을 수 있습니다.
- 이 애플리케이션을 실행하려면
- git clone #repo_url# <br />
- cd test <br />
- go mod init "<MODULE_NAME>" <br />
**MODULE_NAME은 github.com/<YOUR_USERNAME>/<YOUR_REPO_NAME>이 됩니다.** <br />
- go mod init github.com/<FOLDER-PATH> <br/>
- go run
---
go mod init "<MODULE_NAME>"은 테스트 폴더에 go.mod 파일을 생성합니다. <br />
- go.mod 파일은 GoLang에서 의존성 관리의 기초입니다.
- 프로젝트에서 필요하거나 사용할 모든 모듈이 go.mod 파일에 유지됩니다.
- 프로젝트에서 사용하거나 가져올 모든 패키지의 항목을 생성합니다.
- 수동으로 각 종속성을 가져오는 노력을 줄입니다.
처음 **go test**를 실행하면 go.sum 파일이 생성됩니다. <br />
- **go test** 또는 **go build**가 처음 실행될 때 go.sum 파일이 생성됩니다.
- 특정 버전(최신)으로 모든 패키지를 설치합니다.
- 우린 파일을 편집하거나 수정할 필요가 없습니다.
추가로 언급할 만한 것들
- [Terraform 클라우드](https://cloud.hashicorp.com/products/terraform) - Terraform 클라우드는 HashCorp의 관리형 서비스 제품입니다. 실무자, 팀 및 조직이 프로덕션에서 Terraform을 사용하기 위해 불필요한 도구와 문서가 필요하지 않습니다.
- [Terragrunt](https://terragrunt.gruntwork.io/) - Terragrunt는 구성을 건조하게 유지하고, 여러 Terraform 모듈로 작업하고, 원격 상태를 관리하기 위한 추가 도구를 제공하는 얇은 래퍼입니다.
- [Atlantis](https://www.runatlantis.io/) - Terraform 풀 리퀘스트 자동화
### 대안
이 섹션을 시작할 때 57일째에 몇 가지 대안이 있다고 언급했으며, 이번 챌린지에서도 이에 대해 계속 살펴볼 계획입니다.
| Cloud Specific | Cloud Agnostic |
| ------------------------------- | -------------- |
| AWS CloudFormation | Terraform |
| Azure Resource Manager | Pulumi |
| Google Cloud Deployment Manager | |
저는 위의 목록 중 AWS CloudFormation을 가장 많이 사용했으며 AWS에서 기본으로 제공하지만, Terraform 이외의 다른 제품은 사용해 본 적이 없습니다. 클라우드별 버전은 특정 클라우드에서는 매우 훌륭하지만, 여러 클라우드 환경이 있는 경우 이러한 구성을 마이그레이션하는 데 어려움을 겪거나 IaC 작업을 위해 여러 관리 플레인을 사용해야 할 것입니다.
흥미로운 다음 단계는 시간을 내서 [Pulumi](https://www.pulumi.com/)에 대해 자세히 알아보는 것입니다.
Pulumi 사이트의 비교 부분에서
> "Terraform과 Pulumi 모두 코드가 원하는 인프라 상태를 나타내는 코드 모델로 원하는 상태 인프라를 제공하며, 배포 엔진은 이 원하는 상태를 스택의 현재 상태와 비교하여 어떤 리소스를 생성, 업데이트 또는 삭제해야 하는지를 결정합니다."
제가 볼 수 있는 가장 큰 차이점은 HCL(HashCorp 구성 언어)과 달리 Pulumi는 Python, TypeScript, JavaScript, Go, .NET과 같은 범용 언어를 허용한다는 점입니다.
간략한 개요 [Pulumi 소개: 코드형 최신 인프라](https://www.youtube.com/watch?v=QfJTJs24-JM) 저는 선택의 폭이 넓다는 점이 마음에 들어서 좀 더 자세히 알아보고 싶었습니다.
이것으로 IaC 섹션을 마무리하고, 다음에는 구성 관리와 약간 겹치는 부분, 특히 일부 작업 및 데모에 Ansible을 사용할 구성 관리의 큰 그림을 살펴볼 것입니다.
## 리소스
아래에 많은 리소스를 나열했으며 이 주제는 이미 여러 번 다루어졌다고 생각합니다. 추가 리소스가 있는 경우 리소스와 함께 PR을 올리면 기꺼이 검토하여 목록에 추가해 드리겠습니다.
- [What is Infrastructure as Code? Difference of Infrastructure as Code Tools](https://www.youtube.com/watch?v=POPP2WTJ8es)
- [Terraform Tutorial | Terraform Course Overview 2021](https://www.youtube.com/watch?v=m3cKkYXl-8o)
- [Terraform explained in 15 mins | Terraform Tutorial for Beginners](https://www.youtube.com/watch?v=l5k1ai_GBDE)
- [Terraform Course - From BEGINNER to PRO!](https://www.youtube.com/watch?v=7xngnjfIlK4&list=WL&index=141&t=16s)
- [HashiCorp Terraform Associate Certification Course](https://www.youtube.com/watch?v=V4waklkBC38&list=WL&index=55&t=111s)
- [Terraform Full Course for Beginners](https://www.youtube.com/watch?v=EJ3N-hhiWv0&list=WL&index=39&t=27s)
- [KodeKloud - Terraform for DevOps Beginners + Labs: Complete Step by Step Guide!](https://www.youtube.com/watch?v=YcJ9IeukJL8&list=WL&index=16&t=11s)
- [Terraform Simple Projects](https://terraform.joshuajebaraj.com/)
- [Terraform Tutorial - The Best Project Ideas](https://www.youtube.com/watch?v=oA-pPa0vfks)
- [Awesome Terraform](https://github.com/shuaibiyy/awesome-terraform)
- [Pulumi - IaC in your favorite programming language!](https://www.youtube.com/watch?v=vIjeiDcsR3Q&t=51s)
[Day 63](day63.md)에서 봐요!

101
2022/ko/Days/day63.md Normal file
View File

@ -0,0 +1,101 @@
---
title: '#90DaysOfDevOps - The Big Picture: Configuration Management - Day 63'
published: false
description: 90DaysOfDevOps - The Big Picture Configuration Management
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048711
---
## 큰 그림: 구성 관리
IaC를 다루는 섹션의 뒷부분에서 바로 이어서 구성 관리 또는 애플리케이션 구성 관리에 대해 이야기할 때 약간의 교차점이 있을 것입니다.
구성 관리는 애플리케이션, 시스템, 서버를 원하는 상태로 유지하는 프로세스입니다. 인프라스트럭처와 겹치는 부분은 IaC가 인프라가 원하는 상태에 있는지 확인하지만, 그 이후에는 특히 Terraform이 OS 설정이나 애플리케이션의 원하는 상태를 관리하지 않기 때문에 구성 관리 도구가 필요하다는 점입니다. Deane에서 변경 사항이 발생할 때 시스템과 애플리케이션이 예상대로 작동하는지 확인합니다.
구성 관리는 문서화되지 않은 크고 작은 변경을 방지합니다.
### 시나리오: 구성 관리를 사용하려는 이유
구성 관리를 사용하고자 하는 시나리오나 이유를 알기 위해 철수를 만나보세요. 철수는 우리의 시스템 관리자이며, 환경 내의 모든 시스템에서 열심히 일하며 만족하는 사람입니다.
시스템에 장애가 발생하거나 화재가 발생하거나 서버가 다운되면 어떻게 될까요? 철수는 화재가 발생하면 어떻게 해야 하는지 정확히 알고 있기 때문에 쉽게 해결할 수 있지만, 특히 대규모로 확장하는 환경에서 여러 서버가 장애를 일으키기 시작하면 철수에게 구성 관리 도구가 필요한 이유가 바로 여기에 있습니다. 구성 관리 도구는 철수가 각 서버를 빠르고 효과적으로 대규모로 설정하는 방법에 대한 지침을 푸시할 수 있는 올바른 코드를 구성하기만 하면 되는 록스타처럼 보이도록 도와줄 수 있습니다.
### 구성 관리 도구
다양한 구성 관리 도구를 사용할 수 있으며, 각 도구에는 특정 상황에 더 적합한 특정 기능이 있습니다.
![](/2022/Days/Images/Day63_config1.png)
이 단계에서는 위 그림의 옵션을 간략히 살펴본 후 어떤 도구를 사용할지, 왜 사용할지 결정하겠습니다.
- **Chef**
- Chef는 인프라 자동화를 통해 모든 환경, 모든 규모에서 구성이 일관되게 적용되도록 보장합니다.
- Chef는 Ruby와 Erlang으로 작성된 OpsCode에서 개발한 오픈 소스 도구입니다.
- Chef는 이기종 인프라를 보유하고 있으며 성숙한 솔루션을 찾고 있는 조직에 가장 적합합니다.
- Recipes와 Cookbooks은 시스템의 구성 코드를 결정합니다.
- 프로 - 방대한 Recipes 컬렉션을 사용할 수 있습니다.
- 장점 - 강력한 버전 제어를 제공하는 Git과 잘 통합됩니다.
- 단점 - 학습 곡선이 가파르며 상당한 시간이 필요합니다
- 단점 - 메인 서버에서 제어할 수 있는 권한이 많지 않습니다.
- 아키텍처 - 서버/클라이언트
- 설정 용이성 - 보통
- 언어 - 절차적 - 작업 수행 방법 지정
- **Puppet**
- Puppet은 자동 배포를 지원하는 구성 관리 도구입니다.
- Puppet은 Ruby로 빌드되며 매니페스트 작성에 DSL을 사용합니다.
- Puppet은 확장성에 중점을 둔 이기종 인프라에서도 잘 작동합니다.
- 장점 - 지원을 위한 대규모 커뮤니티가 있습니다.
- 장점 - 잘 발달된 보고 메커니즘입니다.
- 단점 - 고급 작업을 수행하려면 Ruby 언어에 대한 지식이 필요합니다.
- 단점 - 메인 서버에 대한 제어 권한이 많지 않습니다.
- 아키텍처 - 서버/클라이언트
- 설정 용이성 - 보통
- 언어 - 선언적 - 수행할 작업만 지정 가능
- **Ansible**
- Ansible은 구성 관리, 클라우드 프로비저닝, 배포 및 오케스트레이션을 자동화하는 IT 자동화 도구입니다.
- Ansible Playbook의 핵심은 YAML로 작성되어 있습니다. (몇 번 본 적이 있으므로 YAML에 대한 섹션을 만들어야 합니다.)
- Ansible은 빠르게 시작하고 실행하는 데 중점을 두는 환경이 있을 때 잘 작동합니다.
- 서버에 지침을 제공하는 Playbook에서 작동합니다.
- 장점 - 원격 노드에 에이전트가 필요하지 않습니다.
- 장점 - YAML은 배우기 쉽습니다.
- 단점 - 성능 속도가 다른 도구보다 느린 경우가 많습니다.(철수가 직접 수동으로 수행하는 것보다 빠름)
- 단점 - YAML은 Ruby만큼 강력하지는 않지만 학습 곡선이 적습니다.
- 아키텍처 - 클라이언트 전용
- 설정 용이성 - 매우 쉬움
- 언어 - 절차적 - 작업 수행 방법 지정
- **SaltStack**
- SaltStack은 구성 관리와 원격 실행을 자동화하는 CLI 기반 도구입니다.
- SaltStack은 Python 기반이며, 명령어는 YAML 또는 해당 DSL로 작성됩니다.
- 확장성과 복원력을 최우선으로 고려하는 환경에 적합합니다.
- 장점 - 가동 및 실행 시 사용이 간편합니다.
- 장점 - 우수한 보고 메커니즘입니다.
- 단점 - 설정 단계가 까다롭습니다.
- 단점 - 다른 서비스보다 훨씬 덜 개발된 새로운 웹 UI가 있습니다.
- 아키텍처 - 서버/클라이언트
- 설정 용이성 - 보통
- 언어 - 선언적 - 수행할 작업만 지정함
### Ansible과 Terraform 비교
이 섹션에서 사용할 도구는 Ansible입니다. (사용하기 쉽고 언어에 지식이 약간만 필요합니다.)
도구를 좀 더 자세히 살펴보기 전에 Ansible과 Terraform의 몇 가지 차이점을 살펴보는 것이 중요하다고 생각합니다.
| | Ansible | Terraform |
| ----------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| 유형 | Ansible은 구성 관리 도구입니다. | Terraform은 오케스트레이션 도구입니다. |
| 인프라 | Ansible은 변경 가능한 인프라를 지원하며, Terraform은 변경 불가능한 인프라를 지원합니다. |
| 언어 | Ansible은 절차적 언어를 따르고, Terraform은 선언적 언어를 따릅니다. |
| 프로비저닝 | 부분 프로비저닝(VM, 네트워크, 스토리지) 제공합니다. | Terraform은 광범위한 프로비저닝(VM, 네트워크, 스토리지) 제공합니다. |
| 패키징 | 패키징 및 템플릿에 대한 완벽한 지원 제공합니다. | 패키징 및 템플릿에 대한 부분 지원 제공합니다. |
| 라이프사이클 관리 | Ansible에는 라이프사이클 관리 기능이 없습니다. | Terraform은 라이프사이클 및 상태 관리에 크게 의존합니다. |
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
[Day 64](day64.md)에서 봐요!

87
2022/ko/Days/day64.md Normal file
View File

@ -0,0 +1,87 @@
---
title: '#90DaysOfDevOps - Ansible: Getting Started - Day 64'
published: false
description: '90DaysOfDevOps - Ansible: Getting Started'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048765
---
## Ansible: 시작하기
어제 [Day 63](day63.md)에서 Ansible이 무엇인지에 대해 조금 다루었지만 여기서는 이에 대해 조금 더 자세히 알아보겠습니다. 먼저 Ansible은 RedHat에서 제공합니다. 둘째, 에이전트가 없으며 SSH를 통해 연결하고 명령을 실행합니다. 셋째, 크로스 플랫폼(Linux 및 macOS, WSL2) 및 오픈 소스(엔터프라이즈용 유료 옵션도 있음)이며 다른 모델에 비해 Ansible은 구성을 push합니다.
### Ansible 설치
여러분이 상상할 수 있듯이, RedHat과 Ansible 팀은 Ansible을 문서화하는 데 환상적인 작업을 해왔습니다. 이는 일반적으로 [여기](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)에서 찾을 수 있는 설치 단계부터 시작됩니다. Ansible은 에이전트가 없는 자동화 도구이며, 이 도구는 "Control Node"라고 하는 시스템에 배포되고 이 Control Node에서 SSH를 통해 머신 및 기타 장치(네트워크일 수 있음)를 관리한다고 말씀드린 것을 기억하세요.
위에 링크된 문서에는 Windows OS를 Control Node로 사용할 수 없다고 명시되어 있습니다.
Control Node 및 적어도 이 데모에서는 [Linux 섹션](day20.md)에서 만든 Linux VM을 Control Node로 사용하겠습니다.
이 시스템은 우분투를 실행 중이며 설치 단계는 다음 명령만 있으면 됩니다.
```Shell
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
```
이제 Control Node에 ansible이 설치되어 있어야 하며, `ansible --version`을 실행하여 확인할 수 있으며 아래와 비슷한 내용이 표시됩니다.
![](/2022/Days/Images/Day64_config1.png)
이제 환경의 다른 Node를 제어하는 방법을 살펴보기 전에 로컬 머신에 대해 `ansible localhost -m ping` 명령을 실행하여 ansible의 기능을 확인할 수도 있습니다. 이 명령은 [Ansible 모듈](https://docs.ansible.com/ansible/2.9/user_guide/modules_intro.html)을 사용하며, 여러 시스템에서 하나의 작업을 빠르게 수행할 수 있는 방법이기도 합니다. 로컬 호스트만으로는 그다지 재미있지 않지만, 무언가를 얻거나 모든 시스템이 가동 중이고 1000개 이상의 서버와 디바이스가 있다고 상상해 보세요.
![](/2022/Days/Images/Day64_config2.png)
또는 실제 모듈의 실제 사용법은 `ansible webservers -m service -a "name=httpd state=started"`와 같이 모든 웹서버에 httpd 서비스가 실행 중인지 여부를 알려주는 것일 수 있습니다. 이 명령에 사용된 웹서버 용어에 대해 간략히 설명했습니다.
### 호스트
위에서 localhost를 사용하여 시스템에 대한 간단한 핑 모듈을 실행하는 방법으로는 네트워크에 다른 컴퓨터를 지정할 수 없습니다. 예를 들어 VirtualBox가 실행 중인 Windows 호스트에는 IP 10.0.0.1의 네트워크 어댑터가 있지만 아래에서 볼 수 있듯이 핑으로 연결할 수 있지만 ansible을 사용하여 해당 작업을 수행할 수 없습니다.
![](/2022/Days/Images/Day64_config3.png)
이러한 작업으로 자동화할 호스트 또는 Node를 지정하려면 이를 정의해야 합니다. 시스템의 /etc/ansible 디렉토리로 이동하여 정의할 수 있습니다.
![](/2022/Days/Images/Day64_config4.png)
편집하려는 파일은 호스트 파일이며, 텍스트 편집기를 사용하여 호스트를 정의할 수 있습니다. 호스트 파일에는 파일을 사용하고 수정하는 방법에 대한 많은 훌륭한 지침이 포함되어 있습니다. 아래로 스크롤하여 [windows]라는 새 그룹을 만들고 해당 호스트에 대한 `10.0.0.1` IP 주소를 추가하겠습니다. 파일을 저장합니다.
![](/2022/Days/Images/Day64_config5.png)
그러나 Ansible이 시스템에 연결하려면 SSH를 사용할 수 있어야 한다고 말씀드린 것을 기억하세요. 아래에서 볼 수 있듯이 `ansible windows -m ping`을 실행하면 SSH를 통한 연결에 실패하여 연결할 수 없다는 메시지가 표시됩니다.
![](/2022/Days/Images/Day64_config6.png)
이제 인벤토리에 호스트를 추가하기 시작했는데, 모든 장치를 정의하는 곳이기 때문에 이 파일의 다른 이름인 네트워크 장치, 스위치 및 라우터도 여기에 추가하고 그룹화할 수 있습니다. 하지만 호스트 파일에는 Linux 시스템 그룹에 액세스하기 위한 자격 증명도 추가했습니다.
![](/2022/Days/Images/Day64_config7.png)
이제 `ansible Linux -m ping`을 실행하면 아래와 같이 성공합니다.
![](/2022/Days/Images/Day64_config8.png)
이제 구성을 자동화하려는 대상 시스템인 Node 요구 사항이 있습니다. 이 시스템에는 Ansible을 위한 어떤 것도 설치하지 않습니다(소프트웨어를 설치할 수는 있지만 필요한 Ansible의 클라이언트는 없습니다). Ansible은 SSH를 통해 연결하고 SFTP를 통해 모든 것을 전송합니다. (원하는 경우 SSH를 구성한 경우 SCP 대 SFTP를 사용할 수 있습니다.)
### Ansible 명령
리눅스 머신에 대해 `ansible Linux -m ping`을 실행하고 응답을 얻을 수 있는 것을 보셨겠지만, 기본적으로 Ansible을 사용하면 많은 adhoc 명령을 실행할 수 있습니다. 하지만 이 명령을 시스템 그룹에 대해 실행하여 해당 정보를 다시 가져올 수 있습니다. [adhoc 명령](https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html)
명령을 반복하거나 이러한 명령을 실행하기 위해 개별 시스템에 로그인해야 하는 경우 Ansible이 도움이 될 수 있습니다. 예를 들어, 아래의 간단한 명령은 Linux 그룹에 추가하는 모든 시스템에 대한 모든 운영 체제 세부 정보를 출력합니다.
`ansible linux -a "cat /etc/os-release"`
다른 사용 사례로는 시스템 재부팅, 파일 복사, 패커 및 사용자 관리 등이 있습니다. adhoc 명령과 Ansible 모듈을 결합할 수도 있습니다.
adhoc 명령은 선언적 모델을 사용하여 지정된 최종 상태에 도달하는 데 필요한 작업을 계산하고 실행합니다. adhoc 명령은 시작하기 전에 현재 상태를 확인하고 현재 상태가 지정된 최종 상태와 다르지 않으면 아무 작업도 수행하지 않음으로써 일종의 무임승차를 하는 셈입니다.
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
[Day 65](day65.md)에서 봐요!

278
2022/ko/Days/day65.md Normal file
View File

@ -0,0 +1,278 @@
---
title: '#90DaysOfDevOps - Ansible Playbooks - Day 65'
published: false
description: 90DaysOfDevOps - Ansible Playbooks
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049054
---
### Ansible Playbook
이 섹션에서는 적어도 Ansible의 경우 하나의 명령으로 여러 서버를 실행하여 긴 서버 목록을 재부팅하는 것과 같은 간단한 명령을 수행하고 각 서버에 개별적으로 연결해야 하는 번거로움을 줄일 수 있다는 점이 가장 큰 장점이라고 할 수 있습니다.
하지만 실제로 베어 운영 체제를 가져와서 해당 시스템에서 실행할 소프트웨어와 서비스를 선언하고 모두 원하는 상태로 실행되도록 하는 것은 어떨까요?
이것이 바로 Ansible Playbook이 필요한 이유입니다. Playbook을 사용하면 서버 그룹을 가져와서 해당 그룹에 대해 구성 및 설치 작업을 수행할 수 있습니다.
### Playbook 형식
Playbook > Play > Task
스포츠에 관심이 있는 분이라면 Playbook이라는 용어를 들어보셨을 텐데요, Playbook은 다양한 Play와 Task로 구성된 Play 방법을 팀에게 알려주는 것으로, Play를 스포츠나 게임의 세트 피스라고 생각하면 각 Play에 Task가 연관되어 있고, Play를 구성하는 여러 Task가 있을 수 있으며, Playbook에는 여러 가지 다른 Play가 있을 수 있습니다.
이러한 Playbook은 YAML(YAML은 마크업 언어가 아님)로 작성되어 있으며, 지금까지 다룬 많은 섹션, 특히 컨테이너와 Kubernetes에서 YAML 형식의 구성 파일을 찾을 수 있습니다.
playbook.yml이라는 간단한 Playbook을 살펴보겠습니다.
```Yaml
- name: Simple Play
hosts: localhost
connection: local
tasks:
- name: Ping me
ping:
- name: print os
debug:
msg: "{{ ansible_os_family }}"
```
위의 파일 [simple_play](/2022/Days/Configmgmt/simple_play.yml)을 찾을 수 있습니다. 그런 다음 `ansible-playbook simple_play.yml` 명령을 사용하면 다음 단계를 수행합니다.
![](/2022/Days/Images/Day65_config1.png)
'gathering facts'라는 첫 번째 Task가 발생한 것을 볼 수 있지만, 우리가 트리거하거나 요청하지 않았나요? 이 모듈은 원격 호스트에 대한 유용한 변수를 수집하기 위해 Playbook에서 자동으로 호출됩니다. [ansible.builtin.setup](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html)
두 번째 Task는 Ping을 설정하는 것이었는데, 이것은 ICMP Ping이 아니라 원격 또는 로컬 호스트에 대한 연결 성공 시 `pong`을 반환하는 파이썬 스크립트입니다. [ansible.builtin.ping](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ping_module.html)
그런 다음 첫 번째 Task로 정의한 세 번째 또는 두 번째 Task는 OS를 알려주는 메시지 인쇄를 비활성화하지 않는 한 실행됩니다. 이 Task에서는 조건문을 사용하고 있으므로 모든 유형의 운영 체제에 대해 이 Playbook을 실행할 수 있으며, 그러면 OS 이름이 반환됩니다. 편의상 이 출력은 단순히 메시지를 출력하고 있지만 다음과 같이 말하는 Task를 추가할 수 있습니다:
```Yaml
tasks:
- name: "shut down Debian flavoured systems"
command: /sbin/shutdown -t now
when: ansible_os_family == "Debian"
```
### Vagrant로 환경 설정하기
Vagrant를 사용하여 Node 환경을 설정할 것입니다. 저는 이것을 합리적인 4 Node로 유지하려고 하지만 300 Node 또는 3000 Node가 될 수 있으며 이것이 서버를 구성할 수 있는 Ansible 및 기타 구성 관리 도구의 힘이라는 것을 알 수 있기를 바랍니다.
이 파일은 [여기](/2022/Days/Configmgmt/Vagrantfile)에서 찾을 수 있습니다.
```Vagrant
Vagrant.configure("2") do |config|
servers=[
{
:hostname => "db01",
:box => "bento/ubuntu-21.10",
:ip => "192.168.169.130",
:ssh_port => '2210'
},
{
:hostname => "web01",
:box => "bento/ubuntu-21.10",
:ip => "192.168.169.131",
:ssh_port => '2211'
},
{
:hostname => "web02",
:box => "bento/ubuntu-21.10",
:ip => "192.168.169.132",
:ssh_port => '2212'
},
{
:hostname => "loadbalancer",
:box => "bento/ubuntu-21.10",
:ip => "192.168.169.134",
:ssh_port => '2213'
}
]
config.vm.base_address = 600
servers.each do |machine|
config.vm.define machine[:hostname] do |node|
node.vm.box = machine[:box]
node.vm.hostname = machine[:hostname]
node.vm.network :public_network, bridge: "Intel(R) Ethernet Connection (7) I219-V", ip: machine[:ip]
node.vm.network "forwarded_port", guest: 22, host: machine[:ssh_port], id: "ssh"
node.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 2048]
v.customize ["modifyvm", :id, "--name", machine[:hostname]]
end
end
end
end
```
`vagrant up` 명령을 사용하여 VirtualBox에서 이러한 머신을 스핀업하면 메모리를 더 추가할 수 있고 각 머신에 대해 다른 private_network 주소를 정의할 수도 있지만 제 환경에서는 이 방법이 작동합니다. 컨트롤 박스는 리눅스 섹션에서 배포한 우분투 데스크톱이라는 점을 기억하세요.
리소스가 제한되어 있는 경우 `vagrant up web01 web02`를 실행하여 여기서 사용 중인 웹서버만 불러올 수도 있습니다.
### Ansible 호스트 구성
이제 환경이 준비되었으므로 Ansible을 확인할 수 있으며, 이를 위해 우분투 데스크톱(이 데스크톱을 사용할 수도 있지만 아래 네트워크에 액세스하는 네트워크에 있는 모든 Linux 기반 머신을 동일하게 사용할 수 있음)을 컨트롤로 사용하고, ansible 호스트 파일에서 새 Node를 그룹에 추가해 보겠습니다, 이 파일을 인벤토리로 생각할 수 있으며, 이에 대한 대안으로 `-i filename`을 사용하여 ansible 명령의 일부로 호출되는 또 다른 인벤토리 파일을 사용할 수 있습니다. 이는 프로덕션, 테스트 및 스테이징 환경마다 다른 파일을 가질 수 있으므로 호스트 파일을 사용하는 것보다 유용할 수 있습니다. 기본 호스트 파일을 사용하고 있으므로 이 파일을 기본으로 사용하므로 지정할 필요가 없습니다.
기본 호스트 파일에 다음을 추가했습니다.
```Text
[control]
ansible-control
[proxy]
loadbalancer
[webservers]
web01
web02
[database]
db01
```
![](/2022/Days/Images/Day65_config2.png)
계속 진행하기 전에 Node에 대해 명령을 실행할 수 있는지 확인하기 위해 `ansible nodes -m command -a hostname`을 실행해 보겠습니다. 이 간단한 명령은 연결이 있는지 테스트하고 호스트 이름을 다시 보고합니다.
또한, 연결을 보장하기 위해 /etc/hosts 파일 내의 Ubuntu 제어 Node에 이러한 Node와 IP를 추가했습니다. 우분투 상자에서 각 Node에 대해 SSH 구성을 수행해야 할 수도 있습니다.
```Text
192.168.169.140 ansible-control
192.168.169.130 db01
192.168.169.131 web01
192.168.169.132 web02
192.168.169.133 loadbalancer
```
![](/2022/Days/Images/Day65_config3.png)
이 단계에서는 제어 Node와 서버 Node 사이에 SSH 키를 설정하는 과정을 진행하겠습니다. 다음 단계에서는 호스트의 파일에 변수를 추가하여 사용자 이름과 비밀번호를 제공하는 방법을 사용할 수 있습니다. 이 방법은 결코 모범 사례가 될 수 없으므로 권장하지 않습니다.
SSH를 설정하고 Node 간에 공유하려면 아래 단계를 따르세요. 비밀번호(`vagrant`)를 묻는 메시지가 표시되면 `y`를 몇 번 눌러야 수락할 수 있습니다.
`ssh-keygen`
![](/2022/Days/Images/Day65_config5.png)
`ssh-copy-id localhost`
![](/2022/Days/Images/Day65_config6.png)
이제 모든 VM이 켜져 있다면 `ssh-copy-id web01 && ssh-copy-id web02 && ssh-copy-id loadbalancer && ssh-copy-id db01`을 실행하면 비밀번호를 입력하라는 메시지가 표시됩니다(이 경우 비밀번호는 `vagrant`입니다).
모든 VM을 실행하지 않고 웹서버만 실행하고 있으므로 `ssh-copy-id web01 && ssh-copy-id web02`를 발급했습니다.
![](/2022/Days/Images/Day65_config7.png)
Playbook을 실행하기 전에 그룹과 간단하게 연결되었는지 확인하고 싶어서 `ansible webservers -m ping`을 실행하여 연결을 테스트했습니다.
![](/2022/Days/Images/Day65_config4.png)
### 첫 번째 "진짜" Ansible Playbook
첫 번째 Ansible Playbook은 웹 서버를 구성하는 것으로, 호스트 파일에서 [webservers] 그룹 아래에 웹 서버를 그룹화했습니다.
Playbook을 실행하기 전에 web01과 web02에 apache가 설치되어 있지 않은 것을 확인할 수 있습니다. 아래 스크린샷 상단은 이 Playbook을 실행하기 위해 ansible 컨트롤 내에서 생성한 폴더 및 파일 레이아웃을 보여줍니다. `playbook1.yml`이 있고, template 폴더에는 `index.html.j2``ports.conf.j2` 파일이 있습니다. 이 파일은 위에 나열된 리포지토리 폴더에서 찾을 수 있습니다.
그런 다음 web01에 SSH로 접속하여 apache가 설치되어 있는지 확인합니다.
![](/2022/Days/Images/Day65_config8.png)
위에서 web01에 apache가 설치되어 있지 않다는 것을 알 수 있으므로 아래 Playbook을 실행하여 이 문제를 해결할 수 있습니다.
```Yaml
- hosts: webservers
become: yes
vars:
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps"
tasks:
- name: ensure apache is at the latest version
apt:
name: apache2
state: latest
- name: write the apache2 ports.conf config file
template:
src: templates/ports.conf.j2
dest: /etc/apache2/ports.conf
notify:
- restart apache
- name: write a basic index.html file
template:
src: templates/index.html.j2
dest: /var/www/html/index.html
notify:
- restart apache
- name: ensure apache is running
service:
name: apache2
state: started
handlers:
- name: restart apache
service:
name: apache2
state: restarted
```
위의 Playbook을 분석합니다:
- `host: webserver`는 이 Playbook을 실행할 그룹이 웹서버라는 그룹이라는 것을 의미합니다.
- `become: yes`는 Playbook을 실행하는 사용자가 원격 시스템에서 루트가 된다는 의미입니다. 루트 비밀번호를 입력하라는 메시지가 표시됩니다.
- 그런 다음 `vars`가 있는데, 이는 웹서버 전체에서 원하는 몇 가지 환경 변수를 정의합니다.
그런 다음 Task를 시작합니다,
- Task 1은 apache가 최신 버전을 실행 중인지 확인하는 것입니다.
- Task 2는 template 폴더에 있는 소스에서 ports.conf 파일을 작성하는 것입니다.
- Task 3은 기본 index.html 파일을 생성하는 것입니다.
- Task 4는 apache가 실행 중인지 확인하는 것입니다.
마지막으로 Handler 섹션인 [Handler: 변경에 대한 Task 실행](https://docs.ansible.com/ansible/latest/user_guide/playbooks_handlers.html)이 있습니다.
"때로는 컴퓨터에서 변경이 이루어질 때만 Task가 실행되기를 원할 때가 있습니다. 예를 들어, 태스크가 해당 서비스의 구성을 업데이트하지만, 구성이 변경되지 않은 경우 서비스를 다시 시작하고 싶을 수 있습니다. Ansible은 이 사용 사례를 해결하기 위해 Handler를 사용합니다. Handler는 알림을 받을 때만 실행되는 태스크입니다. 각 Handler는 전 세계적으로 고유한 이름을 가져야 합니다."
이 단계에서는 5개의 VM을 배포했다고 생각할 수 있습니다(Ansible 컨트롤 역할을 하는 Ubuntu 데스크톱 머신 포함). 다른 시스템은 이 섹션의 나머지 부분에서 다루게 될 것입니다.
### Playbook 실행
이제 Node에 대해 Playbook을 실행할 준비가 되었습니다. Playbook을 실행하려면 `ansible-playbook playbook1.yml`을 사용하면 됩니다. Playbook 내에서 Playbook이 실행될 호스트를 정의했으며, 정의한 Task를 안내합니다.
명령이 완료되면 Play와 Task를 보여주는 출력이 표시되며, 아래 이미지에서 원하는 상태를 설치하는 데 시간이 걸리는 것을 확인할 수 있습니다.
![](/2022/Days/Images/Day65_config9.png)
그런 다음 Node로 이동하여 Node에 소프트웨어가 설치되었는지 확인하여 이를 다시 확인할 수 있습니다.
![](/2022/Days/Images/Day65_config10.png)
위와 같이 두 개의 독립형 웹서버를 배포했으므로 이제 정의한 각각의 IP로 이동하여 새 웹 사이트를 가져올 수 있습니다.
![](/2022/Days/Images/Day65_config11.png)
이 섹션의 나머지 부분을 진행하면서 이 Playbook을 기반으로 구축할 것입니다. 또한 Ubuntu 데스크톱을 가져와서 Ansible을 사용하여 애플리케이션과 구성을 부트스트랩할 수 있는지 살펴보고 싶어서 이 부분도 다뤄볼 수 있을 것 같습니다. 예를 들어 명령에서 로컬 호스트를 사용하여 로컬 호스트에 대해 Playbook을 실행할 수 있다는 것을 보셨습니다.
여기에 추가해야 할 또 다른 사항은 우리는 실제로 Ubuntu VM으로만 작업하고 있지만 Ansible은 대상 시스템에 구애받지 않는다는 것입니다. 시스템을 관리하기 위해 이전에 언급했던 대안은 서버별로 서버를 관리할 수 있습니다(서버 수가 많을 경우 확장성이 떨어지고 Node가 3개일 때도 문제가 있음) Linux 섹션에서 다시 다룬 셸 스크립팅을 사용할 수도 있지만 이러한 Node는 잠재적으로 다를 수 있으므로 가능하지만 누군가 스크립트를 유지 및 관리해야 합니다. Ansible은 무료이며 전문화된 스크립트가 필요 없는 대신 간편한 버튼을 누릅니다.
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
위에 나열된 마지막 재생 목록은 이 섹션의 많은 코드와 아이디어가 나온 곳이며, 동영상 형식의 훌륭한 리소스이자 워크스루입니다.
[Day 66](day66.md)에서 봐요!

130
2022/ko/Days/day66.md Normal file
View File

@ -0,0 +1,130 @@
---
title: '#90DaysOfDevOps - Ansible Playbooks Continued... - Day 66'
published: false
description: 90DaysOfDevOps - Ansible Playbooks Continued...
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048712
---
## Ansible Playbook (계속)
지난 섹션에서는 vagrant 파일을 사용하여 4대의 머신을 배포하는 작은 실험실을 만드는 것으로 시작했고, 이 섹션에서 만든 Linux 머신을 Ansible 제어 시스템으로 사용했습니다.
또한 Playbook의 몇 가지 시나리오를 실행했고 마지막에는 web01과 web02를 개별 웹 서버로 만드는 Playbook을 만들었습니다.
![](/2022/Days/Images/Day66_config1.png)
### 깔끔하게 정리하기
추가 자동화 및 배포를 시작하기 전에 Playbook을 간결하고 깔끔하게 유지하는 기능과 작업과 Handler를 하위 폴더로 분리하는 방법에 대해 다뤄야 합니다.
작업을 폴더 내의 해당 파일에 복사하겠습니다.
```Yaml
- name: ensure apache is at the latest version
apt: name=apache2 state=latest
- name: write the apache2 ports.conf config file
template:
src=templates/ports.conf.j2
dest=/etc/apache2/ports.conf
notify: restart apache
- name: write a basic index.html file
template:
src: templates/index.html.j2
dest: /var/www/html/index.html
notify:
- restart apache
- name: ensure apache is running
service:
name: apache2
state: started
```
Handler도 마찬가지입니다.
```Yaml
- name: restart apache
service:
name: apache2
state: restarted
```
Playbook의 이름을 `playbook2.yml`로 지정한 다음, 이 파일을 가리킵니다. 이 모든 파일은 [ansible-scenario2](/2022/Days/Configmgmt/ansible-scenario2/)에서 찾을 수 있습니다.
제어 머신에서 테스트할 수 있습니다. 리포지토리에서 파일을 복사한 경우 "write a basic index.html file"에서 변경된 사항을 발견했을 것입니다.
![](/2022/Days/Images/Day66_config2.png)
`curl web01:8000`을 사용하여 어떤 간단한 변경이 있었는지 알아봅시다.
![](/2022/Days/Images/Day66_config3.png)
방금 Playbook을 정리하고 규모에 따라 Playbook을 매우 압도적으로 만들 수 있는 영역을 분리하기 시작했습니다.
### Role과 Ansible Galaxy
현재 4개의 VM을 배포했으며 이 중 2개의 VM을 웹 서버로 구성했지만 데이터베이스 서버와 로드 밸런서 또는 프록시 등 좀 더 구체적인 기능이 있습니다. 이 작업을 수행하고 리포지토리를 정리하기 위해 Ansible 내에서 Role을 사용할 수 있습니다.
이를 위해 공유 리포지토리에서 Ansible Role을 관리하기 위해 존재하는 `ansible-galaxy` 명령을 사용합니다.
![](/2022/Days/Images/Day66_config4.png)
우리는 `ansible-galaxy`를 사용하여 웹서버에 대한 세부 정보를 넣을 apache2의 Role을 생성할 것입니다.
![](/2022/Days/Images/Day66_config5.png)
위의 명령 `ansible-galaxy init roles/apache2`는 위에 표시된 폴더 구조를 생성합니다. 다음 단계는 기존 작업과 template을 새 구조의 관련 폴더로 이동하는 것입니다.
![](/2022/Days/Images/Day66_config6.png)
복사하여 붙여넣으면 파일을 쉽게 옮길 수 있지만, tasks/main.yml을 변경하여 이 파일이 apache2_install.yml을 가리키도록 해야 합니다.
또한 새로운 Role을 참조하도록 Playbook을 변경해야 합니다. playbook1.yml과 playbook2.yml에서 작업과 Handler를 두 버전 간에 변경하면서 다른 방식으로 결정합니다. 아래와 같이 이 Role을 사용하도록 Playbook을 변경해야 합니다:
```Yaml
- hosts: webservers
become: yes
vars:
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 66!"
roles:
- apache2
```
![](/2022/Days/Images/Day66_config7.png)
이제 새 Playbook 이름인 `ansible-playbook playbook3.yml`로 Playbook을 다시 실행하면 deprecated가 발생한 것을 확인할 수 있으며, 다음에 수정할 수 있습니다.
![](/2022/Days/Images/Day66_config8.png)
Playbook이 실행되었지만, deprecated가 발생했으므로 이제 방법을 수정해야 합니다. 이를 위해 tasks/main.yml의 include 옵션을 아래와 같이 import_tasks로 변경했습니다.
![](/2022/Days/Images/Day66_config9.png)
이 파일은 [ansible-scenario3](/2022/Days/Configmgmt/ansible-scenario3)에서 찾을 수 있습니다.
또한 우리가 만들 `ansible-galaxy`를 사용하면서 몇 가지 Role을 더 만들 것입니다:
- common = 모든 서버용(`ansible-galaxy init roles/common`)
- nginx = 로드밸런서용(`ansible-galaxy init roles/nginx`)
![](/2022/Days/Images/Day66_config10.png)
여기서는 여기까지만 하고 다음 세션에서는 배포했지만, 아직 아무것도 하지 않은 다른 Node에 대한 작업을 시작하겠습니다.
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
위에 나열된 마지막 재생 목록은 이 섹션의 많은 코드와 아이디어가 나온 곳이며, 동영상 형식의 훌륭한 리소스이자 워크스루입니다.
[Day 67](day67.md)에서 봐요!

122
2022/ko/Days/day67.md Normal file
View File

@ -0,0 +1,122 @@
---
title: '#90DaysOfDevOps - Using Roles & Deploying a Loadbalancer - Day 67'
published: false
description: '90DaysOfDevOps - Using Roles & Deploying a Loadbalancer'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048713
---
## Role 사용 및 로드밸런서 배포하기
지난 세션에서는 Role에 대해 다루고 `ansible-galaxy` 명령을 사용하여 앞으로 사용할 몇 가지 Role에 대한 폴더 구조를 만들었습니다. 모든 것이 Role 폴더에 숨겨져 있기 때문에 구성 코드의 작업 저장소가 훨씬 더 깔끔해졌습니다.
하지만 지금까지는 apache2 Role만 사용했고 웹서버를 처리하기 위해 작동하는 playbook3.yaml이 있습니다.
이 시점에서 `vagrant up web01 web02`만 사용했다면 이제 `vagrant up loadbalancer`를 실행하면 로드 밸런서/프록시로 사용할 다른 Ubuntu 시스템이 나타납니다.
호스트 파일에 이 새 시스템을 이미 정의했지만, 사용할 수 있을 때까지 ssh 키가 구성되지 않았으므로 시스템이 가동되고 준비되면 `ssh-copy-id loadbalancer`도 실행해야 합니다.
### Common Role
어제 세션 마지막에 `common` Role을 만들었는데, Common은 모든 서버에서 사용되는 반면 다른 Role은 사용 사례에 따라 다르지만 이제 설치하려는 애플리케이션은 가짜처럼 일반적이며 이것이 왜 그런지 많은 이유를 알 수는 없지만 그 목적을 보여줍니다. Common Role 폴더 구조에서 작업 폴더로 이동하면 main.yml이 있습니다. 이 YAML에서 이 파일을 install_tools.yml 파일로 가리켜야 하며, `- import_tasks: install_tools.yml` 줄을 추가하여 이를 수행합니다. 이전에는 `include`였으나 곧 사용되지 않을 예정이므로 import_tasks를 사용합니다.
```Yaml
- name: "Install Common packages"
apt: name={{ item }} state=latest
with_items:
- neofetch
- tree
- figlet
```
그런 다음 playbook에서 각 호스트 블록에 대한 Common Role을 추가합니다.
```Yaml
- hosts: webservers
become: yes
vars:
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 66!"
roles:
- common
- apache2
```
### Nginx
다음 단계는 로드밸런서 VM에 nginx를 설치하고 구성하는 것입니다. 일반적인 폴더 구조와 마찬가지로, 마지막 세션을 기반으로 nginx를 구성합니다.
먼저 playbook에 호스트 블록을 추가하겠습니다. 이 블록에는 Common Role과 새로운 nginx Role이 포함됩니다.
playbook은 여기에서 찾을 수 있습니다. [playbook4.yml](/2022/Days/Configmgmt/ansible-scenario4/playbook4.yml)
```Yaml
- hosts: webservers
become: yes
vars:
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 66!"
roles:
- common
- apache2
- hosts: proxy
become: yes
roles:
- common
- nginx
```
이것이 의미가 있으려면 실행할 작업을 정의해야 하며, 같은 방식으로 이번에는 설치용 파일과 구성용 파일 두 개를 가리키도록 작업의 main.yml을 수정하겠습니다.
원하는 결과에 따라 수정한 다른 파일이 몇 개 더 있는데, [ansible-scenario4](/2022/Days/Configmgmt/ansible-scenario4) 폴더에서 변경된 모든 파일을 살펴보세요. nginx 폴더의 작업, Handler 및 template 폴더를 확인하면 추가 변경 사항과 파일을 찾을 수 있습니다.
### 업데이트된 playbook 실행
어제부터 시스템에 일부 패키지를 설치하는 Common Role을 추가한 데 이어 설치 및 구성을 포함하는 nginx Role도 추가했습니다.
`anible-playbook playbook4.yml`을 사용하여 playbook4.yml을 실행해 보겠습니다.
![](/2022/Days/Images/Day67_config1.png)
이제 웹 서버와 로드밸런서가 구성되었으므로 이제 로드밸런서의 IP 주소인 http://192.168.169.134/ 로 이동할 수 있어야 합니다.
![](/2022/Days/Images/Day67_config2.png)
이 과정을 따르고 있는데도 이 상태가 나타나지 않는다면 사용 중인 환경의 서버 IP 주소 때문일 수 있습니다. 이 파일은 `templates\mysite.j2`에서 찾을 수 있으며 아래와 유사하게 보입니다: 웹 서버 IP 주소로 업데이트해야 합니다.
```J2
upstream webservers {
server 192.168.169.131:8000;
server 192.168.169.132:8000;
}
server {
listen 80;
location / {
proxy_pass http://webservers;
}
}
```
우리가 설치한 것이 모두 정상이라고 확신하지만, ansible을 사용하여 임시 명령을 사용하여 이러한 일반적인 도구 설치를 확인해 보겠습니다.
`ansible loadbalancer -m command -a neofetch`
![](/2022/Days/Images/Day67_config3.png)
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
위에 나열된 마지막 재생 목록은 이 섹션의 많은 코드와 아이디어가 나온 곳이며, 동영상 형식의 훌륭한 리소스이자 워크스루입니다.
[Day 68](day68.md)에서 봐요!

353
2022/ko/Days/day68.md Normal file
View File

@ -0,0 +1,353 @@
---
title: '#90DaysOfDevOps - Tags, Variables, Inventory & Database Server config - Day 68'
published: false
description: '90DaysOfDevOps - Tags, Variables, Inventory & Database Server config'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048780
---
## Tag, Variable, Inventory 및 Database 서버 구성
### Tag
어제 세션에 playbook을 남겨두었으므로 모든 작업을 실행하고 해당 playbook 내에서 play해야 합니다. 즉, 웹서버와 로드밸런서 play 및 작업을 모두 실행해야 완료할 수 있습니다.
하지만 Tag를 사용하면 원하는 경우 이러한 작업을 분리할 수 있습니다. 이는 환경에 매우 크고 긴 playbook이 있는 경우 효율적인 방법이 될 수 있습니다.
이 경우 playbook 파일에서는 [ansible-scenario5](/2022/Days/Configmgmt/ansible-scenario5/playbook5.yml)를 사용하고 있습니다.
```Yaml
- hosts: webservers
become: yes
vars:
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 66!"
roles:
- common
- apache2
tags: web
- hosts: proxy
become: yes
roles:
- common
- nginx
tags: proxy
```
그런 다음 `ansible-playbook playbook5.yml --list-tags`를 사용하여 이를 확인할 수 있으며, list Tag는 우리가 playbook에서 정의한 Tag의 윤곽을 나타냅니다.
![](/2022/Days/Images/Day68_config1.png)
이제 프록시만 타깃팅하려면 `ansible-playbook playbook5.yml --tags proxy`를 실행하면 아래에서 볼 수 있듯이 프록시에 대해서만 playbook을 실행할 수 있습니다.
![](/2022/Days/Images/Day68_config2.png)
Tag는 작업 수준에서도 추가할 수 있으므로 원하는 위치와 작업을 세분화할 수 있습니다. 예를 들어 애플리케이션 중심 Tag가 될 수도 있고, 작업을 살펴보고 설치, 구성 또는 제거에 따라 작업에 Tag를 지정할 수도 있습니다. 사용할 수 있는 또 다른 매우 유용한 Tag는 다음과 같습니다.
`tag: always` 이것은 명령에 어떤 --tags를 사용하든 상관없이 항상 값으로 Tag가 지정된 항목이 있으면 ansible-playbook 명령을 실행할 때 항상 실행되도록 보장합니다.
Tag를 사용하여 여러 Tag를 함께 묶을 수도 있으며, `ansible-playbook playbook5.yml --tags proxy,web`을 실행하도록 선택하면 해당 Tag가 있는 모든 항목이 실행됩니다. 물론 이 예제에서는 playbook을 실행하는 것과 같은 의미이지만, 다른 play가 여러 개 있는 경우에는 이 방법이 의미가 있을 것입니다.
둘 이상의 Tag를 정의할 수도 있습니다.
### Variable
Ansible에는 크게 두 가지 유형의 Variable이 있습니다.
- User created
- Ansible Facts
### Ansible Facts
playbook을 실행할 때마다 "Gathering facts"라는 정의되지 않은 작업이 있었는데, 이러한 Variable 또는 fact를 사용하여 자동화 작업을 수행할 수 있습니다.
![](/2022/Days/Images/Day68_config3.png)
다음 `ansible proxy -m setup` 명령을 실행하면 JSON 형식의 많은 출력을 볼 수 있습니다. 이를 사용하려면 터미널에 많은 정보가 있어야 하므로 `ansible proxy -m setup >> facts.json`을 사용하여 파일로 출력하고 싶습니다. [여기](/2022/Days/Configmgmt/ansible-scenario5/facts.json)에서 이 파일을 볼 수 있습니다.
![](/2022/Days/Images/Day68_config4.png)
이 파일을 열면 명령에 대한 모든 종류의 정보를 볼 수 있습니다. IP 주소, 아키텍처, 바이오스 버전을 확인할 수 있습니다. 이 정보를 활용하여 playbook에 사용하려는 경우 유용한 정보가 많이 있습니다.
한 가지 아이디어는 웹서버의 IP 주소를 하드코딩한 nginx template mysite.j2 내에서 이러한 Variable 중 하나를 잠재적으로 사용하는 것입니다. mysite.j2에 for 루프를 생성하면 [webservers] 그룹을 순환하여 2개 이상의 웹서버를 자동으로 동적으로 생성하거나 이 로드 밸런서 구성에 추가할 수 있습니다.
```
#Dynamic Config for server {{ ansible_facts['nodename'] }}
upstream webservers {
{% for host in groups['webservers'] %}
server {{ hostvars[host]['ansible_facts']['nodename'] }}:8000;
{% endfor %}
}
server {
listen 80;
location / {
proxy_pass http://webservers;
}
}
```
위의 결과는 지금과 동일하게 보이지만 웹 서버를 더 추가하거나 제거하면 프록시 구성이 동적으로 변경됩니다. 이 기능을 사용하려면 이름 확인을 구성해야 합니다.
### User created
User created Variable은 우리가 직접 만든 Variable입니다. playbook을 살펴보면 `vars:`가 있고 거기에 3개의 Variable 목록이 있는 것을 볼 수 있습니다.
```Yaml
- hosts: webservers
become: yes
vars:
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 68!"
roles:
- common
- apache2
tags: web
- hosts: proxy
become: yes
roles:
- common
- nginx
tags: proxy
```
그러나 Variable을 해당 파일로 이동하여 playbook에 Variable이 없도록 할 수 있습니다. 이 작업을 수행하되, [ansible-scenario6](/2022/Days/Configmgmt/ansible-scenario6) 폴더로 이동하겠습니다. 해당 폴더의 루트에 group_vars 폴더를 만들겠습니다. 그런 다음 all이라는 또 다른 폴더를 만듭니다(모든 그룹이 이 Variable을 가져옵니다). 이 폴더에 `common_variables.yml`이라는 파일을 만들고 playbook의 Variable을 이 파일에 복사합니다. Variable과 함께 playbook에서 Variable을 제거합니다.
```Yaml
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 68!"
```
이 Variable을 전역 Variable로 연결하기 때문에 여기에 NTP 및 DNS 서버도 추가할 수 있습니다. Variable은 우리가 만든 폴더 구조에서 설정됩니다. 이제 playbook이 얼마나 깔끔해졌는지 아래에서 확인할 수 있습니다.
```Yaml
- hosts: webservers
become: yes
roles:
- common
- apache2
tags: web
- hosts: proxy
become: yes
roles:
- common
- nginx
tags: proxy
```
그 Variable 중 하나는 http_port로, 아래와 같이 mysite.j2 내의 for 루프에서 이 Variable을 다시 사용할 수 있습니다:
```J2
#Dynamic Config for server {{ ansible_facts['nodename'] }}
upstream webservers {
{% for host in groups['webservers'] %}
server {{ hostvars[host]['ansible_facts']['nodename'] }}:{{ http_port }};
{% endfor %}
}
server {
listen 80;
location / {
proxy_pass http://webservers;
}
}
```
또한, 어떤 웹서버를 사용하고 있는지 파악할 수 있도록 roles/apache2/templates/index.HTML.j2 파일에 분석 가능한 사실을 정의할 수도 있습니다.
```J2
<html>
<h1>{{ html_welcome_msg }}! I'm webserver {{ ansible_facts['nodename'] }} </h1>
</html>
```
Variable을 변경하여 `ansible-playbook playbook6.yml` 명령을 실행한 결과, 로드밸런서에 도달하면 그룹에 있는 웹서버 중 하나에 도달한 것을 볼 수 있습니다.
![](/2022/Days/Images/Day68_config5.png)
또한 host_vars라는 폴더를 추가하고 web01.yml을 생성하여 원하는 경우 특정 메시지를 표시하거나 호스트별로 표시되는 내용을 변경할 수 있습니다.
### Inventory 파일
지금까지 호스트를 결정하기 위해 /etc/ansible 폴더에 있는 기본 호스트 파일을 사용했습니다. 그러나 프로덕션 및 스테이징과 같이 환경마다 다른 파일을 사용할 수 있습니다. 더 많은 환경을 만들지는 않겠습니다. 하지만 호스트 파일은 만들 수 있습니다.
서버와 노드의 다양한 Inventory에 대해 여러 개의 파일을 만들 수 있습니다. 우리는 `ansible-playbook -i dev playbook.yml`을 사용하여 이를 호출합니다. 호스트 파일 내에 Variable을 정의한 다음 이를 출력하거나 playbook의 다른 곳에서 해당 Variable을 활용할 수도 있습니다. 예를 들어 아래 예제 및 교육 과정에서는 호스트 파일에서 생성된 환경 Variable을 로드밸런서 웹 페이지 template에 추가하여 웹 페이지 메시지의 일부로 환경을 표시했습니다.
### Database 서버 배포
아직 전원을 켜고 구성하지 않은 머신이 하나 더 있습니다. vagrant 파일이 있는 곳에서 `vagrant up db01`을 사용하여 이 작업을 수행할 수 있습니다. 전원이 켜지고 액세스할 수 있게 되면 `ssh-copy-id db01`을 사용하여 SSH 키를 복사하여 액세스할 수 있도록 해야 합니다.
여기서는 [ansible-scenario7](/2022/Days/Configmgmt/ansible-scenario7) 폴더에서 작업할 것입니다.
그런 다음 `ansible-galaxy init roles/mysql`을 사용하여 "MySQL"이라는 새 Role에 대한 새 폴더 구조를 만들어 보겠습니다.
playbook에서 Database 구성을 위한 새로운 play 블록을 추가하겠습니다. /etc/ansible/hosts 파일에 그룹 Database가 정의되어 있습니다. 그런 다음 Database 그룹에 공통 Role과 이전 단계에서 생성한 MySQL이라는 새 Role을 갖도록 지시합니다. 또한 Database 그룹에 Database Tag를 지정하고 있는데, 이는 앞서 설명한 것처럼 원하는 경우 이러한 Tag에 대해서만 실행하도록 선택할 수 있음을 의미합니다.
```Yaml
- hosts: webservers
become: yes
roles:
- common
- apache2
tags:
web
- hosts: proxy
become: yes
roles:
- common
- nginx
tags:
proxy
- hosts: database
become: yes
roles:
- common
- mysql
tags: database
```
이제 Role 폴더 구조 내에서 트리가 자동으로 생성되었으므로 다음을 채워야 합니다:
Handlers - main.yml
```Yaml
# handlers file for roles/mysql
- name: restart mysql
service:
name: mysql
state: restarted
```
Tasks - install_mysql.yml, main.yml & setup_mysql.yml
install_mysql.yml - 이 작업은 MySQL을 설치하고 서비스가 실행 중인지 확인하기 위해 수행됩니다.
```Yaml
- name: "Install Common packages"
apt: name={{ item }} state=latest
with_items:
- python3-pip
- mysql-client
- python3-mysqldb
- libmysqlclient-dev
- name: Ensure mysql-server is installed latest version
apt: name=mysql-server state=latest
- name: Installing python module MySQL-python
pip:
name: PyMySQL
- name: Ensure mysql-server is running
service:
name: mysql
state: started
```
main.yml은 이러한 파일에서 작업을 가져오도록 제안하는 포인터 파일입니다.
```Yaml
# tasks file for roles/mysql
- import_tasks: install_mysql.yml
- import_tasks: setup_mysql.yml
```
setup_mysql.yml - 이 작업은 Database와 Database 사용자를 생성합니다.
```Yaml
- name: Create my.cnf configuration file
template: src=templates/my.cnf.j2 dest=/etc/mysql/conf.d/mysql.cnf
notify: restart mysql
- name: Create database user with name 'devops' and password 'DevOps90' with all database privileges
community.mysql.mysql_user:
login_unix_socket: /var/run/mysqld/mysqld.sock
login_user: "{{ mysql_user_name }}"
login_password: "{{ mysql_user_password }}"
name: "{{db_user}}"
password: "{{db_pass}}"
priv: '*.*:ALL'
host: '%'
state: present
- name: Create a new database with name '90daysofdevops'
mysql_db:
login_user: "{{ mysql_user_name }}"
login_password: "{{ mysql_user_password }}"
name: "{{ db_name }}"
state: present
```
위에서 비밀번호, 사용자 이름 및 Database와 같은 일부 구성을 결정하기 위해 몇 가지 Variable을 사용하고 있음을 알 수 있으며, 이 Variable은 모두 group_vars/all/common_variables.yml 파일에 저장되어 있습니다.
```Yaml
http_port: 8000
https_port: 4443
html_welcome_msg: "Hello 90DaysOfDevOps - Welcome to Day 68!"
mysql_user_name: root
mysql_user_password: "vagrant"
db_user: devops
db_pass: DevOps90
db_name: 90DaysOfDevOps
```
또한 template 폴더에 아래와 같은 my.cnf.j2 파일이 있습니다:
```J2
[mysql]
bind-address = 0.0.0.0
```
### playbook 실행
이제 VM이 실행 중이고 구성 파일이 준비되었으므로 이제 playbook을 실행할 준비가 되었습니다. 다음 `ansible-playbook playbook7.yml`을 실행하면 이전에 수행한 모든 작업이 포함된 playbook을 실행할 수 있고, `ansible-playbook playbook7.yml --tags database` 명령으로 Database 그룹에 배포하여 새 구성 파일만 실행하도록 선택할 수도 있습니다.
Database Tag에 대해서만 실행했지만, 오류가 발생했습니다. 이 오류는 pip3(파이썬)가 설치되어 있지 않다는 것을 알려줍니다. 이 오류는 일반 작업에 추가하여 해결할 수 있습니다.
![](/2022/Days/Images/Day68_config6.png)
위의 문제를 수정하고 playbook을 다시 실행했더니 성공적으로 변경되었습니다.
![](/2022/Days/Images/Day68_config7.png)
이제 새로 구성한 db01 서버에서 모든 것이 우리가 원하는 대로 작동하는지 확인해야 합니다. Control Node에서 `ssh db01` 명령을 사용하여 이 작업을 수행할 수 있습니다.
MySQL에 연결하기 위해 `sudo /usr/bin/mysql -u root -p`를 사용하고 프롬프트에서 root에 대한 vagrant 암호를 제공했습니다.
연결이 완료되면 먼저 DevOps라는 사용자가 생성되었는지 확인합니다. `select user, host from mysql.user;`
![](/2022/Days/Images/Day68_config8.png)
이제 `SHOW DATABASES;` 명령을 실행하여 생성된 새 Database를 확인할 수 있습니다.
![](/2022/Days/Images/Day68_config9.png)
루트를 사용하여 연결했지만 이제 `sudo /usr/bin/MySQL -u devops -p`를 사용하여 동일한 방법으로 DevOps 계정으로 로그인할 수도 있지만 여기서 암호는 DevOps90입니다.
제가 발견한 한 가지는 `setup_mysql.yml``login_unix_socket: /var/run/mysqld/mysqld.sock` 줄을 추가해야 db01 MySQL 인스턴스에 성공적으로 연결할 수 있었고 이제 이 작업을 실행할 때마다 사용자를 만들 때 변경 사항을 보고하므로 어떤 제안이라도 대단히 감사하겠습니다.
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
위에 나열된 마지막 재생 목록은 이 섹션의 많은 코드와 아이디어가 나온 곳이며, 동영상 형식의 훌륭한 리소스이자 워크스루입니다.
[Day 69](day69.md)에서 봐요!

143
2022/ko/Days/day69.md Normal file
View File

@ -0,0 +1,143 @@
---
title: '#90DaysOfDevOps - All other things Ansible - Automation Controller (Tower), AWX, Vault - Day 69'
published: false
description: '90DaysOfDevOps - All other things Ansible - Automation Controller (Tower), AWX, Vault'
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048714
---
## 기타 모든 Ansible - 자동화 컨트롤러(타워), AWX, Vault
구성 관리에 대한 섹션을 마무리하면서 Ansible을 다룰 때 접할 수 있는 다른 영역에 대해 살펴보고 싶었습니다.
Ansible 자동화 플랫폼을 구성하는 많은 제품이 있습니다.
Red Hat Ansible Automation Platform은 조직 전반에서 자동화를 구축하고 운영하기 위한 기반입니다. 이 플랫폼에는 전사적인 자동화를 구현하는 데 필요한 모든 도구가 포함되어 있습니다.
![](/2022/Days/Images/Day69_config1.png)
이 글에서는 이 중 일부를 다루려고 합니다. 하지만 더 자세한 내용은 공식 Red Hat Ansible 사이트에서 더 많은 정보를 확인할 수 있습니다. [Ansible.com](https://www.ansible.com/?hsLang=en-us)
### Ansible 자동화 컨트롤러 | AWX
자동화 컨트롤러와 AWX는 제공하는 기능이 매우 유사하기 때문에 이 두 가지를 함께 묶었습니다.
AWX 프로젝트 또는 줄여서 AWX는 Red Hat이 후원하는 오픈 소스 커뮤니티 프로젝트로, 사용자 환경 내에서 Ansible 프로젝트를 더 잘 제어할 수 있도록 지원합니다. AWX는 자동화 컨트롤러 구성 요소가 파생된 업스트림 프로젝트입니다.
엔터프라이즈 솔루션을 찾고 계신다면 자동화 컨트롤러를 찾으시거나 이전에 Ansible Tower라고 들어보셨을 것입니다. Ansible 자동화 컨트롤러는 Ansible 자동화 플랫폼의 컨트롤 플레인입니다.
AWX와 자동화 컨트롤러는 지금까지 이 섹션에서 다룬 다른 모든 기능 위에 다음과 같은 기능을 제공합니다.
- 사용자 인터페이스
- 역할 기반 액세스 제어
- workflow
- CI/CD 통합
자동화 컨트롤러는 지원 비용을 지불하는 엔터프라이즈 제품입니다.
Minikube kubernetes 환경 내에서 AWX를 배포하는 방법을 살펴보겠습니다.
### Ansible AWX 배포하기
AWX를 kubernetes 클러스터에 배포할 필요는 없으며, [github](https://github.com/ansible/awx)에서 AWX에 대한 자세한 내용을 확인할 수 있습니다. 그러나 버전 18.0부터는 AWX 오퍼레이터를 사용하여 AWX를 설치하는 것이 선호됩니다.
우선 Minikube 클러스터가 필요합니다. kubernetes 섹션에서 `minikube start --cpus=4 --memory=6g --addons=ingress` 명령으로 새 Minikube 클러스터를 생성하는 방법을 따라 했다면 이 작업을 수행할 수 있습니다.
![](/2022/Days/Images/Day69_config2.png)
공식 [Ansible AWX 오퍼레이터](https://github.com/ansible/awx-operator)는 여기에서 확인할 수 있습니다. 설치 지침에 명시된 대로 이 리포지토리를 복제한 다음 배포를 실행해야 합니다.
위의 리포지토리를 folk한 다음 `git clone https://github.com/MichaelCade/awx-operator.git`을 실행했는데, 여러분도 똑같이 하시고 제가 만든 리포지토리는 변경되거나 존재하지 않을 수 있으므로 사용하지 않는 것이 좋습니다.
복제된 리포지토리에서 아래와 같이 `NodePort``ClusterIP`로 변경해야 하는 awx-demo.yml 파일을 찾을 수 있습니다:
```Yaml
---
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: awx-demo
spec:
service_type: ClusterIP
```
다음 단계는 awx 연산자를 배포할 네임스페이스를 정의하는 것으로, `export NAMESPACE=awx` 명령을 사용한 다음 `make deploy`로 배포를 시작합니다.
![](/2022/Days/Images/Day69_config3.png)
확인을 통해 새 네임스페이스가 있고 네임스페이스에서 awx-operator-controller pod가 실행되고 있음을 확인합니다. `kubectl get pods -n awx`
![](/2022/Days/Images/Day69_config4.png)
복제된 리포지토리 내에서 awx-demo.yml이라는 파일을 찾을 수 있으며, 이제 이 파일을 Kubernetes 클러스터와 awx 네임스페이스에 배포하려고 합니다. `kubectl create -f awx-demo.yml -n awx`
![](/2022/Days/Images/Day69_config5.png)
`kubectl get pods -n awx -w`로 진행 상황을 계속 주시할 수 있습니다.
모든 것이 실행되면 아래와 같은 이미지와 비슷한 것이 보일 것입니다.
![](/2022/Days/Images/Day69_config6.png)
이제 새 터미널에서 `minikube service awx-demo-service --url -n $NAMESPACE`를 실행하여 Minikube 인그레스를 통해 이를 노출한 후 awx 배포에 액세스할 수 있어야 합니다.
![](/2022/Days/Images/Day69_config7.png)
그런 다음 해당 주소 []로 브라우저를 열면 사용자 이름과 비밀번호를 입력하라는 메시지가 표시되는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day69_config8.png)
기본적으로 사용자 이름은 admin이며, 비밀번호를 얻으려면 다음 명령어를 실행하여 `kubectl get secret awx-demo-admin-password -o jsonpath="{.data.password}" -n awx| base64 --decode`를 얻을 수 있습니다.
![](/2022/Days/Images/Day69_config9.png)
이렇게 하면 중앙 집중화된 위치에서 playbook 및 구성 관리 작업을 관리할 수 있는 UI가 제공되며, 지금까지 하나의 Ansible 제어 스테이션에서 실행하던 것과 달리 팀원들이 함께 작업할 수 있습니다.
이 영역은 이 도구의 기능을 살펴보는 데 더 많은 시간을 할애할 수 있는 또 다른 영역 중 하나입니다.
Ansible AWX 사용에 대해 더 자세히 설명하는 Jeff Geerling의 훌륭한 리소스를 소개해 드리겠습니다. [Ansible 101 - 에피소드 10 - Ansible 타워 및 AWX](https://www.youtube.com/watch?v=iKmY4jEiy_A&t=752s)
이 비디오에서 그는 자동화 컨트롤러(이전 Ansible Tower)와 Ansible AWX(무료 및 오픈 소스)의 차이점에 대해서도 자세히 설명합니다.
### Ansible Vault
`ansible-vault`를 사용하면 Ansible 데이터 파일을 암호화하고 해독할 수 있습니다. 이 섹션에서는 일부 민감한 정보를 건너뛰고 일반 텍스트로 표시했습니다.
Ansible 바이너리에는 이 민감한 정보를 마스킹할 수 있는 `ansible-vault`가 내장되어 있습니다.
![](/2022/Days/Images/Day69_config10.png)
비밀 관리는 점차 HashiCorp Vault나 AWS 키 관리 서비스와 같은 도구와 함께 더 많은 시간을 할애해야 하는 또 다른 영역이 되었습니다. 이 부분은 더 자세히 살펴볼 영역으로 표시하겠습니다.
Jeff Geerling의 훌륭한 리소스와 데모를 다시 한번 링크해드리겠습니다 [Ansible 101 - 에피소드 6 - Ansible Vault와 역할](https://www.youtube.com/watch?v=JFweg2dUvqM).
### Ansible Galaxy(문서)
이제 데모 프로젝트의 일부 역할과 파일 구조를 생성하기 위해 이미 `ansible-galaxy`를 사용했습니다. 하지만 [Ansible Galaxy 문서](https://galaxy.ansible.com/docs/)도 있습니다.
"Galaxy는 Ansible 콘텐츠를 찾고 공유하기 위한 허브입니다."
### Ansible 테스트
- [Ansible Molecule](https://molecule.readthedocs.io/en/latest/) - Molecule 프로젝트는 Ansible 역할의 개발 및 테스트를 지원하도록 설계되었습니다.
- [Ansible Lint](https://ansible-lint.readthedocs.io/en/latest/) - playbook, 역할 및 컬렉션을 Lint하기 위한 CLI 도구입니다.
### 기타 리소스
- [Ansible 문서](https://docs.ansible.com/ansible/latest/index.html)
## 자료
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
위에 나열된 마지막 재생 목록은 이 섹션의 많은 코드와 아이디어가 나온 곳이며, 동영상 형식의 훌륭한 리소스이자 연습입니다.
이 포스팅에서는 구성 관리에 대해 살펴본 내용을 마무리하고, 다음에는 CI/CD 파이프라인과 애플리케이션 개발 및 릴리스에 이러한 workflow를 달성하기 위해 사용할 수 있는 몇 가지 도구 및 프로세스에 대해 살펴봅니다.
[Day 70](day70.md)에서 봐요!

123
2022/ko/Days/day70.md Normal file
View File

@ -0,0 +1,123 @@
---
title: '#90DaysOfDevOps - The Big Picture: CI/CD Pipelines - Day 70'
published: false
description: 90DaysOfDevOps - The Big Picture CI/CD Pipelines
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048836
---
## 큰 그림: CI/CD 파이프라인
CI/CD(지속적 통합/지속적 배포) 파이프라인 구현은 최신 DevOps 환경의 중추입니다.
파이프라인은 애플리케이션의 빌드, 테스트 및 배포를 자동화하여 개발과 운영 간의 격차를 해소합니다.
챌린지의 첫 번째 섹션에서 이 중요한 요소에 대해 많이 다루었습니다. 하지만 다시 한번 말씀드리자면:
지속적 통합(CI)은 점진적인 코드 변경을 더 자주 그리고 안정적으로 수행하는 보다 현대적인 소프트웨어 개발 관행입니다. 지속적 통합에 의해 트리거되는 자동화된 빌드 및 테스트 Workflow Step은 리포지토리에 병합되는 코드 변경 사항을 신뢰할 수 있도록 보장합니다.
그런 다음 해당 코드/애플리케이션은 지속적 배포 프로세스의 일부로 신속하고 원활하게 제공됩니다.
### CI/CD의 중요성은?
- 소프트웨어를 빠르고 효율적으로 배포
- 애플리케이션을 최대한 빠르게 시장에 출시하기 위한 효과적인 프로세스를 촉진합니다.
- 버전 릴리스를 위해 몇 달 또는 몇 년을 기다릴 필요 없이 버그 수정 및 새로운 기능을 지속적으로 제공할 수 있습니다.
개발자가 영향력 있는 작은 변경을 정기적으로 수행할 수 있으므로 더 빠른 수정과 더 많은 기능을 더 빨리 얻을 수 있습니다.
### 자, 이게 무슨 뜻인가요?
[Day 5](day05.md)에서 데브옵스에 대한 많은 이론을 다뤘으며, 이미 여기에서 CI/CD 파이프라인이 최신 데브옵스 환경의 핵심이라고 언급했듯이, 이 파이프라인은 최신 데브옵스 환경의 기본입니다.
![데브옵스](/2022/Days/Images/Day5_DevOps8.png)
이제 데브옵스의 기본을 배우는 여정에 조금 더 들어섰으므로 위 이미지의 몇 가지 핵심 사항을 다시 한번 강조하고 싶습니다.
소프트웨어 개발 수명 주기(SDLC)를 언급하고 있습니다.
이 주기는 영원히 반복되는 주기이기 때문에 일반적으로 무한 루프 내에 단계가 기록됩니다.
개발자가 **코드**를 작성하면 **빌드**되거나 모두 컴파일되고, 버그가 있는지 **테스트**되고, 최종 사용자나 고객이 사용하는 프로덕션에 **배포**되고(**운영**), **모니터링** 및 피드백을 수집하고, 마지막으로 해당 피드백을 중심으로 개선 사항을 **계획**하고 반복하는 것이 이 주기의 단계입니다.
### CI/CD에 대해 좀 더 자세히 알아봅시다.
### CI
CI는 개발자가 하루에 여러 번 공유 리포지토리에 코드를 통합해야 하는 개발 관행입니다.
코드가 작성되어 Github 또는 GitLab과 같은 리포지토리에 push되면 마법이 시작됩니다.
![](/2022/Days/Images/Day70_CICD1.png)
자동화된 빌드를 통해 코드가 검증되므로 팀이나 프로젝트 소유자가 문제를 조기에 발견할 수 있습니다.
![](/2022/Days/Images/Day70_CICD2.png)
여기에서 코드를 분석하고 일련의 자동화된 테스트를 수행하는데, 세 가지 예는 다음과 같습니다.
- 단위 테스트는 소스 코드의 개별 단위를 테스트합니다.
- 유효성 검사 테스트는 소프트웨어가 의도된 용도를 충족하거나 적합한지 확인합니다.
- 형식 테스트는 구문 및 기타 형식 지정 오류를 확인합니다.
이러한 테스트는 workflow로 생성된 다음 마스터 브랜치로 push할 때마다 실행되므로 거의 모든 주요 개발팀에는 일종의 CI/CD workflow가 있으며, 개발팀에서는 하루 종일 전 세계의 여러 팀에서 다양한 프로젝트를 진행하는 개발자로부터 새로운 코드가 들어올 수 있으므로 코드가 승인되기 전에 모든 사람이 같은 페이지에 있는지 확인하는 테스트의 자동화된 workflow를 구축하는 것이 더 효율적입니다. 사람이 매번 이 작업을 수행하려면 훨씬 더 오랜 시간이 걸립니다.
![](/2022/Days/Images/Day70_CICD3.png)
테스트가 완료되고 성공하면 컴파일하여 리포지토리로 보낼 수 있습니다. 예를 들어, 저는 DockerHub를 사용하고 있지만 파이프라인의 CD 측면에 활용되는 모든 곳이 될 수 있습니다.
![](/2022/Days/Images/Day70_CICD4.png)
따라서 이 프로세스는 소프트웨어 개발 프로세스와 매우 유사하며, 애플리케이션을 만들고, 버그를 추가하고, 수정한 다음 소스 제어를 업데이트하고, 테스트하면서 버전도 관리합니다.
다음 단계로 넘어가면 CD 요소인데, 일반적으로 상용 소프트웨어에서 볼 수 있는 CD 요소는 점점 더 많아지고 있으며, 오라클이나 Microsoft와 같은 공급업체로부터 소프트웨어를 받으면 DockerHub 유형 리포지토리에서 이를 소비한 다음 CD 파이프라인을 사용하여 환경에 배포하는 추세를 보게 될 것이라고 주장하고 싶습니다.
### CD
이제 테스트된 버전의 코드를 배포할 준비가 되었습니다. 소프트웨어 공급업체가 이 단계를 진행하겠지만, 저는 이것이 앞으로 우리 모두가 필요한 상용 소프트웨어를 배포하는 방식이 될 것이라고 굳게 믿습니다.
이제 코드를 환경에 배포할 차례입니다. 여기에는 프로덕션 환경뿐만 아니라 스테이징과 같은 다른 환경도 포함될 것입니다.
![](/2022/Days/Images/Day70_CICD5.png)
소프트웨어 배포 1일차에서 다음 단계는 올바른 코드 베이스를 올바른 환경으로 가져오고 있는지 확인하는 것입니다. 소프트웨어 리포지토리(DockerHub)에서 요소를 가져올 수도 있지만, 다른 코드 리포지토리에서 추가 구성, 예를 들어 애플리케이션에 대한 구성을 가져올 수도 있습니다. 아래 다이어그램에서는 DockerHub에서 소프트웨어의 최신 릴리스를 가져온 다음 이를 환경에 릴리스하는 동시에 Git 리포지토리에서 구성을 가져올 수 있습니다. CD 도구가 이 작업을 수행하여 모든 것을 환경에 push합니다.
이 작업은 동시에 수행되지 않을 가능성이 높습니다. 즉, 구성이 올바른지 확인하기 위해 스테이징 환경으로 이동하여 이 구성에 대해 실행한 후 테스트를 위한 수동 단계일 수도 있고, 이 코드를 프로덕션에 배포하기 전에 다시 자동화할 수도 있습니다(자동화로 가겠습니다).
![](/2022/Days/Images/Day70_CICD6.png)
그런 다음 애플리케이션의 v2가 나오면 이번에는 단계를 반복하여 애플리케이션 + 구성이 스테이징에 배포되어 모든 것이 정상인지 확인한 다음 프로덕션에 배포합니다.
### CI/CD를 사용하는 이유는 무엇인가요?
이미 여러 번 이점에 대해 설명했지만, 수동으로 수행해야 하는 작업을 자동화하여 작은 문제가 메인 코드 베이스에 들어가기 전에 발견하기 때문입니다. 고객에게 잘못된 코드를 push하면 큰 문제가 발생할 수 있다는 것을 상상할 수 있을 것입니다!
또한 메인 코드 리포지토리는 시간이 지남에 따라 지속적으로 구축되기 때문에 첫날에 수행한 지름길 수정이 몇 년 후 기하급수적으로 더 많은 비용이 드는 수정이 될 수 있다는 생각인 기술 부채를 방지하는 데 도움이 됩니다.
### 도구
다른 섹션과 마찬가지로 CI/CD 파이프라인 프로세스를 달성하는 몇 가지 도구에 대해 실습해 보겠습니다.
모든 도구가 CI와 CD를 모두 수행해야 하는 것은 아니며, 소프트웨어를 Kubernetes 클러스터에 배포하는 데 있어 CD 요소에 능숙한 ArgoCD를 살펴볼 것입니다. 하지만 Jenkins와 같은 것은 다양한 플랫폼에서 작동할 수도 있습니다.
저는 다음을 살펴볼 계획입니다:
- Jenkins
- ArgoCD
- GitHub Actions
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Introduction to Jenkins](https://www.edx.org/course/introduction-to-jenkins)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 71](day71.md)에서 봐요!

105
2022/ko/Days/day71.md Normal file
View File

@ -0,0 +1,105 @@
---
title: '#90DaysOfDevOps - What is Jenkins? - Day 71'
published: false
description: 90DaysOfDevOps - What is Jenkins?
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048745
---
## Jenkins란 무엇인가요?
Jenkins는 새로 만든 코드를 지속적으로 개발, 테스트 및 배포할 수 있는 지속적 통합 도구입니다.
야간 빌드 또는 지속적 개발을 통해 이를 달성할 수 있는 방법에는 두 가지가 있습니다. 첫 번째 옵션은 개발자가 하루 종일 작업을 개발하다가 정해진 하루가 끝나면 변경 사항을 소스 코드 저장소에 push하는 것입니다. 그런 다음 밤에는 단위 테스트를 실행하고 소프트웨어를 빌드합니다. 이것이 모든 코드를 통합하는 오래된 방식이라고 할 수 있습니다.
![](/2022/Days/Images/Day71_CICD1.png)
다른 옵션이자 선호되는 방식은 개발자가 소스 코드에 변경 사항을 커밋하고 해당 코드 커밋이 완료되면 빌드 프로세스가 지속적으로 시작되는 방식입니다.
![](/2022/Days/Images/Day71_CICD2.png)
위의 방법을 사용하면 전 세계에 분산된 개발자가 있는 경우 매일 정해진 시간에 코드 변경 사항 커밋을 중단할 수 없습니다. 이러한 테스트와 빌드 프로세스를 제어하기 위해 CI 서버 역할을 하는 것이 바로 Jenkins입니다.
![](/2022/Days/Images/Day71_CICD3.png)
여기서는 Jenkins에 대해 이야기하고 있지만 나중에 몇 가지를 더 추가하여 Jenkins가 전반적으로 가장 인기 있는 것으로 보이는 이유와 그 이유, 그리고 다른 도구가 Jenkins보다 무엇을 할 수 있는지에 대해 알아보고자 합니다.
- TravisCI - GitHub에서 호스팅되는 소프트웨어 프로젝트를 빌드하고 테스트하는 데 사용되는 호스팅된 분산형 지속적 통합 서비스입니다.
- Bamboo - 빠른 컴파일을 위해 여러 빌드를 병렬로 실행할 수 있으며, 리포지토리와 연결할 수 있는 기능이 내장되어 있고 Ant 및 Maven용 빌드 작업이 있습니다.
- Buildbot - 소프트웨어 빌드, 테스트 및 릴리스 프로세스를 자동화하기 위한 오픈 소스 프레임워크입니다. Python으로 작성되었으며 여러 플랫폼에서 작업의 분산 병렬 실행을 지원합니다.
- Apache Gump - 매일 밤 Java 프로젝트를 빌드하고 테스트하도록 설계된 Java 프로젝트 전용으로, 모든 프로젝트가 API 및 기능 수준 모두에서 호환되도록 보장합니다.
이제부터는 Jenkins에 초점을 맞추겠습니다. Jenkins는 위의 모든 도구와 마찬가지로 오픈 소스이며 Java로 작성된 자동화 서버입니다. 지속적인 통합을 통해 소프트웨어 개발 프로세스를 자동화하고 지속적인 배포를 용이하게 하는 데 사용됩니다.
### Jenkins의 특징
예상할 수 있듯이 Jenkins는 다양한 영역에 걸쳐 많은 기능을 가지고 있습니다.
**간편한 설치** - Jenkins는 Windows, macOS 및 Linux 운영 체제용 패키지와 함께 실행할 준비가 된 독립형 자바 기반 프로그램입니다.
**간편한 구성** - 오류 확인 및 기본 제공 도움말이 포함된 웹 인터페이스를 통해 쉽게 설정 및 구성할 수 있습니다.
**플러그인** - 업데이트 센터에서 다양한 플러그인을 사용할 수 있으며 CI/CD 툴체인의 여러 도구와 통합됩니다.
**확장 가능** - 사용 가능한 플러그인 외에도 플러그인 아키텍처를 통해 Jenkins를 확장할 수 있어 거의 무한한 용도로 사용할 수 있는 옵션을 제공합니다.
**분산** - Jenkins는 여러 머신에 작업을 쉽게 분산하여 여러 플랫폼에서 빌드, 테스트 및 배포 속도를 높일 수 있도록 지원합니다.
### Jenkins 파이프라인
이 파이프라인을 보셨겠지만, 훨씬 광범위하게 사용되며 특정 도구에 대해서는 언급하지 않았습니다.
Jenkins에 코드를 커밋하면 모든 자동화된 테스트를 통해 애플리케이션을 빌드한 다음 각 단계가 완료되면 해당 코드를 릴리스 및 배포합니다. 이 프로세스를 자동화할 수 있는 것이 바로 Jenkins입니다.
![](/2022/Days/Images/Day71_CICD4.png)
### Jenkins 아키텍처
먼저, 바퀴를 재발명하고 싶지 않기 때문에 항상 [Jenkins 문서](https://www.jenkins.io/doc/developer/architecture/)에서 시작하는 것이 가장 좋지만, 여기에도 제가 메모하고 배운 내용을 적어 두려고 합니다.
Jenkins는 윈도우, 리눅스, 맥OS 등 다양한 운영체제에 설치할 수 있을 뿐만 아니라 Docker 컨테이너로 배포하거나 Kubernetes 내에서 배포할 수 있는 기능도 있습니다. [Jenkins 설치하기](https://www.jenkins.io/doc/book/installing/)
이번 글에서는 Minikube 클러스터 내에 Jenkins를 설치하여 Kubernetes에 배포하는 과정을 시뮬레이션해 보겠습니다. 하지만 이는 이 섹션의 나머지 부분에서 구성한 시나리오에 따라 달라집니다.
이제 아래 이미지를 분석해 보겠습니다.
1단계 - 개발자가 소스 코드 리포지토리에 변경 사항을 커밋합니다.
2단계 - Jenkins가 정기적으로 리포지토리를 확인하여 새 코드를 가져옵니다.
3단계 - 빌드 서버가 코드를 실행 파일로 빌드하며, 이 예에서는 잘 알려진 빌드 서버로 maven을 사용하고 있습니다. 다루어야 할 또 다른 영역입니다.
4단계 - 빌드에 실패하면 개발자에게 피드백이 다시 전송됩니다.
5단계 - 그런 다음 Jenkins는 빌드된 앱을 테스트 서버에 배포합니다. 이 예에서는 잘 알려진 테스트 서버로 selenium을 사용하고 있습니다. 또 다른 영역입니다.
6단계 - 테스트가 실패하면 개발자에게 피드백이 전달됩니다.
7단계 - 테스트가 성공하면 프로덕션에 릴리스할 수 있습니다.
이 주기는 연속적이기 때문에 애플리케이션을 몇 시간, 며칠, 몇 달, 몇 년이 아닌 몇 분 만에 업데이트할 수 있습니다!
![](/2022/Days/Images/Day71_CICD5.png)
필요한 경우 master가 slave Jenkins 환경에 작업을 배포할 수 있는 master-slave 기능이 있는 등 Jenkins의 아키텍처에는 훨씬 더 많은 기능이 있습니다.
참고로 Jenkins는 오픈 소스이므로 지원을 필요로 하는 많은 기업이 있을 것이며, CloudBees는 유료 엔터프라이즈 고객을 위한 지원 및 기타 기능을 제공하는 엔터프라이즈 버전의 Jenkins입니다.
고객 중 한 예로 Bosch를 들 수 있는데, Bosch 사례 연구는 [여기](https://assets.ctfassets.net/vtn4rfaw6n2j/case-study-boschpdf/40a0b23c61992ed3ee414ae0a55b6777/case-study-bosch.pdf)에서 확인할 수 있습니다.
내일은 애플리케이션의 단계별 예시를 통해 Jenkins를 사용하는 방법을 살펴본 다음 다른 도구와 함께 사용할 수 있도록 하겠습니다.
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 72](day72.md)에서 봐요!킨

162
2022/ko/Days/day72.md Normal file
View File

@ -0,0 +1,162 @@
---
title: '#90DaysOfDevOps - Getting hands-on with Jenkins - Day 72'
published: false
description: 90DaysOfDevOps - Getting hands-on with Jenkins
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048829
---
## Jenkins 실습하기
오늘 계획은 Jenkins를 직접 사용해 보고 CI 파이프라인의 일부로 사용할 수 있는 몇 가지 예제 코드 베이스를 살펴보면서 무언가를 만들어 보는 것입니다.
### 파이프라인이란 무엇인가요?
시작하기 전에 CI와 관련하여 파이프라인이 무엇인지 알아야 하는데, 어제 세션에서 이미 다음 이미지와 함께 이 내용을 다루었습니다.
![](/2022/Days/Images/Day71_CICD4.png)
위의 프로세스 또는 단계를 자동화하여 최종적으로 배포된 애플리케이션을 고객, 최종 사용자 등에게 제공할 수 있는 결과물을 얻고자 합니다.
이 자동화된 프로세스를 통해 사용자와 고객에 대한 버전 관리를 수행할 수 있습니다. 모든 변경 사항, 기능 향상, 버그 수정 등은 이 자동화된 프로세스를 거쳐 코드가 양호한지 확인하기 위해 많은 수동 개입 없이 모든 것이 정상인지 확인합니다.
이 프로세스에는 안정적이고 반복 가능한 방식으로 소프트웨어를 빌드하고, 여러 단계의 테스트 및 배포를 통해 빌드된 소프트웨어('build'라고 함)를 발전시키는 작업이 포함됩니다.
Jenkins 파이프라인은 Jenkins파일이라는 텍스트 파일로 작성됩니다. 이 파일은 소스 제어 리포지토리에 커밋되어야 합니다. 이를 코드형 파이프라인이라고도 하며, 몇 주 전에 다룬 IaC에 매우 유사하게 비유할 수도 있습니다.
[Jenkins 파이프라인 정의](https://www.jenkins.io/doc/book/pipeline/#ji-toolbar)
### Jenkins 배포하기
Jenkins 배포를 재미있게 해봤는데요, [문서](https://www.jenkins.io/doc/book/installing/)를 보면 Jenkins를 설치할 수 있는 위치에 대한 옵션이 많다는 것을 알 수 있습니다.
저는 Minikube를 가지고 있고 이를 여러 번 사용했기 때문에 이 작업에도 Minikube를 사용하고 싶었습니다. (또한 무료입니다!) [Kubernetes 설치](https://www.jenkins.io/doc/book/installing/kubernetes/)에 나와 있는 단계는 벽에 부딪혀서 실행하지 못했지만, 여기에 단계를 문서화하면 두 가지를 비교할 수 있습니다.
첫 번째 단계는 Minikube 클러스터를 시작하고 실행하는 것으로, `minikube start` 명령으로 간단히 할 수 있습니다.
![](/2022/Days/Images/Day72_CICD1.png)
여기에서 찾을 수 있는 모든 YAML 구성과 값이 있는 폴더를 [여기](/2022/Days/CICD/Jenkins) 추가했습니다.이제 클러스터가 생겼으므로 다음을 실행하여 jenkins 네임스페이스를 생성할 수 있습니다. `kubectl create -f jenkins-namespace.yml`
![](/2022/Days/Images/Day72_CICD2.png)
클러스터에 Jenkins를 배포하기 위해 Helm을 사용할 것이며, Helm은 Kubernetes 섹션에서 다루었습니다. 먼저 jenkinsci Helm 리포지토리 `helm repo add jenkinsci https://charts.jenkins.io`를 추가한 다음 `helm repo update` chart를 업데이트해야 합니다.
![](/2022/Days/Images/Day72_CICD3.png)
Jenkins의 기본 개념은 파이프라인의 상태를 저장하는 것으로, 위의 Helm 설치를 지속성 없이 실행할 수 있지만 해당 pod가 재부팅, 변경 또는 수정되면 생성한 파이프라인이나 구성이 손실됩니다. `kubectl apply -f jenkins-volume.yml` 명령으로 jenkins-volume.yml 파일을 사용하여 지속성을 위한 volume을 생성합니다.
![](/2022/Days/Images/Day72_CICD4.png)
또한 이 YAML 파일과 명령어를 사용하여 생성할 수 있는 서비스 계정이 필요합니다. `kubectl apply -f jenkins-sa.yml`
![](/2022/Days/Images/Day72_CICD5.png)
이 단계에서는 Helm chart를 사용하여 배포하는 것이 좋으며, 먼저 `chart=jenkinsci/jenkins`를 사용하여 chart를 정의한 다음, 이 명령을 사용하여 배포할 것이며, 여기에는 이전에 클러스터에 배포한 지속성 및 서비스 계정이 포함된 jenkins-values.yml이 포함됩니다. `helm install jenkins -n jenkins -f jenkins-values.yml $chart`
![](/2022/Days/Images/Day72_CICD6.png)
이 단계에서는 pod가 이미지를 가져올 것이지만 pod가 스토리지에 액세스할 수 없으므로 Jenkins를 시작하고 실행하기 위한 구성을 시작할 수 없습니다.
이 단계에서는 문서가 무슨 일이 일어나야 하는지 이해하는 데 큰 도움이 되지 않았습니다. 하지만 Jenkins 설치를 시작할 수 있는 권한이 없다는 것을 알 수 있습니다.
![](/2022/Days/Images/Day72_CICD7.png)
위의 문제를 수정하거나 해결하려면, 우리가 제안한 이 위치에 Jenkins pod가 쓸 수 있도록 액세스 권한 또는 올바른 권한을 제공해야 합니다. 이를 위해 `minikube ssh`를 사용하여 실행 중인 Minikube Docker 컨테이너에 들어간 다음 `sudo chown -R 1000:1000 /data/jenkins-volume`을 사용하여 데이터 volume에 대한 권한이 설정되어 있는지 확인할 수 있습니다.
![](/2022/Days/Images/Day72_CICD8.png)
위의 프로세스로 pod가 수정되어야 하지만, 그렇지 않은 경우 `kubectl delete pod jenkins-0 -n jenkins` 명령으로 pod를 강제로 새로 고칠 수 있습니다. 이 시점에서, 2/2의 실행 중인 pod인 jenkins-0이 있어야 합니다.
![](/2022/Days/Images/Day72_CICD9.png)
이제 관리자 비밀번호가 필요하며 다음 명령어를 사용하여 비밀번호를 입력할 수 있습니다. `kubectl exec --namespace jenkins -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password && echo`
![](/2022/Days/Images/Day72_CICD10.png)
이제 워크스테이션에서 접근할 수 있도록 `port-forward` 명령을 사용할 것이므로 새 터미널을 엽니다. `kubectl --namespace jenkins port-forward svc/jenkins 8080:8080`
![](/2022/Days/Images/Day72_CICD11.png)
이제 브라우저를 열고 `http://localhost:8080`에 로그인하여 이전 단계에서 수집한 username: admin과 password로 인증할 수 있어야 합니다.
![](/2022/Days/Images/Day72_CICD12.png)
인증이 완료되면 Jenkins 시작 페이지는 다음과 같이 표시되어야 합니다:
![](/2022/Days/Images/Day72_CICD13.png)
여기에서 "Manage Jenkins"로 이동하면 사용 가능한 몇 가지 업데이트가 있는 "Manage Plugins"가 표시됩니다. 해당 플러그인을 모두 선택하고 "Download now and install after restart"를 선택합니다.
![](/2022/Days/Images/Day72_CICD14.png)
더 나아가 shell 스크립트를 사용하여 Jenkins 배포를 자동화하고 싶다면 트위터에서 저와 공유한 이 훌륭한 리포지토리를 참고하세요 [mehyedes/nodejs-k8s](https://github.com/mehyedes/nodejs-k8s/blob/main/docs/automated-setup.md).
### Jenkinsfile
이제 Kubernetes 클러스터에 Jenkins가 배포되었으므로 이제 돌아가서 이 Jenkinsfile에 대해 생각해 볼 수 있습니다.
모든 Jenkinsfile은 이렇게 시작될 가능성이 높습니다. 먼저 파이프라인의 단계를 정의하는 곳이며, 이 경우에는 빌드 > 테스트 > 배포가 있습니다. 하지만 여기서는 특정 단계를 호출하기 위해 `echo` 명령을 사용하는 것 외에는 아무것도 하지 않습니다.
```
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
}
```
Jenkins 대시보드에서 "New Item"을 선택하고 항목에 이름을 지정합니다. 저는 "echo1"이라고 하고 이것이 파이프라인이라고 해보겠습니다.
![](/2022/Days/Images/Day72_CICD15.png)
확인을 누르면 파이프라인에만 관심이 있는 간단한 테스트를 위한 탭(일반, 빌드 트리거, 고급 프로젝트 옵션 및 파이프라인)이 표시됩니다. 파이프라인에서 스크립트를 추가할 수 있으며, 위의 스크립트를 복사하여 상자에 붙여 넣을 수 있습니다.
위에서 말했듯이 이것은 많은 작업을 수행하지는 않지만 빌드 > 테스트 > 배포의 단계를 보여줍니다.
![](/2022/Days/Images/Day72_CICD16.png)
저장을 클릭하면 이제 아래에 강조 표시된 "build now"를 사용하여 빌드를 실행할 수 있습니다.
![](/2022/Days/Images/Day72_CICD17.png)
또한 터미널을 열고 `kubectl get pods -n jenkins`를 실행하여 어떤 일이 발생하는지 확인해야 합니다.
![](/2022/Days/Images/Day72_CICD18.png)
자, 아주 간단하지만 이제 Jenkins 배포와 설치가 올바르게 작동하고 있으며 여기에서 CI 파이프라인의 구성 요소를 볼 수 있습니다.
다음 섹션에서는 Jenkins 파이프라인을 구축하겠습니다.
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 73](day73.md)에서 봐요!

226
2022/ko/Days/day73.md Normal file
View File

@ -0,0 +1,226 @@
---
title: '#90DaysOfDevOps - Building a Jenkins Pipeline - Day 73'
published: false
description: 90DaysOfDevOps - Building a Jenkins Pipeline
tags: 'DevOps, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048766
---
## Jenkins 파이프라인 구축하기
지난 섹션에서는 Minikube 클러스터에 Jenkins를 배포하고 파이프라인의 단계를 echo하는 것 외에는 별다른 기능을 하지 않는 매우 기본적인 Jenkins 파이프라인을 설정했습니다.
또한 Jenkins Pipeline 생성에서 실행할 수 있는 몇 가지 예제 스크립트가 있다는 것을 보셨을 것입니다.
![](/2022/Days/Images/Day73_CICD1.png)
첫 번째 데모 스크립트는 "Declarative (Kubernetes)"이며 아래 단계를 볼 수 있습니다.
```Yaml
// Uses Declarative syntax to run commands inside a container.
pipeline {
agent {
kubernetes {
// Rather than inline YAML, in a multibranch Pipeline you could use: yamlFile 'jenkins-pod.yaml'
// Or, to avoid YAML:
// containerTemplate {
// name 'shell'
// image 'ubuntu'
// command 'sleep'
// args 'infinity'
// }
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: shell
image: ubuntu
command:
- sleep
args:
- infinity
'''
// Can also wrap individual steps:
// container('shell') {
// sh 'hostname'
// }
defaultContainer 'shell'
}
}
stages {
stage('Main') {
steps {
sh 'hostname'
}
}
}
}
```
이 파이프라인을 실행하면 어떤 결과가 발생하는지 아래에서 확인할 수 있습니다.
![](/2022/Days/Images/Day73_CICD2.png)
### Job 만들기
#### 목표
- 간단한 앱을 만들어 GitHub 공용 리포지토리에 저장 [https://github.com/scriptcamp/kubernetes-kaniko.git](https://github.com/scriptcamp/kubernetes-kaniko.git)
- Jenkins를 사용하여 Docker 컨테이너 이미지를 빌드하고 DockerHub에 push합니다. (이를 위해 비공개 리포지토리를 사용합니다.)
Minikube에서 실행 중이거나 Minikube를 사용하는 Kubernetes 클러스터에서 이 작업을 수행하려면 [Kaniko](https://github.com/GoogleContainerTools/kaniko#running-kaniko-in-a-kubernetes-cluster)라는 것을 사용해야 하지만, 실제 Kubernetes 클러스터에서 Jenkins를 사용하거나 서버에서 실행하는 경우 에이전트를 지정하여 Docker 빌드 명령을 수행하고 이를 DockerHub에 업로드할 수 있는 기능을 제공하는 것이 일반적입니다.
위의 내용을 염두에 두고 GitHub credentials로 Kubernetes에 시크릿을 배포해 보겠습니다.
```Shell
kubectl create secret docker-registry dockercred \
--docker-server=https://index.docker.io/v1/ \
--docker-username=<dockerhub-username> \
--docker-password=<dockerhub-password>\
--docker-email=<dockerhub-email>
```
여기서 다룰 내용 대부분을 관통하는 [DevOpsCube.com](https://devopscube.com/build-docker-image-kubernetes-pod/)의 또 다른 훌륭한 리소스를 공유하고자 합니다.
### Jenkins에 credentials 추가하기
하지만 저희와 다른 Jenkins 시스템을 사용 중이라면 Jenkins 내에서 credentials를 정의한 다음 파이프라인 및 구성 내에서 여러 번 사용하고 싶을 것입니다. 생성 시 결정한 ID를 사용하여 파이프라인에서 이러한 credentials를 참조할 수 있습니다. 계속해서 단계를 진행하여 DockerHub 및 GitHub에 대한 사용자 항목을 만들었습니다.
먼저 "Manage Jenkins"를 선택한 다음 "Manage Credentials"를 선택합니다.
![](/2022/Days/Images/Day73_CICD3.png)
페이지 중앙에 Jenkins로 범위가 설정된 Stores가 표시되면 여기에서 Jenkins를 클릭합니다.
![](/2022/Days/Images/Day73_CICD4.png)
이제 Global Credentials (Unrestricted)를 선택합니다.
![](/2022/Days/Images/Day73_CICD5.png)
그런 다음 왼쪽 상단에 Add Credentials가 있습니다.
![](/2022/Days/Images/Day73_CICD6.png)
계정에 대한 세부 정보를 입력한 다음 확인을 선택하고, 이 credentials를 호출할 때 참조할 ID를 기억하세요. 여기서도 비밀번호 대신 특정 토큰 액세스를 사용하는 것이 좋습니다.
![](/2022/Days/Images/Day73_CICD7.png)
GitHub의 경우 [Personal Access Token](https://vzilla.co.uk/vzilla-blog/creating-updating-your-github-personal-access-token)을 사용해야 합니다.
저는 이 계정을 생성하는 과정이 직관적이지 않아서 사용하지는 않지만, UI에서 명확하지 않아서 그 과정을 공유하고 싶었습니다.
### 파이프라인 구축
Kubernetes 클러스터에 비밀로 배포된 DockerHub credentials를 가지고 있으며, 이 credentials를 파이프라인의 DockerHub 단계에 배포하기 위해 호출할 것입니다.
파이프라인 스크립트는 아래에서 볼 수 있는 것과 같으며, 파이프라인의 프로젝트 가져오기 단계에서도 볼 수 있는 GitHub 리포지토리에 있는 Jenkinsfile이 될 수 있습니다.
```Yaml
podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven
command:
- sleep
args:
- 99d
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command:
- sleep
args:
- 9999999
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker
restartPolicy: Never
volumes:
- name: kaniko-secret
secret:
secretName: dockercred
items:
- key: .dockerconfigjson
path: config.json
''') {
node(POD_LABEL) {
stage('Get the project') {
git url: 'https://github.com/scriptcamp/kubernetes-kaniko.git', branch: 'main'
container('maven') {
stage('Test the project') {
sh '''
echo pwd
'''
}
}
}
stage('Build & Test the Docker Image') {
container('kaniko') {
stage('Deploy to DockerHub') {
sh '''
/kaniko/executor --context `pwd` --destination me1e/helloword
'''
}
}
}
}
}
```
Jenkins 대시보드에서 항목을 시작하려면 "New Item"을 선택해야 합니다.
![](/2022/Days/Images/Day73_CICD8.png)
그런 다음 항목에 이름을 지정하고 파이프라인을 선택한 다음 확인을 누릅니다.
![](/2022/Days/Images/Day73_CICD9.png)
일반 트리거나 빌드 트리거는 선택하지 않겠지만 흥미로운 일정과 기타 구성이 있을 수 있으므로 이 트리거를 사용해 보겠습니다.
![](/2022/Days/Images/Day73_CICD10.png)
마지막에 있는 Pipeline 탭에만 관심이 있습니다.
![](/2022/Days/Images/Day73_CICD11.png)
파이프라인 정의에서 위에 있는 파이프라인 스크립트를 스크립트 섹션에 복사하여 붙여 넣고 저장을 누릅니다.
![](/2022/Days/Images/Day73_CICD12.png)
다음으로 페이지 왼쪽에서 "Build Now" 옵션을 선택합니다.
![](/2022/Days/Images/Day73_CICD13.png)
이제 1분 미만의 짧은 시간을 기다려야 합니다. Status 아래에 위에서 스크립트에서 정의한 단계가 표시됩니다.
![](/2022/Days/Images/Day73_CICD14.png)
더 중요한 것은 이제 DockerHub로 이동하여 새 빌드가 있는지 확인하는 것입니다.
![](/2022/Days/Images/Day73_CICD15.png)
전체적으로 파악하는 데 시간이 좀 걸렸지만, Minikube와 GitHub 및 DockerHub에 대한 액세스를 사용하여 누구나 실행할 수 있는 시나리오를 실습하고 작업하기 위해 계속 진행하려고 했습니다.
이 데모에 사용한 DockerHub 리포지토리는 비공개 리포지토리였습니다. 하지만 다음 섹션에서는 이러한 단계 중 일부를 발전시켜 단순히 `pwd`를 출력하고 몇 가지 테스트 및 빌드 단계를 실행하는 대신 무언가를 수행하도록 하고 싶습니다.
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 74](day74.md)에서 봐요!

96
2022/ko/Days/day74.md Normal file
View File

@ -0,0 +1,96 @@
---
title: '#90DaysOfDevOps - Hello World - Jenkinsfile App Pipeline - Day 74'
published: false
description: 90DaysOfDevOps - Hello World - Jenkinsfile App Pipeline
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048744
---
## Hello World - Jenkinsfile 앱 파이프라인
지난 섹션에서는 공개 GitHub 리포지토리에 있는 dockerfile에서 비공개 Dockerhub 리포지토리로 docker 이미지를 push하는 간단한 Jenkins 파이프라인을 구축했습니다.
이 섹션에서는 한 단계 더 나아가 간단한 애플리케이션을 통해 다음을 달성하고자 합니다.
### 목표
- Dockerfile (Hello World)
- Jenkinsfile
- GitHub 리포지토리가 업데이트될 때 트리거할 Jenkins 파이프라인
- GitHub 리포지토리를 소스로 사용
- Run - 리포지토리 복제/가져오기, 빌드, 테스트, 배포 단계
- 점진적인 버전 번호로 DockerHub에 배포
- Kubernetes 클러스터에 배포하는(여기에는 GitHub credentials를 사용하는 다른 job 및 매니페스트 리포지토리가 포함됨) Stretch Goal
### 1단계
[GitHub 리포지토리](https://github.com/MichaelCade/Jenkins-HelloWorld)가 있습니다. 여기에는 현재 Dockerfile과 index.html이 있습니다.
![](/2022/Days/Images/Day74_CICD1.png)
위에서 파이프라인에서 소스로 사용하던 것을 이제 해당 Jenkins 파이프라인 스크립트를 GitHub 리포지토리에도 추가하려고 합니다.
![](/2022/Days/Images/Day74_CICD2.png)
이제 Jenkins 대시보드로 돌아가서 새 파이프라인을 만들되, 스크립트를 붙여 넣는 대신 "Pipeline script from SCM"를 사용하고 아래의 구성 옵션을 사용하겠습니다.
참고로 리포지토리 URL은 `https://github.com/MichaelCade/Jenkins-HelloWorld.git`을 사용하겠습니다.
![](/2022/Days/Images/Day74_CICD3.png)
이 시점에서 저장 및 적용을 누르면 수동으로 파이프라인을 실행하여 DockerHub 리포지토리에 업로드된 새 Docker 이미지를 빌드할 수 있습니다.
하지만 리포지토리 또는 소스 코드가 변경될 때마다 빌드를 트리거하도록 일정을 설정하고 싶습니다. webhooks를 사용하거나 예약 pull을 사용할 수 있습니다.
파이프라인을 유지하기 위해 값비싼 클라우드 리소스를 사용하고 있고 코드 저장소에 변경 사항이 많다면 많은 비용이 발생할 수 있으므로 이 점을 크게 고려해야 합니다. 이것이 데모 환경이라는 것을 알고 있기 때문에 "poll scm" 옵션을 사용하고 있습니다. (또한 Minikube를 사용하면 webhooks를 사용할 수 있는 기능이 부족하다고 생각합니다.)
![](/2022/Days/Images/Day74_CICD4.png)
어제 세션 이후 변경한 한 가지는 이제 이미지를 공개 저장소(이 경우 michaelcade1\90DaysOfDevOps)에 업로드하고 싶다는 것인데, 제 Jenkinsfile에는 이미 이 변경 사항이 있습니다. 그리고 이전 섹션에서 기존 데모 컨테이너 이미지를 모두 제거했습니다.
![](/2022/Days/Images/Day74_CICD5.png)
여기서 거꾸로 돌아가서 파이프라인을 생성한 다음 이전에 표시된 대로 구성을 추가했습니다.
![](/2022/Days/Images/Day74_CICD6.png)
이 단계에서는 파이프라인이 실행되지 않았으며 스테이지 뷰는 다음과 같이 표시됩니다.
![](/2022/Days/Images/Day74_CICD7.png)
이제 "Build Now" 버튼을 트리거해 보겠습니다. 그러면 스테이지 뷰에 스테이지가 표시됩니다.
![](/2022/Days/Images/Day74_CICD8.png)
이제 DockerHub 리포지토리로 이동하면 2개의 새 Docker 이미지가 있어야 합니다. 빌드 ID는 1이고 최신 빌드가 있어야 하는데, 이는 "Upload to DockerHub"를 기반으로 생성하는 모든 빌드에 대해 Jenkins Build_ID 환경 변수를 사용하여 버전을 전송하고 최신 빌드도 발행하기 때문입니다.
![](/2022/Days/Images/Day74_CICD9.png)
이제 아래와 같이 깃허브 리포지토리에 index.html 파일을 업데이트해 보겠습니다.
![](/2022/Days/Images/Day74_CICD10.png)
Jenkins로 돌아가서 "Build Now"를 다시 선택하면 됩니다. 2번 빌드가 성공했는지 확인해 보겠습니다.
![](/2022/Days/Images/Day74_CICD11.png)
그런 다음 DockerHub를 간단히 살펴보면 태그가 버전 2와 최신 태그가 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day74_CICD12.png)
여기서 한 가지 주목할 점은, 제가 Kubernetes 클러스터에 액세스 및 인증을 통해 DockerHub로 도커 빌드를 push할 수 있는 시크릿을 추가했다는 것입니다. 이 과정을 따라하는 경우 계정에 대해 이 과정을 반복하고 내 리포지토리 및 계정과 연결된 Jenkins파일도 변경해야 합니다.
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 75](day75.md)에서 봐요!

188
2022/ko/Days/day75.md Normal file
View File

@ -0,0 +1,188 @@
---
title: '#90DaysOfDevOps - GitHub Actions Overview - Day 75'
published: false
description: 90DaysOfDevOps - GitHub Actions Overview
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1049070
---
## GitHub Actions 개요
이 섹션에서는 방금 시간을 할애한 것과는 다른 접근 방식을 살펴보고자 합니다. 이 세션에서 집중적으로 다룰 내용은 GitHub Actions입니다.
GitHub Actions는 파이프라인의 다른 작업들 사이에서 빌드, 테스트 및 배포할 수 있는 CI/CD 플랫폼입니다. 이 플랫폼은 GitHub 리포지토리를 대상으로 빌드하고 테스트하는 Wolkflow의 개념을 가지고 있습니다. 또한 GitHub Actions를 사용하여 리포지토리 내에서 발생하는 Event를 기반으로 다른 Wolkflow를 구동할 수도 있습니다.
### Wolkflow
전반적으로 GitHub Actions에서는 작업을 **Wolkflow**라고 부릅니다.
- **Wolkflow**는 구성 가능한 자동화된 프로세스입니다.
- YAML 파일로 정의됩니다.
- 하나 이상의 **Job**을 포함하고 실행합니다.
- 리포지토리의 **Event**에 의해 트리거될 때 실행되거나 수동으로 실행할 수 있습니다.
- 리포지토리당 여러 Wolkflow를 사용할 수 있습니다.
- **Wolkflow**에는 **Job**과 해당 **Job**을 달성하기 위한 **Step**이 포함됩니다.
- **Wolkflow** 내에는 **Wolkflow**가 실행되는 **Runner**도 있습니다.
예를 들어 PR을 빌드하고 테스트하는 **Wolkflow**, 릴리스가 만들어질 때마다 애플리케이션을 배포하는 **Wolkflow**, 누군가 새 issue를 열 때마다 레이블을 추가하는 또 다른 **Wolkflow**가 있을 수 있습니다.
### Event
Event는 Wolkflow를 실행하도록 트리거하는 리포지토리의 특정 이벤트입니다.
### Job
Job은 Runner에서 실행되는 Wolkflow의 Step 집합입니다.
### Step
Job 내의 각 Ste은 실행되는 shell 스크립트 또는 Action이 될 수 있습니다. Step은 순서대로 실행되며 서로 종속됩니다.
### Action
자주 반복되는 작업에는 반복 가능한 사용자 지정 애플리케이션이 사용됩니다.
### Runner
Runner는 Wolkflow를 실행하는 서버로, 각 Runner는 한 번에 하나의 작업을 실행합니다. GitHub Actions는 Ubuntu Linux, Microsoft Windows 및 macOS Runner를 실행할 수 있는 기능을 제공합니다. 특정 OS 또는 하드웨어에서 직접 호스팅할 수도 있습니다.
아래에서 Wolkflow를 트리거하는 Event > Wolkflow가 두 개의 Job으로 구성 > 작업 내에 단계와 액션이 있는 모습을 볼 수 있습니다.
아래에서 Wolkflow를 트리거하는 Event가 있고 > Wolkflow가 두 개의 Job으로 구성되어 있으며 > Job 내에 Step가 있고 > Action이 있는 것을 볼 수 있습니다.
![](/2022/Days/Images/Day75_CICD1.png)
### YAML
실제 사용 사례를 살펴보기 전에 위의 이미지를 예제 YAML 파일 형태로 간단히 살펴봅시다.
주석을 추가하여 YAML Wolkflow의 구성 요소를 찾을 수 있도록 했습니다.
```Yaml
#Workflow
name: 90DaysOfDevOps
#Event
on: [push]
#Jobs
jobs:
check-bats-version:
#Runner
runs-on: ubuntu-latest
#Steps
steps:
#Actions
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install -g bats
- run: bats -v
```
### GitHub Actions 실습하기
코드 빌드, 테스트, 배포 및 그 이후의 지속적인 단계와 관련하여 CI/CD 요구 사항을 충족할 수 있는 GitHub Actions에는 많은 옵션이 있다고 생각합니다.
GitHub Actions를 사용할 수 있는 많은 옵션과 기타 자동화된 작업을 볼 수 있습니다.
### 코드 lint에 GitHub 액션 사용하기
한 가지 옵션은 리포지토리 내에서 코드를 깨끗하고 깔끔하게 정리하는 것입니다. 이것이 첫 번째 예제 데모가 될 것입니다.
이 섹션의 리소스 중 하나에 링크된 몇 가지 예제 코드를 사용하여 `GitHub/super-linter`를 사용하여 코드를 확인하겠습니다.
```Yaml
name: Super-Linter
on: push
jobs:
super-lint:
name: Lint code base
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run Super-Linter
uses: github/super-linter@v3
env:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
**github/super-linter**
위에서 단계 중 하나에 GitHub/super-linter라는 Action이 있으며 이는 커뮤니티에서 이미 작성된 Step을 참조하고 있음을 알 수 있습니다. 이에 대한 자세한 내용은 [Super-Linter](https://github.com/github/super-linter)에서 확인할 수 있습니다.
"이 리포지토리는 super-linter를 실행하기 위한 Github Actions를 위한 저장소입니다. 소스 코드의 유효성을 검사하는 데 도움이 되도록 bash로 작성된 다양한 linter의 간단한 조합입니다."
또한 위의 코드 스니펫에 GITHUB_TOKEN이 언급되어 있어서 이것이 왜 필요한지, 어떤 용도로 사용되는지 궁금했습니다.
"참고: Wolkflow에서 환경 변수 `GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`을 전달하면 GitHub Super-Linter가 PR의 Checks 섹션에 각 linter 실행 상태를 표시합니다. 이 기능이 없으면 전체 실행의 전체 상태만 볼 수 있습니다. **GitHub Secret은 GitHub에서 자동으로 설정하므로 설정할 필요가 없으며, Action으로 전달하기만 하면 됩니다.**"
굵은 텍스트는 이 단계에서 주목해야 할 중요한 부분입니다. 우리는 이 기능을 사용하지만, 리포지토리 내에서 환경 변수를 설정할 필요는 없습니다.
테스트할 리포지토리는 Jenkins 데모에서 사용한 리포지토리를 사용하겠습니다. [Jenkins-HelloWorld](https://github.com/MichaelCade/Jenkins-HelloWorld).
다음은 Jenkins 세션에 남겨둔 저장소입니다.
![](/2022/Days/Images/Day75_CICD2.png)
이 기능을 활용하려면 위의 Actions 탭을 사용하여 곧 다룰 마켓플레이스에서 선택하거나 위의 super-linter 코드를 사용하여 파일을 생성할 수 있는데, 직접 생성하려면 리포지토리에 이 위치에 새 파일을 만들어야 합니다. `.github/workflows/workflow_name`은 분명히 여러분이 알아볼 수 있는 유용한 이름이어야 하며, 여기에는 리포지토리에 대해 다양한 작업과 작업을 수행하는 다양한 Wolkflow가 있을 수 있습니다.
`.github/workflows/super-linter.yml`을 생성하겠습니다.
![](/2022/Days/Images/Day75_CICD3.png)
이제 코드를 붙여 넣고 리포지토리에 코드를 커밋한 다음 Actions 탭으로 이동하면 아래와 같은 super-linter Wolkflow가 표시됩니다.
![](/2022/Days/Images/Day75_CICD4.png)
코드에서 리포지토리에 무언가를 push할 때 이 Wolkflow가 실행되도록 정의했기 때문에, super-linter.yml을 리포지토리에 push할 때 Wolkflow가 트리거되었습니다.
![](/2022/Days/Images/Day75_CICD5.png)
위에서 보시다시피 해킹 능력과 코딩 능력에 따라 몇 가지 오류가 발생했습니다.
적어도 아직은 제 코드는 아니었지만, 이 코드를 실행하고 오류가 발생했을 때 이 [문제](https://github.com/github/super-linter/issues/2255)를 발견했습니다.
2번 super-linter의 버전을 버전 3에서 4로 변경하고 작업을 다시 실행했습니다.
![](/2022/Days/Images/Day75_CICD6.png)
예상대로 해커 코딩에서 몇 가지 문제가 발생했으며 여기 [Wolkflow](https://github.com/MichaelCade/Jenkins-HelloWorld/runs/5600278515?check_suite_focus=true)에서 확인할 수 있습니다.
Wolkflow 내에서 무언가가 실패하거나 오류를 보고했을 때 리포지토리에 표시되는 모습을 지금 보여주고 싶었습니다.
![](/2022/Days/Images/Day75_CICD7.png)
이제 제 코드에서 문제를 해결하고 변경 사항을 적용하면 Wolkflow가 다시 실행됩니다(이미지에서 'bugs'를 해결하는 데 시간이 걸린 것을 볼 수 있습니다.) 파일을 삭제하는 것은 권장되지 않지만, 문제가 해결되었음을 보여주는 매우 빠른 방법입니다.
![](/2022/Days/Images/Day75_CICD8.png)
위에 강조 표시된 new Wolkflow 버튼을 누르면 수많은 작업의 문이 열립니다. 이번 챌린지를 진행하면서 눈치채셨겠지만, 저희는 거인의 어깨 위에 서서 코드, 자동화 및 기술을 널리 공유하여 삶을 더 편하게 만들고자 하는 것이 아닙니다.
![](/2022/Days/Images/Day75_CICD9.png)
Wolkflow가 성공했을 때 리포지토리의 녹색 체크 표시를 보여드리지 못했네요.
![](/2022/Days/Images/Day75_CICD10.png)
지금까지는 GitHub Actions의 기본적인 관점에 대해 설명했지만, 저와 같은 분이라면 GitHub Actions를 사용하여 많은 작업을 자동화할 수 있는 다른 방법을 알고 계실 것입니다.
다음에는 CD의 또 다른 영역인 애플리케이션을 환경에 배포하기 위해 ArgoCD를 살펴볼 것입니다.
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 76](day76.md)에서 봐요!

83
2022/ko/Days/day76.md Normal file
View File

@ -0,0 +1,83 @@
---
title: '#90DaysOfDevOps - ArgoCD Overview - Day 76'
published: false
description: 90DaysOfDevOps - ArgoCD Overview
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048809
---
## ArgoCD 개요
"Argo CD는 Kubernetes를 위한 선언적 GitOps 지속적 배포 도구입니다."
버전 제어가 핵심입니다. 환경을 즉석에서 변경했는데 그 변경 사항을 기억하지 못하고 불이 켜져 있고 모든 것이 초록색이기 때문에 계속 진행했던 적이 있으신가요? 변경을 시도했다가 모든 것 또는 일부가 망가진 적이 있나요? 변경한 사실을 알았다면 잘못된 스크립트나 맞춤법 오류를 빠르게 되돌릴 수 있을 것입니다. 하지만 대규모로 변경을 진행하다 보니 본인도 몰랐을 수도 있고, 바로 발견하지 못해 비즈니스가 어려움을 겪고 있을 수도 있습니다. 따라서 버전 관리가 중요합니다. 뿐만 아니라 "애플리케이션 정의, 구성 및 환경은 선언적이어야 하며 버전 관리가 이루어져야 합니다." 이 외에도 "애플리케이션 배포 및 수명 주기 관리는 자동화되고, 감시 가능하며, 이해하기 쉬워야 한다"고 언급합니다.
운영 배경을 가지고 있지만 IaC로 사용하는 데 많은 경험을 쌓은 저로서는 지속적인 배포/제공 워크플로우를 통해 이 모든 좋은 것들을 처리할 수 있는 다음 단계라고 생각합니다.
[ArgoCD란](https://argo-cd.readthedocs.io/en/stable/)
### ArgoCD 배포
이번 배포에서는 신뢰할 수 있는 Minikube Kubernetes 클러스터를 다시 로컬로 사용할 것입니다.
```Shell
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
```
![](/2022/Days/Images/Day76_CICD1.png)
`kubectl get pods -n argocd`로 모든 ArgoCD pod가 실행되고 있는지 확인합니다.
![](/2022/Days/Images/Day76_CICD2.png)
또한, `kubectl get all -n argocd`로 네임스페이스에 배포한 모든 것을 확인해봅시다.
![](/2022/Days/Images/Day76_CICD3.png)
위의 내용이 정상적으로 보이면 포트 포워드를 통해 접근하는 것을 고려해야 합니다. 새 터미널에서 `kubectl port-forward svc/argocd-server -n argocd 8080:443` 명령을 사용합니다.
그런 다음 새 웹 브라우저를 열고 `https://localhost:8080`로 이동합니다.
![](/2022/Days/Images/Day76_CICD4.png)
로그인하려면 관리자 사용자 이름이 필요하며, 생성한 암호를 비밀번호로 사용하려면 `kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo`를 사용합니다.
![](/2022/Days/Images/Day76_CICD5.png)
로그인하면 비어있는 CD 캔버스가 표시됩니다.
![](/2022/Days/Images/Day76_CICD6.png)
### 애플리케이션 배포
이제 ArgoCD를 실행하고 실행 중이므로 이제 Helm뿐만 아니라 Git 리포지토리에서 애플리케이션을 배포하는 데 사용할 수 있습니다.
제가 배포하고자 하는 애플리케이션은 Pac-Man입니다. 네, Pac-Man은 유명한 게임이자 데이터 관리와 관련하여 많은 데모에서 사용하는 게임이며, 우리가 Pac-Man을 보는 것은 이번이 마지막이 아닐 것입니다.
[Pac-Man](https://github.com/MichaelCade/pacman-tanzu.git)의 리포지토리는 여기에서 찾을 수 있습니다.
스크린샷을 사용하여 각 단계를 설명하는 대신, 이 특정 애플리케이션 배포를 위해 수행한 단계를 다루는 연습 동영상을 만드는 것이 더 쉬울 것이라고 생각했습니다.
[ArgoCD 데모 - 90일간의 개발 운영](https://www.youtube.com/watch?v=w6J413_j0hA)
참고 - 영상 중 앱 상태가 정상인데도 만족스럽지 않은 서비스가 있는데, 이는 Pac-Man 서비스에 대해 설정된 로드밸런서 유형이 보류 중이고, Minikube에는 로드밸런서가 구성되지 않았기 때문입니다. 이 문제를 테스트하고 싶으시다면 서비스에 대한 YAML을 ClusterIP로 변경하고 포트 포워딩을 사용하여 게임을 플레이할 수 있습니다.
이것으로 CICD 파이프라인 섹션을 마칩니다. 현재 업계에서 이 영역에 많은 관심이 집중되고 있으며, 일반적으로 CICD 내에서 사용되는 방법론과 관련된 GitOps 관련 용어도 듣게 될 것입니다.
다음 섹션에서는 새로운 개념은 아니지만 환경을 다르게 바라보면서 점점 더 중요해지고 있는 또 다른 개념 또는 영역인 Observability에 대해 살펴봅니다.
## 자료
- [Jenkins is the way to build, test, deploy](https://youtu.be/_MXtbjwsz3A)
- [Jenkins.io](https://www.jenkins.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/en/stable/)
- [ArgoCD Tutorial for Beginners](https://www.youtube.com/watch?v=MeU5_k9ssrs)
- [What is Jenkins?](https://www.youtube.com/watch?v=LFDrDnKPOTg)
- [Complete Jenkins Tutorial](https://www.youtube.com/watch?v=nCKxl7Q_20I&t=3s)
- [GitHub Actions](https://www.youtube.com/watch?v=R8_veQiYBjI)
- [GitHub Actions CI/CD](https://www.youtube.com/watch?v=mFFXuXjVgkU)
[Day 77](day77.md)에서 봐요!

Some files were not shown because too many files have changed in this diff Show More