Code Snippet

Just another Code Snippet site

[How-To] Kubernetes

Install KubeCtl on windows : https://kubernetes.io/fr/docs/tasks/tools/install-kubectl/

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/windows/amd64/kubectl.exe

Install KubeCtl on CentOS/RHEL

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl

Define config file :

export KUBECONFIG=/path/to/kubectl.cfg

Create a deployment:

kubectl create deployment hello-node --image=tutum/hello-world

Create a service to expose the deployment :

kubectl expose deployment hello-node --type=LoadBalancer --port 80 --name=hello-node-lb

Get service info (and LoadBalancer port) :

kubectl get services -o wide

Scale deployment

kubectl scale deployment DEPLOYMENT_NAME --replicas=1

Delete deployment(s)

kubectl delete deployments DEPLOYMENT_NAME 
kubectl delete deployments -n NAMESPACE DEPLOYMENT_NAME 
kubectl delete deployments -n NAMESPACE --all

Describe deployment(s)

kubectl describe deployments -n NAMESPACE DEPLOYMENT_NAME

Add private repo to container.d:

edit /etc/containerd/config.toml

[plugins]
  [plugins."io.containerd.grpc.v1.cri"]
    sandbox_image = "registry.k8s.io/pause:3.6"
    max_container_log_line_size = -1
    [plugins."io.containerd.grpc.v1.cri".containerd]
      default_runtime_name = "runc"
      snapshotter = "overlayfs"
      [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
        [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
          runtime_type = "io.containerd.runc.v2"
          runtime_engine = ""
          runtime_root = ""
          [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
            systemdCgroup = true
    [plugins."io.containerd.grpc.v1.cri".registry]
      config_path = ""
      [plugins."io.containerd.grpc.v1.cri".registry.auths]
      [plugins."io.containerd.grpc.v1.cri".registry.configs]
        [plugins."io.containerd.grpc.v1.cri".registry.configs."MY_HTTPS_IP:MY_PORT".tls]
          insecure_skip_verify = true
      [plugins."io.containerd.grpc.v1.cri".registry.headers]
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."MY_HTTPS_IP:MY_PORT"]
          endpoint = ["https://MY_HTTPS_IP:MY_PORT"]

Restart container.d

systemctl restart containerd

Test a pull using crictl

crictl --debug pull MY_HTTPS_IP:MY_PORT/MY_IMAGE:latest

, , , ,


14 thoughts on “[How-To] Kubernetes

Leave a Reply

Your email address will not be published. Required fields are marked *