Skip to content

Commit

Permalink
docs: Refactor k8s (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf authored Sep 21, 2024
1 parent 585ea85 commit f3f366b
Show file tree
Hide file tree
Showing 138 changed files with 2,661 additions and 230 deletions.
1 change: 1 addition & 0 deletions docs/argocd/manifests/declarative.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ spec:
selfHeal: true
syncOptions:
- CreateNamespace=true # This will create namespace if not present


27 changes: 24 additions & 3 deletions docs/docker/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ Docker is an open-source platform designed to simplify the development, deployme
- `CMD` (command to run when the container starts)
- `WORKDIR` (create a directory where all the files will be copied and used)

To build an image from the **Dockerfile**, use this command:
### Docker Build Architecture

We can build the image in two ways single architecture or multi-architecture. In the single architecture, we can build the image for a specific architecture, and in multi-architecture, we can build the image for multiple architectures.

#### Single Architecture

```bash
docker build -t <image-name> .
```

#### Multi-Architecture

```bash
docker build <path>
// docker build .
docker buildx build --platform linux/amd64,linux/arm64 -t <image-name> .
```

**Good Practice**
Expand Down Expand Up @@ -236,6 +245,18 @@ HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost/ || exit 1
```

### Container Registry

A repo - a collection of repositories. Use to store and access container images.

Some popular registries are:

- Docker Hub
- GitHub Container Registry (ghcr.io)
- Google Container Registry (gcr.io)
- Amazon Elastic Container Registry (ECR)
- Azure Container Registry (ACR)

### Private Docker Registry

We can create a registry with the official [Registry image](https://hub.docker.com/_/registry).
Expand Down
39 changes: 39 additions & 0 deletions docs/github-actions/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,45 @@ jobs:
run: echo ${{ needs.deploy.outputs.url }}
```

## Artifacts

It allows you to share data between jobs in a workflow and store data once the workflow has been completed. We can use the `upload-artifact` and `download-artifact` actions to upload and download artifacts.

```yaml
name: Share data between jobs
on: [push]
jobs:
job_1:
name: Generate Random Number
runs-on: ubuntu-latest
steps:
- shell: bash
run: |
echo $((RANDOM % 100)) > random-number.txt
- name: Upload random number for job 1
uses: actions/upload-artifact@v4
with:
name: random_number
path: random-number.txt
job_2:
name: Echo Random Number
needs: job_1
runs-on: ubuntu-latest
steps:
- name: Download random number from job 1
uses: actions/download-artifact@v4
with:
name: random_number
- shell: bash
run: |
number=$(cat random-number.txt)
echo The random number is $number
```


### What's next?

- [Scenarios](./scenarios.md) - A collection of GitHub Actions workflow files I use and created to help you understand the concepts better.
Expand Down
16 changes: 15 additions & 1 deletion docs/golang/concepts/0) test.go
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
package main
package main

import "fmt"

func main() {
var num int = 42
var numFloat float64 = float64(num)

var numFloat2 = 3.14
var numInt = int(numFloat2)

fmt.Println(numFloat)
fmt.Println(numInt)
}

3 changes: 2 additions & 1 deletion docs/golang/concepts/17) switch-statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

func main() {

city := "london"
city := "paris"

switch city {
case "london", "manchester": // Here we are checking for multiple values with the same output
println("London or Manchester")
case "paris":
println("Paris ")
fallthrough
case "rome":
println("Rome ")
default: // This is the default case
Expand Down
18 changes: 18 additions & 0 deletions docs/golang/concepts/6) string-opr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"
"strings"
)

func main() {

var name = "John"
fmt.Println(len(name)) // It will print the length of the string
fmt.Println(strings.ToUpper(name)) // It will print the string in uppercase
fmt.Println(strings.ToLower(name)) // It will print the string in lowercase
fmt.Println(strings.Title(name)) // It will print the string in title case
fmt.Println(strings.Repeat(name, 3)) // It will repeat the string 3 times
fmt.Println(strings.Replace(name, "J", "K", 1)) // It will replace the first occurrence of J with K
fmt.Println(strings.Split(name, "")) // It will split the string into a slice of characters
}
23 changes: 23 additions & 0 deletions docs/helm/charts/minimal/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions docs/helm/charts/minimal/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: minimal
description: A tiny helm chart for educational purposes
type: application
version: 0.1.0
appVersion: 1.26.0
1 change: 1 addition & 0 deletions docs/helm/charts/minimal/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi 👋 -- you just deployed {{ template "envShort" . }}
7 changes: 7 additions & 0 deletions docs/helm/charts/minimal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- define "envShort" -}}
{{- if eq .Values.environment "production" -}}
prod
{{- else -}}
non-prod
{{- end -}}
{{- end -}}
13 changes: 13 additions & 0 deletions docs/helm/charts/minimal/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: helm-{{ .Release.Name }}-configmap
data:
appVersion: {{ .Chart.AppVersion }}
environment: {{ .Values.environment | quote }}
envShort: {{ template "envShort" . }}
{{- range .Values.configData }}
{{- if .enabled }}
{{ .key }}: {{ .value | quote }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions docs/helm/charts/minimal/values-alt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
environment: staging

configData:
- key: conditionalKey
value: "this wont be included"
enabled: false
6 changes: 6 additions & 0 deletions docs/helm/charts/minimal/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
environment: production

configData:
- key: conditionalKey
value: "this will be included"
enabled: true
115 changes: 106 additions & 9 deletions docs/helm/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,128 @@ sidebar_position: 1
title: Helm Introduction
---

Helm is Package manager for Kubernetes.
Helm is package manager and a templating engine for Kubernetes. It allows you to define, install, and upgrade even the most complex Kubernetes applications. It's like apt, yum, or homebrew for Kubernetes. Primary use case is application deployment and environment management.

## Helm Architecture

The new architecture of Helm 3 is very simple. It has only client-side components. The server-side components like Tiller are removed in Helm 3. Helm 3 is a client-side application that interacts with the Kubernetes API server.

### Using a Helm Chart

- Once we install the helm to the system, we have to add a chart repository, like prometheus, Ingress-nginx and [more](https://artifacthub.io/packages/search?kind=0)
To deploy an application using Helm, you need to create a Helm chart. A Helm chart is a collection of files that describe a related set of Kubernetes resources. A single chart might be used to deploy something simple, like a memcached pod, or something complex, like a full web app stack with HTTP servers, databases, caches, and so on.

First we need to add the repository to the helm

```bash
helm repo add bitnami https://charts.bitnami.com/bitnami
```

- We can update the repository using the following command

```bash
helm repo update
```

Eg:
- Then we can install the chart using the following command

```bash
helm repo add <name> <repo url>
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm install postgres bitnami/postgresql
```

- To check list of charts we can install
we can search for the available charts using the following command

```bash
helm search repo kubernetes-dashboard
helm search repo bitnami
```

- To install a chart
Or search the available versions of the chart using the following command

```bash
helm search repo bitnami/postgresql --versions
```
helm install <name> kubernetes-dashboard/kubernetes-dashboard

We can also pull the chart locally to look at the configuration files. `--version` flag is used to specify the version of the chart not the app version

```bash
helm pull bitnami/postgresql --version 16.3.0
```

We can give values to the chart using the values flag and padding the values in the yaml file

```bash
helm install postgresql bitnami/postgresql --values values.yaml
```

The values.yaml file should look like this

```yaml
commonAnnotations:
foo: bar
```
We can upgrade the chart using the following command
```bash
helm upgrade --install postgresql bitnami/postgresql --values values.yaml --version=16.4.0 --namespace=my-namespace
```

We can rollback the chart using the following command `postgresql` is the release name we can get the release name using `helm list`.

```bash
helm rollback postgresql
```

To check helm release status

```bash
helm list
```

To check values provided by the user. Again `postgresql` is the release name

```bash
helm get values postgresql
```

We can also get actual manifest files that are generated by the helm chart. Again `postgresql` is the release name

```bash
helm get manifest postgresql
```

We can uninstall the chart using the following command. Again `postgresql` is the release name

```bash
helm uninstall postgresql
```

### Creating our own Helm Chart

- We can create our own helm chart using the following command. It will generate a dir with all the boilerplate code.

```bash
helm create mychart
```

- We can install the chart using the following command. `mychart` is the chart name and `./mychart` is the path to the chart

```bash
helm install mychart ./mychart
```

We can also apply with a values file

```bash
helm install mychart ./mychart --values values.yaml
```

## Helm Hooks

Helm hooks are a way to interact with the lifecycle of a release. They allow you to intervene at certain points in a release's life cycle. Helm supports the following hooks:

- `pre-install` - Runs before any templates are rendered.
- `post-install` - Runs after all templates have been rendered and resources have been created.

### What's next?

[Learning Resources](./learning-resources.md) - Learn more about Helm with these resources.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions docs/kubernetes/apps/nginx-simple-app/Deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: nginx-ns
spec:
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx
image: nginx:latest
resources:
limits:
memory: "128Mi"
cpu: "500m"
requests:
memory: "64Mi"
cpu: "250m"
ports:
- containerPort: 80
4 changes: 4 additions & 0 deletions docs/kubernetes/apps/nginx-simple-app/Namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: nginx-ns
Loading

0 comments on commit f3f366b

Please sign in to comment.