Skip to content

UWCS/kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Kubernetes: Orchestrated

Feel free to ask questions!!! It is entirely possible something in here doesn't work :)

Docker refresher

Take a look in the demo/docker directory. Start by looking in Makefile and replacing instances of your-github-username-here with your github username.

Build and run locally

  • cd demo/docker
  • Check out waht's going on with the app!
  • To build, run make build

Log in to ghcr.io

We will push our image to the Github container repository, ghcr.io. First, we need to log in.

  • Generate a Github PAT (Personal Access Token): Go to Github -> Settings -> Developer Settings -> Personal access tokens, and generate a token.
  • Copy it / put it somewhere safe, then run make login, and paste in your token when prompted.

Push to ghcr.io

  • make publish Will push your image to ghcr.io, so we can use it in Kubernetes.

Kubernetes

Setting up

To interface with our Kubernetes cluster, we use kubectl, which you will need to download and set up. To install on Linux, run:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
# If you have sudo on your machine, do:
mv kubectl /usr/bin/kubectl
# If you don't, we can add it to PATH temporarily instead:
export PATH=$PATH:$(pwd)

Now we need to tell kubectl how to talk to our cluster. To do this:

  • Create a file at ~/kubeconfig with the following contents:
    apiVersion: v1
    clusters:
    - cluster:
        insecure-skip-tls-verify: true
        server: https://mc.uwcs.co.uk:6443
      name: uwcs
    contexts:
    - context:
        cluster: uwcs
        user: uwcs
      name: uwcs
    current-context: uwcs
    kind: Config
    preferences: {}
    users:
    - name: uwcs
      user:
        client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrRENDQVRlZ0F3SUJBZ0lJV1J0cVRxU1MrWFl3Q2dZSUtvWkl6ajBFQXdJd0l6RWhNQjhHQTFVRUF3d1kKYXpOekxXTnNhV1Z1ZEMxallVQXhOekE0T0RneU1UWTBNQjRYRFRJME1ESXlOVEUzTWpreU5Gb1hEVEkxTURJeQpOREUzTWpreU5Gb3dNREVYTUJVR0ExVUVD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TlZIUTRFRmdRVWpVaU8xbTF0QWEwRG83NmFiWG9OCnFEREJPdEl3Q2dZSUtvWkl6ajBFQXdJRFNRQXdSZ0loQUpEUEg1MHF1dEx6UWJ4bXBvMmkwZFNtd1phSmxGUkUKZEowU3VkYXh0RjA1QWlFQStURlBxYXVpcDd6alhIalFwUDVuQnE2clN3RzNuaEJTeDF1UFE5UDFjRnM9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
        client-key-data: ASK_ME_FOR_THIS!
  • Run
    export KUBECONFIG=~/kubeconfig
  • You should now be able to use kubectl! Try running kubectl get pods -A and see what we get.

Using kubectl to deploy our dockerised app

The syntax of kubectl is generally:

kubectl <verb> <resource type> <flags>

so for example, something like:

kubectl get pod --namespace kube-system

will list all running pods in the kube-system namespace.

In this repo, look under demo/kubernetes, you will see some Kubernetes manifests.

  • Try reading through them, and think about what might happen when you apply these. Which one should you apply first, and why?
  • Modify ns.yaml to create a namespace with your name instead of mine. To apply this, run:
    kubectl apply -f ns.yaml
    Then list existing namespaces with
    kubectl get namespace
  • Modify deployment.yaml to point to your image and namespace instead of mine, and apply it with kubectl apply -f deployment.yaml
  • Likewise with service.yaml!
  • To make your application accessible to you, run kubectl port-forward --namespace <your namespace> service/hello 5000:5000, then visit 127.0.0.1:5000 in your browser. Ta-da!

About

SoT for Kubernetes deployments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published