-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cb2e49
commit 293f4a6
Showing
8 changed files
with
194 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: IaC | ||
linkTitle: IaC # The title of left navigation, optional. | ||
navWeight: 1000 # Upper weight gets higher precedence, optional. | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
date: 2023-08-01T21:00:00+08:00 | ||
title: 🐢 Terraform | ||
navWeight: 50 # Upper weight gets higher precedence, optional. | ||
series: | ||
- IaC | ||
- Terraform | ||
categories: | ||
- Devops | ||
--- | ||
|
||
|
||
### Validate Terraform code | ||
|
||
```bash | ||
dirs -c | ||
for DIR in $(find ./examples -type d); do | ||
pushd $DIR | ||
terraform init | ||
terraform fmt -check | ||
terraform validate | ||
popd | ||
done | ||
``` | ||
|
||
### Execute Terraform | ||
|
||
```bash | ||
export DO_PAT="dop_v1_xxxxxxxxxxxxxxxx" | ||
doctl auth init --context rkub | ||
|
||
# inside a dir with a tf file | ||
terraform init | ||
terraform validate | ||
terraform plan -var "do_token=${DO_PAT}" | ||
terraform apply -var "do_token=${DO_PAT}" -auto-approve | ||
|
||
# clean apply | ||
terraform plan -out=infra.tfplan -var "do_token=${DO_PAT}" | ||
terraform apply infra.tfplan | ||
|
||
# Control | ||
terraform show terraform.tfstate | ||
|
||
# Destroy | ||
terraform plan -destroy -out=terraform.tfplan -var "do_token=${DO_PAT}" | ||
terraform apply terraform.tfplan | ||
``` | ||
|
||
* Connect to Droplet with private ssh key | ||
ssh root@$(terraform output -json ip_address_workers | jq -r '.[0]') -i .key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
date: 2023-08-01T21:00:00+08:00 | ||
title: 🐙 Network troubleshooting | ||
navWeight: 50 # Upper weight gets higher precedence, optional. | ||
series: | ||
- Infrastructure | ||
categories: | ||
- Kubernetes | ||
--- | ||
|
||
## Troubleshoot DNS | ||
|
||
* `vi dns.yml` | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: dnsutils | ||
namespace: default | ||
spec: | ||
containers: | ||
- name: dnsutils | ||
image: registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3 | ||
command: | ||
- sleep | ||
- "infinity" | ||
imagePullPolicy: IfNotPresent | ||
restartPolicy: Always | ||
``` | ||
* deploy dnsutils | ||
```bash | ||
k apply -f dns.yml | ||
pod/dnsutils created | ||
|
||
kubectl get pods dnsutils | ||
NAME READY STATUS RESTARTS AGE | ||
dnsutils 1/1 Running 0 36s | ||
``` | ||
|
||
* Troubleshoot with dnsutils | ||
|
||
```bash | ||
kubectl exec -i -t dnsutils -- nslookup kubernetes.default | ||
;; connection timed out; no servers could be reached | ||
command terminated with exit code 1 | ||
|
||
kubectl exec -ti dnsutils -- cat /etc/resolv.conf | ||
search default.svc.cluster.local svc.cluster.local cluster.local psflab.local | ||
nameserver 10.43.0.10 | ||
options ndots:5 | ||
|
||
kubectl get endpoints kube-dns --namespace=kube-system | ||
NAME ENDPOINTS AGE | ||
kube-dns 10.42.0.6:53,10.42.0.6:53,10.42.0.6:9153 5d1h | ||
|
||
kubectl get svc kube-dns --namespace=kube-system | ||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | ||
kube-dns ClusterIP 10.43.0.10 <none> 53/UDP,53/TCP,9153/TCP 5d1h | ||
``` | ||
|
||
## CURL | ||
|
||
```bash | ||
cat << EOF > curl.yml | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: curl | ||
namespace: default | ||
spec: | ||
containers: | ||
- name: curl | ||
image: curlimages/curl | ||
command: | ||
- sleep | ||
- "infinity" | ||
imagePullPolicy: IfNotPresent | ||
restartPolicy: Always | ||
EOF | ||
|
||
k apply -f curl.yml | ||
|
||
#Test du DNS | ||
kubectl exec -i -t curl -- curl -v telnet://10.43.0.10:53 | ||
kubectl exec -i -t curl -- curl -v telnet://kube-dns.kube-system.svc.cluster.local:53 | ||
kubectl exec -i -t curl -- nslookup kube-dns.kube-system.svc.cluster.local | ||
|
||
curl -k -I --resolve subdomain.domain.com:52.165.230.62 https:/subdomain.domain.com/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters