Skip to content

Commit

Permalink
Reverting back to ingress for the webinar
Browse files Browse the repository at this point in the history
  • Loading branch information
BobJWalker committed May 29, 2024
1 parent f26f64c commit e11feab
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 117 deletions.
50 changes: 25 additions & 25 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ Configuring Kubernetes to host this particular container will teach you the foll
- [Environment Variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/)
- [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/)
- [Namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)
- [Gateway](https://gateway-api.sigs.k8s.io/)
- [Gateway Listener](https://gateway-api.sigs.k8s.io/guides/tls/?h=listener#downstream-tls)
- [HTTPRoute](https://gateway-api.sigs.k8s.io/api-types/httproute/)
- [Ingress Controllers](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/)
- [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/)

# GitHub Action and Docker Repository

Expand All @@ -29,7 +28,7 @@ If you fork this repo you will need to set the following repo secrets:
The docker image, manifest files, and variables will be provided to you.

## 1. Install K8s
Install ONE of the following on a VM or locally!
Install **_ONE_** of the following on a VM or locally!

- [docker desktop](https://docs.docker.com/desktop/) - easiest and preferred
- 🍎 If you are working on a Mac with an Apple chip—Docker Desktop is the easiest option:
Expand All @@ -43,8 +42,9 @@ Install ONE of the following on a VM or locally!
Open up a command prompt or terminal. Change the current directory in the terminal to the `k8s/provision` folder in this repo.
- Run the following commands:
- Create all the namespaces: `kubectl apply -f namespaces.yaml`
- Install the NGINX Gateway Resources: `kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml`
- Install the NGINX Gateway: `helm install ngf oci://ghcr.io/nginxinc/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway`
- Install the NGINX Ingress Controller: `kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.5/deploy/static/provider/cloud/deploy.yaml`

**Important:** For this activity we are using `Ingress` instead of the newer `Gateway API`. The core concepts are the same, but ingress is more simplistic and easier to learn.

## 3. Configure your hosts file.
Go to your hosts file (if on Windows) and add the following entries. The nginx ingress controller uses host headers for all routing. Doing this will allow you to easily access the application running on your k8s cluster.
Expand All @@ -58,23 +58,6 @@ Go to your hosts file (if on Windows) and add the following entries. The nginx
127.0.0.1 argocd.local
```

## 3. Install Argo

This will install ArgoCD on your cluster. Perfect for poking around!

- Install ArgoCD
- Run `kubectl create namespace argocd`
- Run `kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml`
- Change the current directory in the terminal to the `k8s/provision` folder in this repo.
- Run `kubectl apply -n argocd -f argocd-gateway.yaml`
- To access ArgoCD UI
- To login
- URL is https://argocd.local
- You will likely get a cert error, go ahead and proceed
- Username is admin
- Run `kubectl get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' --namespace argocd` to get the password.
- Please note it is base64, which you will need to decode. You can do that via an online editor, or PowerShell `[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("blahblahblah"))`

# Learning Sessions

If you are looking to Learn K8s, here are some lessons to perform using this repo.
Expand All @@ -89,15 +72,18 @@ These instructions will deploy the following to the default namespace.

- Secret
- Deployment (Image)
- ClusterIp Service
- ClusterIP Service
- Gateway Listener
- HTTP Route

To perform the deployment do the following:
- Go to https://hub.docker.com/r/bobjwalker99/randomquotes-k8s/tags and find the latest version tag (0.1.3 for example). Update the `image` entry in the randomquotes-deployment.yaml file.
- Open up a command prompt or terminal. Change the current directory in the terminal to the `k8s/base` folder in this repo.
- Run `kubectl apply -f randomquotes-secrets.yaml`
- Run `kubectl apply -f randomquotes-deployment.yaml`

**Important:** The secret must be in a separate file because later activities we will use kustomize, which will manage the secret for us. If you were only using manifest files, I'd recommend combining the two.

It might take a moment for the deployment to finish. I like to check the status of the pods. Run `kubectl get pods` until the randomquotes pod shows up as healthy.

Once the deployment is finished go to http://randomquotes.local.
Expand Down Expand Up @@ -125,7 +111,21 @@ We are going to deploy to all four namespaces. The instructions are the same, s

## 3. Third Activity - ArgoCD

This activity will happen only if we have enough time. We will install and configure ArgoCD so we can compare and contrast the two.
This will install ArgoCD on your cluster and configure an application to deploy.

- Install ArgoCD
- Run `kubectl create namespace argocd`
- Run `kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml`
- To access ArgoCD UI
- Run kubectl port-forward svc/argocd-server -n argocd 8080:443
- **Important** The port forwarding will only work while that window is open.
- If you want to, you can mess with ingress rules, but this is the quick and dirty approach to getting going.
- To login
- URL is https://argocd.local
- You will likely get a cert error, go ahead and proceed
- Username is admin
- Run `kubectl get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' --namespace argocd` to get the password.
- Please note it is base64, which you will need to decode. You can do that via an online editor, or PowerShell `[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("blahblahblah"))`

- Configure first application
- Click the `New App` button
Expand Down
47 changes: 14 additions & 33 deletions k8s/base/randomquotes-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
apiVersion: v1
kind: Secret
metadata:
name: random-quotes-secrets
type: Opaque
stringData:
homepageDisplay: "blah"
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -46,31 +38,20 @@ spec:
- port: 6801
targetPort: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: randomquotes-gateway-nginx
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: randomquotes-gateway-route-nginx
name: randomquotes-ingress-nginx
spec:
parentRefs:
- name: randomquotes-gateway-nginx
hostnames:
- "randomquotes.local"
ingressClassName: nginx
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: randomquotes-app-cluster-ip-service
port: 6801
- host: randomquotes.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: randomquotes-app-cluster-ip-service
port:
number: 6801
39 changes: 14 additions & 25 deletions k8s/charts/templates/randomquotes-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,20 @@ spec:
- port: 6801
targetPort: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: randomquotes-gateway-nginx
name: randomquotes-ingress-nginx
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: randomquotes-gateway-route-nginx
spec:
parentRefs:
- name: randomquotes-gateway-nginx
hostnames:
- "randomquotes.local"
ingressClassName: nginx
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: randomquotes-app-cluster-ip-service
port: 6801
- host: randomquotes.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: randomquotes-app-cluster-ip-service
port:
number: 6801
4 changes: 2 additions & 2 deletions k8s/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ images:
newTag: "0.1.90-helm.5"
patches:
- target:
kind: HTTPRoute
name: randomquotes-gateway-route-nginx
kind: Ingress
name: randomquotes-ingress-nginx
path: randomquotes-ingress-nginx.yaml
2 changes: 1 addition & 1 deletion k8s/overlays/dev/randomquotes-ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- op: replace
path: /spec/hostnames/0
path: /spec/rules/0/host
value: randomquotesdev.local
4 changes: 2 additions & 2 deletions k8s/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ images:

patches:
- target:
kind: HTTPRoute
name: randomquotes-gateway-route-nginx
kind: Ingress
name: randomquotes-ingress-nginx
path: randomquotes-ingress-nginx.yaml
2 changes: 1 addition & 1 deletion k8s/overlays/prod/randomquotes-ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- op: replace
path: /spec/hostnames/0
path: /spec/rules/0/host
value: randomquotesprod.local
4 changes: 2 additions & 2 deletions k8s/overlays/staging/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ images:

patches:
- target:
kind: HTTPRoute
name: randomquotes-gateway-route-nginx
kind: Ingress
name: randomquotes-ingress-nginx
path: randomquotes-ingress-nginx.yaml
2 changes: 1 addition & 1 deletion k8s/overlays/staging/randomquotes-ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- op: replace
path: /spec/hostnames/0
path: /spec/rules/0/host
value: randomquotesstaging.local
4 changes: 2 additions & 2 deletions k8s/overlays/test/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ images:
newTag: "0.1.92"
patches:
- target:
kind: HTTPRoute
name: randomquotes-gateway-route-nginx
kind: Ingress
name: randomquotes-ingress-nginx
path: randomquotes-ingress-nginx.yaml
2 changes: 1 addition & 1 deletion k8s/overlays/test/randomquotes-ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- op: replace
path: /spec/hostnames/0
path: /spec/rules/0/host
value: randomquotestest.local
45 changes: 23 additions & 22 deletions k8s/provision/argocd-gateway.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
apiVersion: v1
kind: Service
metadata:
name: argocd-gateway-nginx
name: argocd-cluster-ip-service
spec:
gatewayClassName: nginx
listeners:
- name: https
port: 443
protocol: HTTPS
type: ClusterIP
selector:
app.kubernetes.io/name: argocd-server
ports:
- port: 6801
targetPort: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argo-gateway-route-nginx
name: argo-ingress-nginx
spec:
parentRefs:
- name: argo-gateway-nginx
hostnames:
- "argocd.local"
ingressClassName: nginx
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: svc/argocd-server
port: 443
- host: argocd.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-cluster-ip-service
port:
number: 6801

0 comments on commit e11feab

Please sign in to comment.