techsupport:kube3760
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| techsupport:kube3760 [2022/11/30 19:37] – kjohns23 | techsupport:kube3760 [2023/03/15 17:20] (current) – kjohns23 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Gitlab and Kubernetes in CIS*3760 F23 ===== | + | ==== Gitlab and Kubernetes in CIS*3760 F23 ==== |
| - | This is a guide to assist students in CIS*3760 with the process of deploying an application developed on the SoCS Gitlab Server to our Kubernetes cluster. Each project group will be provided with their own server running RKE2 Kubernetes, on which to deploy. The server will be located at cis3760-XX where XX is your group number. | + | This is a guide to assist students in CIS*3760 with the process of deploying an application developed on the SoCS Gitlab Server to our Kubernetes cluster. Each project group will be provided with their own server running RKE2 Kubernetes, on which to deploy. The server will be located at cis3760-XX.socs.uoguelph.ca |
| ===== How To Interact With Kubernetes ==== | ===== How To Interact With Kubernetes ==== | ||
| Line 15: | Line 15: | ||
| If you prefer to interact with Kubernetes directly from your own machine, the kubectl command can be installed directly on your local machine. | If you prefer to interact with Kubernetes directly from your own machine, the kubectl command can be installed directly on your local machine. | ||
| - | Follow the instructions for your Operating system from the [[ https:// | + | Follow the instructions for your Operating system from the [[ https:// |
| - | From the [[ https:// | + | From the [[ https:// |
| Unfortunately, | Unfortunately, | ||
| Line 23: | Line 23: | ||
| ==== Building your Application Container in Gitlab ==== | ==== Building your Application Container in Gitlab ==== | ||
| - | Guide to use kaniko here. | + | Kaniko is a tool that allows you to build your Docker container automatically as part of a CI/CD Pipeline. |
| + | 1. As a prerequisite your Dockerfile containing all of your container build information must be located in the root of your git repository. If you want to place your Dockerfile in a subdirectory you will have to edit the --dockerfile line in the below configuration to specify the new location. | ||
| - | 1. You will need to host your Docker container. If the container can be publicly accessible, this can be hosted in Docker Hub. If it must be private, | + | 2. Add the following lines to your .gitlab-ci.yml in the root of your Gitlab |
| + | |||
| + | < | ||
| + | stages: | ||
| + | - build | ||
| + | |||
| + | build: | ||
| + | stage: build | ||
| + | image: | ||
| + | name: gcr.io/kaniko-project/ | ||
| + | entrypoint: ["" | ||
| + | script: | ||
| + | - / | ||
| + | --context " | ||
| + | --dockerfile " | ||
| + | --destination " | ||
| + | </ | ||
| + | |||
| + | Once your container is built it needs to be hosted | ||
| ==== Integrating Gitlab and Kubernetes with Gitlab Agent ==== | ==== Integrating Gitlab and Kubernetes with Gitlab Agent ==== | ||
| Line 39: | Line 58: | ||
| - id: "< | - id: "< | ||
| paths: | paths: | ||
| - | - glob: '/ | + | - glob: '/ |
| </ | </ | ||
| Line 68: | Line 87: | ||
| </ | </ | ||
| - | Next, run the following command on your kubernetes server to install the gitlab agent in kubernetes and automatically connect it to your gitlab project. | + | Next, run the following command on your kubernetes server, specifying your token from step 3, to install the gitlab agent in kubernetes and automatically connect it to your gitlab project. |
| + | < | ||
| < | < | ||
| - | 8. In your Gitlab Project go to Settings > Registry > Deploy Tokens. Enter a name to label the token, a username, and check read_registry | + | ==== Deploying |
| - | 9. Run the following command, substitution the username you entered in the previous step for DOCKER_USER, | + | 1. Kubernetes needs to be able to connect to the Gitlab Docker Registry. In your Gitlab Project go to Settings |
| - | The gitlab agent is now set up and can pull your container from the SoCS container | + | 2. Run the following command, substituting the username you entered in the previous step for DOCKER_USER, |
| - | ==== Deploying your Application | + | 3. A Manifest file needs to be defined in Gitlab. This is a yaml file that lists the kubernetes specifications required to deploy your application within Kubernetes. A sample mainefest file is available in the code block below, and should be placed in manifests/ |
| + | |||
| + | < | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: infovis-deployment | ||
| + | namespace: infovis | ||
| + | spec: | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: infovis | ||
| + | replicas: 1 | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: infovis | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: nginx-custom | ||
| + | image: registry.socs.uoguelph.ca/ | ||
| + | imagePullSecrets: | ||
| + | - name: regcred | ||
| + | |||
| + | --- | ||
| + | apiVersion: v1 | ||
| + | kind: Service | ||
| + | metadata: | ||
| + | annotations: | ||
| + | labels: | ||
| + | app: infovis | ||
| + | name: infovis-service | ||
| + | namespace: infovis | ||
| + | spec: | ||
| + | ports: | ||
| + | - name: " | ||
| + | port: 80 | ||
| + | targetPort: 80 | ||
| + | selector: | ||
| + | app: infovis | ||
| + | |||
| + | --- | ||
| + | apiVersion: networking.k8s.io/ | ||
| + | kind: Ingress | ||
| + | metadata: | ||
| + | name: infovis-ingress | ||
| + | namespace: infovis | ||
| + | spec: | ||
| + | rules: | ||
| + | - host: cis3760-99.socs.uoguelph.ca | ||
| + | http: | ||
| + | paths: | ||
| + | - path: / | ||
| + | pathType: Prefix | ||
| + | backend: | ||
| + | service: | ||
| + | name: infovis-service | ||
| + | port: | ||
| + | number: 80 | ||
| + | ingressClassName: | ||
| + | </ | ||
| + | |||
| + | ==== Conclusion | ||
| + | |||
| + | All the pieces are now in place to deploy your application automatically to your gitlab server. You can view your application by connecting to your cis3760xx.socs.uoguelph.ca server in a web browser. Each time your container is updated within Gitlab, the agent will automatically pull the latest version to the kubernetes server. | ||
| - | Look at official documentation TODO add instructions on how to do this. TODO maybe add a sample repository. | + | ==== Graphical Representation ==== |
| - | The yaml file should be placed in your project git repository. | + | The following image is a graphical representation of the SoCS Gitlab and Kubernetes Setup and how the pieces fit together and relate to each other. |
| + | {{: | ||
techsupport/kube3760.1669837055.txt.gz · Last modified: 2022/11/30 19:37 by kjohns23