Contents

Introduction

Prerequisites

Requirements

Components Used

What is kube-apiserver?

Problem

Root Cause Analysis

Steps for Recovery

Post Checks

Introduction

This document describes a solution to recover the continuous restart of kube-apiserver pod.

Prerequisites

Requirements

Cisco recommends that you have the knowledge of these topics:

- Dockers and Kubernetes

- Cisco Subscriber Microservices Infrastructure (SMI) Ultra Cloud Core Common Execution Environment (CEE)

Components Used

The information in this document is based on the Kubernetes v1.21.0 version.

The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, ensure that you understand the potential impact of any command.

What is kube-apiserver?

- The Kubernetes Application programming interface(API) server validates and configures data for the API objects which include pods, services, replication controllers, and others. The API Server services REpresentational State Transfer(REST) operations and provide the front-end to the cluster's shared state through which all other components interact.

- Kubernetes API server is responsible to authenticate and validate requests, to retrieve and update data in etcd data store. In fact, kube-API server is the only component that interacts directly with the etcd datastore.

- These are the steps the kube-API server takes when a pod is created in the cluster:

a. Authenticate User

b. Validate Request

c. Retrieve Data

d. Update ETCD

e. Scheduler

f. Kubelet

- The other components such as the scheduler, kube-controller-manager & kubelet, use the API server to perform updates in the cluster in their respective areas.

Problem

The kube-apiserver-smf-data-master-3 restart is observed continuously. In this case, execute kubectl CLI kubectl get pods -A -o wide | grep apiserver to identify the issue:

cloud-user@smf-data-master-1:~$ kubectl get pods -A -o wide | grep apiserver

kube-system      kube-apiserver-smf-data-master-1                   1/1     Running   4          68d    10.192.1.22       smf-data-master-1   <none>           <none>

kube-system      kube-apiserver-smf-data-master-2                   1/1     Running   4          68d    10.192.1.23       smf-data-master-2   <none>           <none>

kube-system      kube-apiserver-smf-data-master-3                   0/1     Running   2          68d    10.192.1.24       smf-data-master-3   <none>           <none>

cloud-user@smf-data-master-1:~$

These errors were observed in the kubectl logs <kube-apiserver_pod_name> -n kube-system:

cloud-user@smf-data-master-1:~$ kubectl logs  kube-apiserver-smf-data-master-3 -n kube-system

E1116 20:09:52.635602       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:09:53.691253       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:09:54.751145       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:09:55.808782       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:09:56.865492       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:09:57.906426       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:09:58.963801       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:10:00.027583       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:10:01.084615       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:10:02.206947       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:10:03.256261       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:10:04.313860       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

E1116 20:10:05.363353       1 cacher.go:419] cacher (*core.Secret): unexpected ListAndWatch error: failed to list *core.Secret: unable to transform key "/registry/secrets/cee-dnceed21/alert-logger-sa-token-dzhkb": invalid padding on input; reinitializing...

To recover, you must try to restart the kube-apiserver pod with CLI kubectl delete pod <kube-apiserver_pod_name> -n kube-system, but it doesn't help.

Root Cause Analysis

On further analysis, it was found that the difference in the secret value between master-3, where the kube-apiserver restarted continuously, and other master nodes, caused this issue.

From Master-1:

cloud-user@smf-data-master-1:~$ cat /data/kubernetes/secrets.conf

apiVersion: apiserver.config.k8s.io/v1

kind: EncryptionConfiguration

resources:

- resources:

- secrets

providers:

- aescbc:

keys:

- name: key1

secret: BG5hleucjlD5ZDkFYUxoGLHHhBA/AeoNruHM0i70/ZI=   <<<<<<<<<<

- identity: {}

cloud-user@smf-data-master-1:~$

From Master-3:

cloud-user@smf-data-master-3:~$ cat /data/kubernetes/secrets.conf

apiVersion: apiserver.config.k8s.io/v1

kind: EncryptionConfiguration

resources:

- resources:

- secrets

providers:

- aescbc:

keys:

- name: key1

secret: XK+7mbh3YEnMdqswtySQ1d6QRehg+K6/J1d2e3EnMvI=   <<<<<<<<

- identity: {}

cloud-user@smf-data-master-3:~$

Steps for Recovery

1. As part of recovery, copy the current secret of master-3 to a backup file:

cloud-user@smf-data-master-3:~$ sudo cp /data/kubernetes/secrets.conf /data/kubernetes/secrets.conf-bkp

2. Edit the secrets, configure them in Master-3, and change the value of secret to the same value as seen in other master nodes.

cloud-user@smf-data-master-3:~$ sudo vim /data/kubernetes/secrets.conf

apiVersion: apiserver.config.k8s.io/v1

kind: EncryptionConfiguration

resources:

- resources:

- secrets

providers:

- aescbc:

keys:

- name: key1

secret: XK+7mbh3YEnMdqswtySQ1d6QRehg+K6/J1d2e3EnMvI=     <----  Change this value to “BG5hleucjlD5ZDkFYUxoGLHHhBA/AeoNruHM0i70/ZI=“ as in other Master nodes

- identity: {}

3. Restart the kube-apiserver container on Master-3:

cloud-user@smf-data-master-3:~$ sudo docker ps -f "name=k8s_kube-apiserver" -q | xargs sudo docker restart

Post Checks

Verify Kubernetes from master:

cloud-user@pod-name-smf-master-1:~$ kubectl get pods -A -o wide | grep kube-apiserver

Now, all pods must be up and must run without any restarts.