mirror of
https://github.com/wahyd4/knowledge.git
synced 2026-08-09 05:06:28 +10:00
4.5 KiB
4.5 KiB
Kubernetes
Terminology
- Pod
- Single container
- Multiple containers
- share ip
- share volumes
- Node
- Service
- ClusterIP (default)
- NodePort ( access by port)
- LoadBalancer (external ip)
- ExternalName dns
- Deployment
- Replica Set
- Service rolling update
- DaemonSet
- running a cluster storage daemon, such as glusterd, ceph, on each node
- running a logs collection daemon on every node, such as fluentd or logstash.
- running a node monitoring daemon on every node, such as Prometheus Node Exporter, collectd, New Relic agent, or Ganglia gmond.
- StatefulSets
- Ordered, graceful deployment and scaling
- Stable, persistent storage.
- Stable, unique network identifiers.
- Ordered, graceful deletion and termination.
- Proxy
- DNS
- service.namespace
- Secrets
- Persistent volumes
- Available
- a free resource that is not yet bound to a claim
- Bound
- the volume is bound to a claim
- Released
- the claim has been deleted, but the resource is not yet reclaimed by the cluster
- Failed
- the volume has failed its automatic reclamation
- Available
Several ways to access a service inside Kubernetes cluster
- ClusterIP, Can only be accessed inside the cluster. You can access inside
kubectl proxy - NodePort, You can access the service by a specific public port between
30000–32767, if the cluster server IP changes, then your service' endpoint url changes. - LoadBalancer, it's kind of external service, all the requests go through the loadbalancer. Every service needs a new IP for this.
- Ingress, can be shared among multiple services, you can have different types of ingress controllers: gec, nginx, contour,istio and so on.
Links:
Zero down time deployment
Set strategy type to RollingUpdate instead of Recreate
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 50%
maxSurge: 1
Some useful commands
kubectl config set-context context-name --namespace default-namespace-name #default active context
kubectl config view #view config
kubectl get nodes #get nodes
kubectl get namespaces #get all namespaces
kubectl get pods #get pods
kubectl get deployments #get deployments
kubectl get services #get services
kubectl get ingress #get ingresses
Kubernetes Dashboard
Deploy Dashboard
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
Access dashboard
# First fetch cluster info, make sure cluster is running properly
kubectl cluster-info
# Normally the url for dashboard would be
http://your_ip:8080/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
Configure Kubectl to access remote Kubernetes cluster
Here is a very simple config which use HTTP and not secure, should only for local testing purpose
Config
Having a yaml file called config-demo in your current folder
apiVersion: v1
clusters:
- cluster:
server: http://your_cluster_ip:8080
name: development
contexts:
- context:
cluster: development
namespace: dev
user: developer
name: dev
current-context: dev
kind: Config
preferences: {}
users:
- name: developer
Connect to remote cluster
kubectl get all --kubeconfig=config-demo --all-namespaces
For long term usage, you will need to copy the content to your ~/.kube/config
TODO: Setup SSL connection
Helm
Add Kubernetes yaml template engine and the package manager for Kubernetes
How to use
helm init
helm upgrade --install -f abc/values-staging.yaml some-name ./abc
# abc/values-staging.yaml the value file
# some-name the release name
# abc the template folder
helm delete --purge mqtt # mqtt the release name
Install 3rd party packages
helm repo add gitlab https://charts.gitlab.io/ # add remote repo
helm repo update # update index
helm install mirantisworkloads/vernemq
Tips
- Normally when you just updated the configmap the deployment or statefulset pod wouldn't updated, but you can add a label to deployment/statefulset yaml, when the value changes the pods will be recreated
template:
metadata:
labels:
app: vernemq
configmapVersion: "{{ .Release.Revision }}"