Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add homework 10.Kubernetes_installation #2932

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check pod status

on:
workflow_dispatch:

jobs:
Check_pod_status:
runs-on: ubuntu-latest

steps:
- name: Checking the repository
uses: actions/checkout@v4

- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo -e "Host *\n StrictHostKeyChecking no" > ~/.ssh/config

- name: Connect SSH and check pod status
id: pod_status
run: |
FAILED_PODS=$(ssh ${{ secrets.K8S_USER }}@${{ secrets.K8S_HOST }} -o ProxyCommand="ssh -W %h:%p -q ${{ secrets.PROXY_USER }}@${{ secrets.PROXY_HOST }} -p ${{ secrets.PROXY_PORT }}" \
"kubectl get pods -A --field-selector status.phase!=Running,status.phase!=Succeeded")

if [ -n "$FAILED_PODS" ]; then
SAFE_FAILED_PODS=$(echo "$FAILED_PODS" | awk '{printf "%s\\n", $0}')
echo "failed_pods=true" >> $GITHUB_OUTPUT
echo "failed_pods_content"= $SAFE_FAILED_PODS >> $GITHUB_OUTPUT
else
echo "failed_pods=false" >> $GITHUB_OUTPUT
fi

- name: Debug pod status
run: |
if [ -n "${{ steps.pod_status.outputs.failed_pods_content }}" ]; then
echo "FAILED_PODS: ${{ steps.pod_status.outputs.failed_pods_content }}"
else
echo "No failed pods found"
fi

- name: Slack Notification
if: steps.pod_status.outputs.failed_pods == 'true'
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CUSTOM_PAYLOAD: |
{
"username": "Cluster monitoring",
"icon_emoji": ":satellite_antenna:",
"attachments": [
{
"color": "danger",
"title": "Problematic Pods Detected :dart:",
"text": "```${{ steps.pod_status.outputs.failed_pods_content }}```",
"mrkdwn_in": ["text"]
}
]
}
62 changes: 62 additions & 0 deletions Denis_Fedosevich/10.Kubernetes_installation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 10. Kubernetes installation (WS)

## Homework Assignment 1. K8s Installation

### Install kubectl for local run

```shell
denis@server:~$ curl -LO https://dl.k8s.io/release/`curl -LS https://dl.k8s.io/release/stable.txt`/bin/linux/amd64/
denis@server:~$ chmod +x ./kubectl
denis@server:~$ sudo mv ./kubectl /usr/local/bin/kubectl
denis@server:~$ kubectl version --client
Client Version: v1.32.1
Kustomize Version: v5.5.0
denis@server:~$
```

### Install k9s

```shell
denis@server:~$ wget https://github.com/derailed/k9s/releases/download/v0.32.7/k9s_linux_amd64.deb
denis@server:~$ sudo dpkg -i k9s_linux_amd64.deb
denis@server:~$ k9s version
____ __.________
| |/ _/ __ \______
| < \____ / ___/
| | \ / /\___ \
|____|__ \ /____//____ >
\/ \/

Version: v0.32.7
Commit: 6b5d24f5741a1789fb97ba3e11f0ee868d93459d
Date: 2024-11-16T20:22:28Z
```
Cluster selection
![K8s cluster selection](./images/image_1.png)

List of all pods in all namespaces
![Image list of all pods](./images/image_2.png)

### Pod deployment

[Link of pod YAML manifest](pod.yaml)

```shell
denis@server:~/10.Kubernetes_installation_WS$ kubectl apply -f pod.yaml
pod/ubuntu-default created
denis@server:~/10.Kubernetes_installation_WS$ k9s
```

Checking the running new pod
![Running pod status](./images/image_3.png)

### Monitoring of cluster:

List of links:
- [Workflow](.github/workflows/pod_status.yaml)
- [Action](https://github.com/fedos1993/10.Kubernetes_installation_WS/actions/workflows/pod_status.yaml)


Result of slack notification

![Result of slack notification](./images/image_4.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Denis_Fedosevich/10.Kubernetes_installation/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-default
labels:
app: ubuntu
spec:
containers:
- image: ghcr.io/pluhin/busy-box:latest
command:
- "sleep"
- "604800"
imagePullPolicy: IfNotPresent
name: ubuntu-default
Loading