If I have my Kubernetes hooked up to GitLab, what does a typical yaml look like to actually deploy to it?

Having some trouble finding this information. For example if my Kubernetes is already hooked up in the dashboard and I have in .gitlab-ci.yml:

deploy_staging:
  stage: deploy
  script:
    - echo "Deploy to staging server"
  environment:
    name: staging
    url: https://stage.mywebsite.com
  only:
    - gitlab

That isn’t enough, right? Would I have to do add the kubectl apply like:

deploy_staging:
  stage: deploy
  before_script:
    - do
    - kubernetes
    - authentication
    - stuff
  script:
    - echo "Deploy to staging server"
    - kubectl apply -n stage -f mydeployment.yaml
  environment:
    name: staging
    url: https://stage.mywebsite.com
  only:
    - gitlab

And do I even need to authenticate when it’s already in the dashboard with the proper K8s API url and token?

What’s the actual pipeline look like to deploy? Haven’t seen an example that uses kubectl create/apply.

This felt funny, but I was able to get it working. If this is bad practice, feel free to let me know.

  1. use google-sdk image for kubectl
  2. set KUBECONFIG in the dashboard then export it in the script
  3. ca cert is missing, so had to copy paste and encode it and set in dashboard then export it in the script and set the config just for that value
deploy_staging:
  stage: deploy
  image: google/cloud-sdk
  before_script:
    - export KUBECONFIG=${KUBECONFIG}
  script:
    - kubectl config set clusters.cluster.certificate-authority-data ${KUBECA_BASE64}
    - kubectl config view
    - kubectl apply -n stage -f mydeployment.yaml
  environment:
    name: staging
    url: https://stage.mywebsite.com