欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

GCP - Kubernetes study notes

程序员文章站 2024-02-10 23:48:58
...

This is my study notes on playing around with GCP and Kubernetes. Not finished. Will be updated from time to time.

Setup

Enable k8s services (Google Kubernetes Engine API) in the console.

gcloud config set account my-google-account
gcloud container clusters create k0 --zone=asia-east1-a

For --zone options you can select from here, a mistake I made was picking the region grid instead of zone grid. That will lead to errors.

Pods, Deployment and Services

A pod is a set of interconnected containers, somewhat similar to a docker-compose object.

# Launch a single instance:
kubectl run nginx --image=nginx:1.10.0
# Get pods
kubectl get pods
# Expose nginx

A deployement will automatically recreate the service if it was down due to some reasons. If you try to delete a pod that is in a deployment, it will "resurrected" automatically. see here

kubectl expose deployment nginx --port 80 --type LoadBalancer
# List services
kubectl get services

monolith.yaml

apiVersion: v1
kind: Pod
metadata:
  name: monolith
  labels:
    app: monolith
spec:
  containers:
    - name: monolith
      image: udacity/example-monolith:1.0.0
      args:
        - "-http=0.0.0.0:80"
        - "-health=0.0.0.0:81"
        - "-secret=secret"
      ports:
        - name: http
          containerPort: 80
        - name: health
          containerPort: 81
      resources:
        limits:
          cpu: 0.2
          memory: "10Mi"

Create the monolith pod

kubectl create -f pods/monolith.yaml

View stdin logs

# One-time poll 
kubectl logs monolith
# Streaming
kubectl logs -f monolith

Port Forwarding

kubectl port-forward monolith 10080:80

Pod selection by labels

kubectl get pods -l "app=monolith, secure=enabled"

You can use the kubectl exec command to run an interactive shell inside the monolith Pod. This can come in handy when you want to troubleshoot from within a container:

# Similar to docker-compose exec <service> /bin/sh, right?
kubectl exec monolith --stdin --tty -c monolith /bin/sh

Command Patterns

kubectl get/create/delete/describe serverices/pods
# or
kubectl create -f definitionInFile.yaml

Rolling Update 1000 pods with deployment yaml replicas

Questions

转载于:https://www.jianshu.com/p/19ca13cde0c3