Skip to content

Instantly share code, notes, and snippets.

@jhahspu
Last active February 13, 2022 19:08
Show Gist options
  • Save jhahspu/24f6c8190b10c733577d6f576a05267a to your computer and use it in GitHub Desktop.
Save jhahspu/24f6c8190b10c733577d6f576a05267a to your computer and use it in GitHub Desktop.
Kubernetes

Cluster info

  • display information about cluster
    • kubectl cluster-info
  • connect to cluster
    • aws eks update-kubeconfig --name [cluster_name] --region eu-west-1
    • fix for permissions: open iam and add eks access
  • multiple contexts
    • kubectl config use-context [context]
  • pods
    • kubectl get pods
  • aws credentials C:\Users\ USERNAME . aws\credentials
[default]
aws_access_key_id = 
aws_secret_access_key = 

[github]
aws_access_key_id = 
aws_secret_access_key = 

  • aws auth
apiVersion: v1
kind: ConfigMap
metadata:
  name: aws-auth
  namespace: kube-system
data:
  mapUsers: |
    - userarn: [USER-ARN]
      username: github-ci
      groups:
        - system:masters
  • kubectl apply -f eks/aws-auth.yml

kubectl commands

  • kubectl get service
  • kubectl get pods
  • kubectl apply -f eks/deployment.yml
  • kubectl apply -f eks/service.yml
  • kubectl apply -f eks/ingress.yml

k9s

  • :ns [enter] (namespace)
  • :service [enter]
  • :pods [enter]
  • :cj [enter] (cronjobs)
  • :configmap [enter]
  • d (describe on aws-auth)
  • :quit [enter] (exit k9s)

deploy image to cluster

apiVersion: apps/v1
kind: Deployment
metadata:
  name: [OBJECT_NAME]
  labels:
    app: [APP_NAME]
spec:
  replicas: 1 (number of pods)
  selector:
    matchLabels:
      app: [APP_NAME]
  template:
    metadata:
      labels:
        app: [APP_NAME]
    spec:
      containers:
      - name: [APP_NAME]
        image: [URI_IMAGE]
        ports:
        - containerPort: 8080 (same as in dockerfile?)
  • deploy

    • kubectl apply -f eks/deployment.yml
  • check errors

    • kubectl logs -f [POD_NAME]
  • service

apiVersion: v1
kind: Service
metadata:
  name: me-warehouse-api-service
spec:
  selector:
    app: me-warehouse-api
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer
  • deploy service

    • kubectl apply -f eks/service.yml
  • kubectl latest

    • https://storage.googleapis.com/kubernetes-release/release/stable.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment